EMONHUB Crashing on Direct Serial Receive

Hi,

I have been trying to solve this issue for the last few days and have read everything that this forum and google has to offer but alas I cannot figure it out.

I have been using the standard openenergymonitor system for a few years now to monitor home power usage.

Recently I have wanted to expand to other monitoring so I am playing with a new emoncms installation to try other sensors. The emoncms I am using is the emonSD-17Jun2015.img.zip image.

With the new sensors I am using RF69 radios and a direct USB connection with a moteinousb to RPi. I have also tried direct serial connection to the RPi with the same result.

The problem is, that when I add a EmonHubSerialInterfacer to the configuration I get the following message on the console:

root@emonpi:~# Exception in thread SerialDirect:

Traceback (most recent call last):

File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner self.run()

File "/home/pi/emonhub/src/interfacers/emonhub_interfacer.py", line 73, in run rxc = self.read()

File "/home/pi/emonhub/src/interfacers/EmonHubserialInterfacer.py", line 81, in read c = new_cargo(rawdata=f)

NameError: global name 'new_cargo' is not defined

and the emonhub.log:

pi@emonpi /var/log/emonhub $ cat emonhub.log
2015-07-05 11:31:59,015 INFO     MainThread EmonHub emonHub 'emon-pi' variant v1.0
2015-07-05 11:31:59,017 INFO     MainThread Opening hub...
2015-07-05 11:31:59,019 INFO     MainThread Logging level set to DEBUG
2015-07-05 11:31:59,020 INFO     MainThread Creating EmonHubSerialInterfacer 'SerialDirect'
2015-07-05 11:31:59,024 DEBUG    MainThread Opening serial port: /dev/ttyUSB0 @ 9600 bits/s
2015-07-05 11:31:59,027 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT'
2015-07-05 11:31:59,029 INFO     MainThread MQTT Init mqtt_host=127.0.0.1 mqtt_port=1883
2015-07-05 11:31:59,036 DEBUG    MainThread MQTT Subscribed to channel' : ToEmonCMS
2015-07-05 11:31:59,038 INFO     MainThread Creating EmonHubEmoncmsHTTPInterfacer 'emoncmsorg'
2015-07-05 11:31:59,041 DEBUG    MainThread emoncmsorg Subscribed to channel' : ToEmonCMS
2015-07-05 11:31:59,138 INFO     MQTT       Connecting to MQTT Server
2015-07-05 11:31:59,147 INFO     MQTT       connection status: Connection successful
2015-07-05 11:31:59,149 DEBUG    MQTT       CONACK => Return code: 0
2015-07-05 11:31:59,252 INFO     MQTT       on_subscribe
2015-07-05 12:18:08,720 WARNING  MainThread SerialDirect thread is dead
2015-07-05 12:18:08,928 WARNING  MainThread SerialDirect thread is dead

I have cut everything back to basics so only sending node number and humidity, here is the minicom report of serial input on the Pi:

pi@emonpi /var/log $ minicom -D /dev/ttyUSB0 -b 9600

Welcome to minicom 2.6.1

OPTIONS: I18n
Compiled on Apr 28 2012, 19:24:31.
Port /dev/ttyUSB0

Press CTRL-A Z for help on special keys

19 6450
19 6450
19 6450
19 6450
19 6440
19 6450
19 6450
19 6450
19 6450
19 6450

I have tried all the different datacode suggestions (including no datacode) but cannot seem to prevent emonhub from crashing.

Any suggestions would be most appreciated.

 

Cheers,

Paddy

pb66's picture

Re: EMONHUB Crashing on Direct Serial Receive

I don't think you have configured anything to cause this issue, from what I see the "serial-direct" settings appear correct and the node/datacode settings will not influence this type of error.

The traceback and error suggest an import issue, looking at the emonhub "emon-pi" variant repo, it's unclear (to me) exactly how the import hierarchy is structured, but it does appear the Cargo module is imported directly into the EmonHubJeeInterfacer rather than the core EmonHubInterfacer and therefore not seen in the SerialInterfacer, so you could try adding "import Cargo" to the imports in EmonHubSerialInterfacer, usually found at  /home/pi/emonhub/src/interfacers/EmonHubSerialInterfacers.py.

Paul

paddy's picture

Re: EMONHUB Crashing on Direct Serial Receive

Hi Paul,

Thanks for taking the time to look at this.

I added import Cargo to the imports as below and rebooted but I still get the same error message.

pi@emonpi ~/emonhub/src/interfacers $ sudo nano EmonHubSerialInterfacer.py
import serial
import time
import Cargo
from pydispatch import dispatcher
import emonhub_interfacer as ehi

