How to insert a node?

Hello

I am using a Raspi with Emonhub installed (without any radio module) and a serial/USB converter to get data from a sub system. The baud rate is 9600 and the values are separated by a TAB. There is no node ID.

I need to first update emonhub.conf like this:

[[my_device]]
    Type = EmonHubJeeInterfacer
    [[[init_settings]]]
        com_port = /dev/ttyUSB0
        com_baud = 9600
        # common com_baud options are 9600 38400 57600

Can I add the node ID in the conf file or should I insert a value in the interfacer?

Will the frames be decoded OK if there is a TAB between values?

Thanks for your help

Walter

Robert Wall's picture

Re: How to insert a node?

pb66's picture

Re: How to insert a node?

If you are not using a "Jee" type device then you should avoid using the EmonHubJeeInterfacer in favor of the EmonHubSerialInterfacer.

​Your [[[init_settings]]] look fine, but you you must have a [[[runtimesettings]]] even if it is not populated, it's a mandatory part of the structure. 

It is normal practice for the device to identify itself to emonhub using a nodeid, but it could be hardcoded to add a nodeid locally.

Adding a node to the [nodes] section of the conf will have no effect unless emonhub has a nodeid to look up, it cannot "get" a nodeid from the [nodes] section, 

I'm not sure about the TAB without doing some tests or research,

Paul

daturach's picture

Re: How to insert a node?

Thanks for your help. I managed to have something working. It did not work out of the box as expected. I had to split the stream of values at the \t (TAB) in the emonhub_interfacer script, "_process_frame" function. I replaced

frame = frame.strip().split(' ') by
frame = mynode + frame
frame = frame.strip().split('\t')

And added my hard coded node in the same function right after its definition. Notice the TAB after the nodeid.

mynode = "20\t"

The interfacers section looks like this in emonhub.conf. The rest is unchanged.

# This interfacer manages the RFM2Pi module
[[RFM2Pi]]
    Type = EmonHubSerialInterfacer
    [[[init_settings]]]
        #com_port = /dev/ttyAMA0
        com_port = /dev/ttyUSB0
        com_baud = 9600
        # common com_baud options are 9600 38400 57600
        #my_node = 17
    [[[runtimesettings]]]
        group = 210
        frequency = 433
        baseid = 15

 

A side note: I wanted to have the nodeid defined in emonhub.conf but did not managed to make that works.

Walter

 

pb66's picture

Re: How to insert a node?

Good to hear you got it working, I will try and factor the "/t" compatibility in with a future version if it fits in ok with existing stuff, I would also like to include csv too.

The node id will be indirectly factored into future versions as I am including a "node id offset" variable so that you can have multiple rfm networks by using a node id offset by 32 gives you the range 32 to 63 etc, To this I will add a "node id omitted" flag so the default settings will continue to not require any mandatory node id settings but you can add an offset (assumed to be zero if omitted by default) and then using a nodeid omitted = true (assumed false by default/omitted) the offset will be the actual node id. It has to be done this way so that emonhub knows whether the first value is a nodeid or a value and support the "normal" OEM packet format.

Paul

PS you can delete the group, baseid and frequency from the runtimesettings and give it a more appropriate name too, the [[RFM2Pi]] could be [[my_device]] as you mentioned in the OP.

 

daturach's picture

Re: How to insert a node?

Great, that looks interesting.

Regarding your PS: ok, will get rid of these parameters and rename the module.

One more thing: I added a 15 secs delay to slow down a bit the amount of data uploaded to emoncms.org. That would have been one update per second without it!

pb66's picture

Re: How to insert a node?

Where did you add the delay? this could block the program from running and miss data from another source, The send interval to emoncms can be set by adding eg "interval = 60" to the emoncms reporters runtimesettings to send no sooner than every 60secs, it will use bulk mode to send lots of data in one go (upto 250 packets in one post).

If you wish to limit the data from the serial device by polling at 15 sec intervals you should use a "if now is more than (last + 15 seconds) read serial" type test so the code can pass and comeback. See the run() function of the JeeListener as an example, that test is done every loop but only if the "interval" has passed will it re send the time for the glcd.

Paul    

daturach's picture

Re: How to insert a node?

I added here...(in emonhub_interfacer)

    def read(self):
        """Read data from serial port and process if complete line received.

        Return data as a list: [NodeID, val1, val2]

        """
        time.sleep(15)  # Time to wait for 15 secs before reading the port
        # Read serial RX
        self._rx_buf = self._rx_buf + self._ser.readline()

I have only one source. In fact, I like the idea of being able to read the data without actually sending them every second.
If I add the interval in the config file, all the data accumulated during that interval will be sent.
What do you mean by "packets"? one packet = all keys + node each sec in my case, so about 60 packets per minute??

Thanks

pb66's picture

Re: How to insert a node?

IMO that isn't the best way to do it, I don't know what your device is so can only speak generally.

If you were ok with extening to 15 secs you should stick with that and just change the delay mechanism, what will the faster interval give you that the 15s interval won't since you are sending the data every 60s+? aside from 15x as big data size and 15x as much work to process, store and sift through to report and graph?

That 1 feed will hog the storage and resources of 15 feeds and only provide 1/4 of the responsiveness due to the 1min updates, this is fine if on your own server (and you wouldn't need the send throttling either) but not so good for emoncms.org.

Paul

daturach's picture

Re: How to insert a node?

Thanks for your valuable comments. This is how the conf file looks like and I have removed the delay in the interfacer.

​
​[reporters]

# This reporter sends data to emonCMS
[[emonCMS]]
    Type = EmonHubEmoncmsReporter
    [[[init_settings]]]
    [[[runtimesettings]]]
        #url = http://localhost/emoncms
        url = http://emoncms.org
        apikey = my_key
        # see http://openenergymonitor.org/emon/node/11064
        interval = 60

#######################################################################
#######################       Interfacers       #######################
#######################################################################
[interfacers]

# This interfacer manages the RFM2Pi module
[[my_device]]
    #Type = EmonHubJeeInterfacer, don't use the Jee interfacer, see 
http://openenergymonitor.org/emon/node/11064
    Type = EmonHubSerialInterfacer
    [[[init_settings]]]
        #com_port = /dev/ttyAMA0
        com_port = /dev/openenergy
        #com_port = /dev/ttyUSB0
        com_baud = 9600
        # common com_baud options are 9600 38400 57600
        #my_node = 17
    [[[runtimesettings]]]
        #group = 210
        #frequency = 433
        #baseid = 15
pb66's picture

Re: How to insert a node?

Try adding something like

        now = time.time()
        if now - self._interval_timestamp < int(self._settings['interval']):
            return
        self._interval_timestamp = now

in place of the delay you had and then define the delay in emonhub.conf   [[my_device]]  [[runtimesettings]]]

        interval = 15

Paul

daturach's picture

Re: How to insert a node?

Thanks, it works perfectly. In the meantime, I added a "my_node" variable in the interfacers runtimesettings list of parameters. I updated a bit the emonhub_interfacer script and now I can define a node without going into the Python script.

Walter

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.