New node data not showing in Emoncms.org

Aha, are you posting locally via the http API? if so you are bypassing
emonhub completely and hence no log. To post to emoncms.org in this case
you will need to repeat the api call in your lan repeater script to post to
emoncms.org as well

How do I send data to my emonpi in order to be processed by emonhub?
I used the examples provided in the Input API :thinking:

Repeating the API call to post to emoncms.org did cross my mind, but I want to use the emonpi as hub for a number of devices, all of them posting to emonpi/emonhub and the emonpi posting to emoncms.org.

OR

send your data to a socket on the emonPi emonhub, which will give you the facility to send the data to other targets, publish the data as mqtt and have the data buffered in case of WAN delays/outages.

OR

install emonhub at the source device too, this will give the option to send to both targets and buffer data locally before the LAN, which I’m guessing might be useful as you have a device called “lan_restarter”.

is there a guide on how to implement this option?

Unfortunately not AFAIK.

Search the forums (both this and the archived one) for “emonhub socket interfacer”, there are a fair few examples and discussions out there.

Never used the socket interfacer myself. I have added this to the emonhub issue list to look into: Document emonhub socket interfacer · Issue #46 · openenergymonitor/emonhub · GitHub

There does seem to be a number of search results when I try “emonhub socket interfacer” as you suggest @pb66 so it may all be out there.

Correction, my bad, @pb66 does actively use the socket interfacer, there will be more to come on this soon

Ahh! When you originally said “(thats two of the core developers of emonhub!?)” had never used them, I assumed you meant you and Glyn, I didn’t realise you were referring to me. Yes, I use a lot of socket interfacers, in many different forms, I would be lost without them.

I found this post

which seems to be what I was looking for.
I have to questions:

  1. if I understood correctly, you have to send to emonhub socket, timestamp+node id+data separated by spaces
  2. didn’t quite understand what you meant by

you can, if you wish send it in that format and you set timestamped = true in the [[runtimesettings]] as per that example, or if timestamped = false (or omited, defaults to false) you can send as just nodeid val1 val2 val2 and a timestamp will be allocated by emonhub on receipt.

That thread refers to original emonhub as opposed to the emonpi variant, there are no reporters in the emonpi variant. It simply means the url and write apikey need to be set to allow emonhub to post to a remote emoncms via http(s) (eg emoncms.org). you should have something like

[[emoncmsorg]]
    Type = EmonHubEmoncmsHTTPInterfacer
    [[[init_settings]]]
    [[[runtimesettings]]]
        pubchannels = ToRFM12,
        subchannels = ToEmonCMS,
        url = https://emoncms.org
        apikey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        senddata = 0                    # Enable sending data to Emoncms.org
        sendstatus = 1                  # Enable sending WAN IP to Emoncms.org MyIP > https://emoncms.org/myip/list
        sendinterval= 30                # Bulk send interval to Emoncms.org in seconds

in your emonhub.conf, in which case you need to edit/add your own apikey.

It seems there is an issue sending to the emonhub socket.
I set up the EmonhubSocketInterfacer:

[[LanRestarter]]
        Type = EmonHubSocketInterfacer
        [[[init_settings]]]
                port_nb = 50012
        [[[runtimesettings]]]
                timestamped = true

and a test node:

[[98]]
    nodename = nodeMCU
    [[[rx]]]
       names = temp1, ext temp, temp2, humidity
       datacodes = h,h,h,h
       scales = 0.1,0.1,0.1,0.1
       units = C,C,C,%

When sending to emonhub, timestamp nodeid val1 val2 val3 val4, i get the following message in emonhub.log:

2018-01-29 23:58:09,808 DEBUG    LanRestarter 1 NEW FRAME : 1517263080.0 98 3.8 1.6 5.2 80.3
2018-01-29 23:58:09,810 WARNING  LanRestarter 1 RX data length: 4 is not valid for datacodes ['h', 'h', 'h', 'h']

Changing timestamped = false in the [[runtimesettings]] and sending nodeid val1 val2 val3 val4, produces this message in emonhub.log:

2018-01-30 09:53:22,282 DEBUG    MainThread Setting LanRestarter timestamped: false
2018-01-30 09:54:30,967 WARNING  LanRestarter Exception caught in LanRestarter thread. Traceback (most recent call last):
  File "/home/pi/emonhub/src/interfacers/emonhub_interfacer.py", line 38, in wrapper
    return f(*args)
  File "/home/pi/emonhub/src/interfacers/emonhub_interfacer.py", line 87, in run
    rxc = self.read()
  File "/home/pi/emonhub/src/interfacers/EmonHubSocketInterfacer.py", line 119, in read
    c.nodeid = int(f[0]) + int(self._settings['nodeoffset'])