"""class EmonhubSerialInterfacer

 

Regards,

Paddy

pb66's picture

Re: EMONHUB Crashing on Direct Serial Receive

paddy's picture

Re: EMONHUB Crashing on Direct Serial Receive

Hi Paul,

I actually just found that difference and the change fixed the problem.

I would never have thought to look there without your pointer.

Thank you very much!

Cheers,

Paddy

pb66's picture

Re: EMONHUB Crashing on Direct Serial Receive

paddy's picture

Re: EMONHUB Crashing on Direct Serial Receive

Hi Paul,

I may have found another glitch. Data was logging fine for a while and then I got this error at the console:

root@emonpi:~# Exception in thread SerialDirect:

Traceback (most recent call last):

File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner self.run()

File "/home/pi/emonhub/src/interfacers/emonhub_interfacer.py", line 73, in run rxc = self.read()

File "/home/pi/emonhub/src/interfacers/EmonHubserialInterfacer.py", line 90, in read c.nodeid = int(f[0])

ValueError: invalid literal for int() with base 10: 'sendtoWait'

Cheers.

Paddy

pb66's picture

Re: EMONHUB Crashing on Direct Serial Receive

Hi Paddy,

This is happening because there is some non-numeric content ie  'sendtoWait' coming in via the serial and tripping emonhub up. basically that "c.nodeid = int(f[0])" comes way before any validation or sanity checks are done and it fall over if f[0] isn't an int.

I sthere a particular reason you have opted for the "emon-pi" variant? is there something you need on the "current" post emonPi image that isn't on the "previous" pre emonPi image?

The reason I ask is the original emonHub has better error handling, not only would this particular fault not occur, if it did it would be easier to fix as it would appear in the logs.

The version you are using is based heavily on the "experimental" branch of emonhub which was not a release version just a proof of concept, Additional work has been done to it by T & G to implement new features predominantly to marry the emonPi to the latest v8.5 low-write emoncms and so some parts have probably been bug tested more than others. It was probally assumed the serial port is permanently occupied by the emonPi board or a RFM2Pi.

You can either try testing for an int immediately before that code, which is a quick and very dirty fix that may just push the issue down the line, ensure you only ever get the correct data format coming in via the serial port, introduce some proper sanity checks (but I would argue this isn't the right place for them) or use the previous image with "original" emonhub.

I would recommend the latter and use original emonhub for what is being specifically discussed here.

Paul

paddy's picture

Re: EMONHUB Crashing on Direct Serial Receive

Hi Paul,

I guess I just went with the latest SD Image. I haven't really been following the recent emon developments and I am not sure what post emonPi and pre emonPi is? I didn't pick up from this post that this was "experimental" as it indicated that this is what is currently shipping on new hardware http://openenergymonitor.org/emon/node/10729

Out of frustration I did try an older image this weekend but I couldn't even get the web page up on that.

Where can I get the latest version of the "original" emonhub? As you suggest this sounds like what I should be using.

Cheers,

Paddy

 

 

pb66's picture

Re: EMONHUB Crashing on Direct Serial Receive

emonPi is the latest hardware release out of the OEM stable, it was crowd funded on kickstarter recently.

There was a new SDcard image with a lot of changes released for the emonPi and that same image is intended to replace the SDcard image that was "current" immediately prior to the emonPi release.

So the Post emonPi release image is more cutting edge and has a lot of good stuff focused more towards the emonPi where as the earlier image is less biased to the emonPi and far more familiar, tried and tested for trying less mainstream stuff (IMO)

The emonPi image contains a version of emonHub called "emon-pi" which is BASED on the experimental branch, As I said additional work has been done to make it suit the emonPi image, I didn't say it was experimental, but it is focused and still being developed.

See the OLD: Raspberry Pi 2 pre-built SD card image (emonSD-13-03-15.img) BETA thread for the earlier image. Or was this the image you tried but had issues with?

Paul

paddy's picture

Re: EMONHUB Crashing on Direct Serial Receive

Hi Paul,

I guess the terminology may be a little confusing. I have been running emon on raspberry Pi's with RFM12Pi's for a couple of years, but I don't have an emonPi.

Anyway even after fixing my code I am finding the emon-pi version of emonHub quite unstable, so will go to as pre emonp-pi version as you suggest. The version that I tried and had issues with was indeed emonSD-13-03-15.img but I shall give it another go.

Thanks again for your help.

Cheers,

Paddy

Comment viewing options

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