Emonhub error? (Solved)

I've just reinstalled my system from scratch on a Pi v2, but following system restarts, emonhub sometimes does not run.and I get this error.
It occurred twice last night, but by restarting again, everything ran OK

pi@raspberrypi ~ $ sudo service emonhub restart
[ ok ] Restarting OpenEnergyMonitor emonHub: emonhub has been restarted ok.
pi@raspberrypi ~ $ Traceback (most recent call last):
  File "/usr/share/emonhub/emonhub.py", line 338, in <module> hub.run()
  File "/usr/share/emonhub/emonhub.py", line 90, in run values = I.read()
  File "/home/pi/emonhub/src/emonhub_interfacer.py", line 509, in read return self._process_frame(f, t)
  File "/home/pi/emonhub/src/emonhub_interfacer.py", line 101, in _process_frame validated = self._validate_frame(ref, frame)
  File "/home/pi/emonhub/src/emonhub_interfacer.py", line 531, in _validate_frame self.rssi = int(received[-1][1:-1])
ValueError: invalid literal for int() with base 10: '9C'

Any thoughts...

pb66's picture

Re: Emonhub error? (Solved)

Which RFM2Pi and firmware versions are you running ?

Line 531 just (strips parenthesis and) the casts the rssi value to an int. To get to that line there are several hoops and hurdles to sift out invalid packets, not least the "if the last value in this frame is enclosed in parenthesis " check immediately before it. Plus the "ValueError: invalid literal for int() with base 10: '9C'" could suggest that value is hex.

Can you see a emonhub.log entry for this ? emonHub may have added a "NEW FRAME" log entry (if in debug mode) and that line would probably end in " (9C) ".

I'm guessing you are using emonhub rc1.2(development branch) ?

I can look at adding an additional check to emonhub to make it more robust against being tripped up by this error as it could be a little more graceful and carry on after logging the issue.

Paul

Paul Reed's picture

Re: Emonhub error? (Solved)

Thanks Paul, this is what showed up in the emonhub log;

2015-09-19 21:45:32,183 INFO EmonHub Pre-Release Development Version (rc1.2)
2015-09-19 21:45:32,185 INFO Opening hub...
2015-09-19 21:45:40,953 WARNING 1 RX data length: 1 is not valid for datacode h
2015-09-19 21:45:45,901 WARNING 2 RX data length: 1 is not valid for datacode h
2015-09-19 22:02:36,090 INFO EmonHub Pre-Release Development Version (rc1.2)
2015-09-19 22:02:36,107 INFO Opening hub...
2015-09-19 22:03:32,532 WARNING 1 Discarded RX frame 'non-numerical content' : ['config', 'save', 'failed']
2015-09-19 22:03:32,948 WARNING 2 Discarded RX frame 'non-numerical content' : ['config', 'save', 'failed']
2015-09-19 22:03:33,368 WARNING 3 Discarded RX frame 'non-numerical content' : ['config', 'save', 'failed']

...and further investigation (thanks to the emonhub log) revealed a problem with a 'Retained MQTT Message' which contained a 13 digit number as it's payload, and was sent as soon as emoncms subscribed to that node, and almost certainly caused the issue above.

Background to this was I was testing emoncms by sending MQTT messages via node-red using qos 1 and with the retained flag set. Unfortunately I had forgot to format the payload, and the default payload is a 13 digit Unix Timestamp, so it was then immediately deleted.
However, I suspect that emoncms phpmqtt is not returning a MQTT Puback message, acknowledging receipt, and the 'timestamp' message was stored by the client as a Retained Message. So, despite a reboot, whenever emoncms subscribed to RX/# at startup, it was sent the 13 digit message which exceeds datacode h spec.

I've now cleared the Retained message cache, and have rebooted several times with no issues.

Paul

pb66's picture

Re: Emonhub error? (Solved)

Glad you got it sorted although I'm a little unsure how the value found it's way in via the serial port and so far into the code, if it was coming from the mqtt broker, do you have some mqtt handling in emonhub or is it stock?

Paul

Paul Reed's picture

Re: Emonhub error? (Solved)

It's stock, and I did think the same, but the only explanation that my limited knowledge could comprehend!

Paul

Comment viewing options

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