ValueError: invalid literal for int() with base 10: '3.1'

2018-01-30 09:54:30,994 WARNING  MainThread LanRestarter thread is dead.
2018-01-30 09:54:30,995 WARNING  MainThread Attempting to restart thread LanRestarter (thread has been restarted 0 times...
2018-01-30 09:54:30,998 INFO     MainThread Creating EmonHubSocketInterfacer 'LanRestarter' 
2018-01-30 09:54:30,999 DEBUG    MainThread Opening socket on port 50012
2018-01-30 09:54:31,000 ERROR    MainThread [Errno 98] Address already in use
2018-01-30 09:54:31,001 ERROR    MainThread Unable to create 'LanRestarter' interfacer: global name 'EmonHubInterfacerInitError' is not defined

Ok, for the first “timestamped” instance the issue only arises from the use of datacodes, delete the datacodes line from your conf like so

[[98]]
    nodename = nodeMCU
    [[[rx]]]
       names = temp1, ext temp, temp2, humidity
       scales = 0.1,0.1,0.1,0.1
       units = C,C,C,%

and it should work fine.

The reason is, you cannot reconstruct the “full” values from raw byte data using datacodes when you are already passing “full” values.

your data payload of

1517263080.0 98 3.8 1.6 5.2 80.3

is actually (correctly) in the form of

timestamp nodeid full_value1 full_value2 full_value3 full_value4

where as by defining

datacodes = h,h,h,h

you are telling emonhub the data will not be in the form of “full” normal values but it will arrive as a stream of 8 (4 x 2 byte signed ints “h”) byte values (0-255) and emonhub is replying that the 4 value payload it received (3.8 1.6 5.2 80.3) cannot be decoded (reconstructed in to 4 values) using the 8 byte value template you defined.

By simply not defining the datacode(s) setting it defaults to the norm of not decoding the data stream.

In the second instance, that’s my fault for working from memory. The setting should be timestamped = True or timestamped = False or omitted for a default of False.

The way Python works a capital “F” is required for a False, “false” is not False and the “false” string results in a True when tested.

This has gone un-noticed because I only use timestamped = True or timestamped = true when passing a timestamped payload (both result in a True because neither is False) and I generally omit the setting for payloads without a timestamp rather than defining False.

In fact more often that not I will just comment and un-comment the setting like so

        #timestamped = True

as deleting or adding the hash is easier/quicker than typing “True” or “False” and less prone to input error it would seem.

So your “false” setting resulted in a True and the nodeid val1 val2 was parsed as if it had a timestamp ie the nodeid was taken as a timestamp and val1 was taken as the nodeid.

Changed timestamped = False, but there is still an issue:

2018-01-30 20:29:52,744 DEBUG    MainThread Setting LanRestarter timestamped: False
2018-01-30 20:31:12,355 WARNING  LanRestarter Exception caught in LanRestarter thread. Traceback (most recent call last):
  File "/home/pi/emonhub/src/interfacers/emonhub_interfacer.py", line 38, in wrapper
    return f(*args)
  File "/home/pi/emonhub/src/interfacers/emonhub_interfacer.py", line 87, in run
    rxc = self.read()
  File "/home/pi/emonhub/src/interfacers/EmonHubSocketInterfacer.py", line 119, in read
    c.nodeid = int(f[0]) + int(self._settings['nodeoffset'])
ValueError: invalid literal for int() with base 10: '6.8'

2018-01-30 20:31:12,450 WARNING  MainThread LanRestarter thread is dead.
2018-01-30 20:31:12,451 WARNING  MainThread Attempting to restart thread LanRestarter (thread has been restarted 1 times...

Then I changed timestamped = True and gave it another try:

2018-01-30 20:34:15,396 DEBUG    MainThread Setting LanRestarter timestamped: True
2018-01-30 20:35:05,579 DEBUG    LanRestarter 6 NEW FRAME : 1517337300.0 98 6.8 6.2 8.6 77.0
2018-01-30 20:35:05,581 DEBUG    LanRestarter 6 Timestamp : 1517337300.0
2018-01-30 20:35:05,582 DEBUG    LanRestarter 6 From Node : 98
2018-01-30 20:35:05,583 DEBUG    LanRestarter 6    Values : [0.68, 0.6200000000000001, 0.86, 7.7]
2018-01-30 20:35:05,584 DEBUG    LanRestarter 6 Sent to channel(start)' : ch1
2018-01-30 20:35:05,586 DEBUG    LanRestarter 6 Sent to channel(end)' : ch1
2018-01-30 20:39:52,423 DEBUG    LanRestarter 7 NEW FRAME : 1517337540.0 98 67.0 61.0 89.0 770.0
2018-01-30 20:39:52,425 DEBUG    LanRestarter 7 Timestamp : 1517337540.0
2018-01-30 20:39:52,427 DEBUG    LanRestarter 7 From Node : 98
2018-01-30 20:39:52,428 DEBUG    LanRestarter 7    Values : [6.7, 6.1000000000000005, 8.9, 77]
2018-01-30 20:39:52,429 DEBUG    LanRestarter 7 Sent to channel(start)' : ch1
2018-01-30 20:39:52,431 DEBUG    LanRestarter 7 Sent to channel(end)' : ch1

Now data seems to be accepted by emonhub, but it doesn’t appear in the inputs/feeds.
Don’t I have to configure pubchannels/subchannels in the EmonHubSocketInterfacer? I tried searching the documentation for their meaning, but didn’t find anything.

Can you provide more emonhub.log? Ideally I need to see what happens prior to the exception to understand what is happening. All I can determine from your snippet is that the payload probably had a “6.8” value in it somewhere.

Can you also test with the timestamped setting commented out or deleted to see if the default non-timestamped behavior is correct.

I expect that is most probably the case, this is something that is only made mandatory in the emonpi variant, however the same settings are used pretty much throughout so you could just copy them from the [[RFM2Pi]] section

        pubchannels = ToEmonCMS,
        subchannels = ToRFM12,

having said that it looks like the original defaults are still being found eg

2018-01-30 20:35:05,584 DEBUG    LanRestarter 6 Sent to channel(start)' : ch1

so you could just try adding the “ch1” channel to the emoncms and mqtt subchannels eg

        subchannels = ToEmonCMS, ch1

@TrystanLea as now confirmed this isn’t working as expected so to have non-timestamped payload delete or comment out the timestamped value altogether as any value there True,true,False,false will require a timestamp, this is a bug and I will take a look once i get a emonpi set up again.

[edit - Issue raised so it doesn’t get forgotten :slight_smile: ]

Prior to the exception I sent the six values to the emonhub socket (timestamp 98 6.8 6.2 8.6 77.0) and after that followed the log snippet I sent.

Nothing else happened since I am working in a test environment.

I think you mean (timestamp 98 6.8 6.2 8.6 77.0), had you sent a timestamp I would have worked, albeit with a timestamp. However just knowing the position of the “6.8” in the payload would have helped, Trystan has now tried this and confirmed the situation so I don’t need the log entries now.

For now comment out or delete the timestamped = line for non-timestamped data.

@TrystanLea has also confirmed data getting to emoncms so hopefully it should all work for you once you define the channel(s).

@lgheorghe and for anyone else interested, I put together the following python test script to test this feature:

import socket, time
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 8080))
s.sendall('98 3.8 1.6 5.2 80.3\r\n')

