Emonhub stops working upon receiving unexpected data

Today i tested the way "backwards" by sending packets from MQTT via emonhub with "RFM69Pi 433Mhz Raspberry Pi Base Station Receiver Board" to a custom node. Result was basically it works. BUT only if i post the data exactly in the expected manner via MQTT. Once i send something "bad" its crashing some process within the system.

First the good case (emonhub log):

I injected the values 88 & 66 into MQTT topic ("emonhub/tx/19/values")

2016-01-12 18:20:51,189 DEBUG    MQTT       Nodeid: 19 values: 88,66
2016-01-12 18:20:51,192 DEBUG    MQTT       8 sent TX packet: 19,88,0,66,0,s
2016-01-12 18:20:51,194 DEBUG    MQTT       8 Sent to channel' : ToRFM12
2016-01-12 18:20:51,259 DEBUG    RFM2Pi     acknowledged command: > 19,88,0,66,0,0s
2016-01-12 18:20:51,361 DEBUG    RFM2Pi     confirmed sent packet size: -> 5 b

Data is received on Node 19 as expected -> everything good

Now the crash case (emonhub log):

I injected the value 555555 into MQTT topic ("emonhub/tx/19/values")

2016-01-12 18:21:04,853 DEBUG    MQTT       Nodeid: 19 values: 555555
2016-01-12 18:21:05,004 WARNING  MainThread MQTT thread is dead
2016-01-12 18:21:05,217 WARNING  MainThread MQTT thread is dead
2016-01-12 18:21:05,431 WARNING  MainThread MQTT thread is dead
2016-01-12 18:21:05,644 WARNING  MainThread MQTT thread is dead
2016-01-12 18:21:05,860 WARNING  MainThread MQTT thread is dead
2016-01-12 18:21:06,073 WARNING  MainThread MQTT thread is dead
2016-01-12 18:21:06,287 WARNING  MainThread MQTT thread is dead
2016-01-12 18:21:06,501 WARNING  MainThread MQTT thread is dead

And boom, the system is down and doesn't recover by itself until restarting the emonhub via:

> sudo service emonhub restart

I mean generally one should inject only sane data into the MQTT system but a little bit more robustness would be nice for a system which is supposed to run 24/7.

 

The system version is the SD Image from 22 dec 2015 and emoncms (updated on 10.1.16) states:

Powered by openenergymonitor.org | low-write 9.3 | 2015.12.30

 

pb66's picture

Re: Emonhub stops working upon receiving unexpected data

There doesn't appear to be any conditioning or processing of the data when using that method so it is dependent on a preformed and flawless packet.

The way this was intended to work in emonhub was the data would be "deconstructed" from real values using the datacodes and scales held in the nodes section of emonhub.conf for the target node or using the defaults for the dispatching interfacer if not specifically defined. This was functional in other interfacers in the "experimental" version this "emonpi" version has been based on, but the MQTT interfacer has since been added and the "reverse processing" bypassed. 

However regardless of how functional the code is, you are right it should not crash and it should indeed be more robust.

It looks like the crash occurs in this section of code

https://github.com/openenergymonitor/emonhub/blob/emon-pi/src/interfacers/EmonHubMqttInterfacer.py#L86-L94

​as the preceding log message from line 85 is seen but not the one in line 95 before the thread dies.

But once this error no longr causes a crash, any values <0 or >255 will cause the whole packet to be discarded with a log entry. see 

https://github.com/openenergymonitor/emonhub/blob/emon-pi/src/interfacers/EmonHubJeeInterfacer.py#L244-L249

​Paul

Comment viewing options

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