and my emonhub conf entry is:

[[sockettests]]
        Type = EmonHubSocketInterfacer
        [[[init_settings]]]
                port_nb = 8080
        [[[runtimesettings]]]
                pubchannels = ToEmonCMS,

Which results in the following emonhub.log

2018-01-30 22:11:03,782 DEBUG    sockettests 2 NEW FRAME : 98 3.8 1.6 5.2 80.3
2018-01-30 22:11:03,782 DEBUG    sockettests 2 Timestamp : 1517350263.78
2018-01-30 22:11:03,783 DEBUG    sockettests 2 From Node : 98
2018-01-30 22:11:03,783 DEBUG    sockettests 2    Values : [3.8, 1.6, 5.2, 80.3]
2018-01-30 22:11:03,783 DEBUG    sockettests 2 Sent to channel(start)' : ToEmonCMS
2018-01-30 22:11:03,783 DEBUG    sockettests 2 Sent to channel(end)' : ToEmonCMS

and emoncms inputs as expected when used with either the emoncms http interfacer or the mqtt interfacer.

You are right - it was without the timestamp.
The string sent was: 98 6.8 6.2 8.6 77.0 - where 98 is the nodeid and 6.8 is the first data value.

I’ve fixed the timestamp property bug and updated the emonhub configuration documentation with an example of how to use the socket interfacer, thanks @pb66 I can see how useful this interfacer could be now:

https://github.com/openenergymonitor/emonhub/blob/emon-pi/configuration.md