I’ve got a python3 port of emonhub running on my emonpi. Everything seems to work but I’m aware that I’m testing a really small subset of what emonhub can do.
I’d really appreciate it if people who are in the position to do so could test this on the own systems. I’m more than happy to help to debug problems.
In the process of getting used to the code I tidied up a few things. I hope these changes are welcome.
This is a Raspberry Pi 2 Model B Rev 1.1 running Buster. It’s a standard emonPi from many years ago.
I suspect it would be much more reliable to build a debian package for this and let apt deal with the mosquitto/python/etc dependencies. That’s outside my expertise for now but I may be learning how to do this for work in the new year!
If we are to go down the path of deprecating support for older versions, there are some other bits which would welcome a cleaup (interfacer modules with the wrong name, for example). There’s almost 5000 lines of code, a lot of which is repeated, and newer python features could make this smaller and more readable. All that might be more effort than it’s worth, though, unless someone smarter than me can come up with a test suite!
Anyway, the python3 port has been running on my system for about 12 hours now.
Good question, not sure (It isn’t an EmonPi then). Look at your invoice (that is what I do!). I think there may be something in ‘Learn’ that helps identify it.
Haha ok I’m not opening it up to figure out what radio module it has. It’s whatever came with the emonPi in January 2016. The invoice just says “emonPi”, so…
OK, The EmonPi is different to the EmonBase, hence my question. The EmonBase is just an RFM card that goes on any Pi. The EmonPi is (effectively) an EmonTX with an RFM module built in all in one case.
2019-12-09 19:23:27,588 WARNING MainThread RFM2Pi thread is dead.
2019-12-09 19:23:27,593 WARNING MainThread Attempting to restart thread RFM2Pi (thread has been restarted 4 times...
2019-12-09 19:23:27,598 INFO MainThread Creating EmonHubJeeInterfacer 'RFM2Pi'
2019-12-09 19:23:27,604 DEBUG MainThread Opening serial port: /dev/ttyAMA0 @ 38400 bits/s
2019-12-09 19:23:29,612 WARNING MainThread Device communication error - check settings
2019-12-09 19:23:29,621 INFO MainThread Setting RFM2Pi baseid: 12 (12i)
2019-12-09 19:23:30,627 INFO MainThread Setting RFM2Pi frequency: 433 (4b)
2019-12-09 19:23:31,632 INFO MainThread Setting RFM2Pi group: 210 (210g)
2019-12-09 19:23:32,637 INFO MainThread Setting RFM2Pi quiet: 1 (1q)
2019-12-09 19:23:33,643 INFO MainThread Setting RFM2Pi calibration: 230V (1p)
2019-12-09 19:23:34,648 DEBUG MainThread Setting RFM2Pi pubchannels: ['ToEmonCMS']
2019-12-09 19:23:34,656 DEBUG MainThread Setting RFM2Pi subchannels: ['ToRFM12']
2019-12-09 19:23:37,432 WARNING RFM2Pi Exception caught in RFM2Pi thread. Traceback (most recent call last):
File "/opt/openenergymonitor/emonhub/src/emonhub_interfacer.py", line 32, in wrapper
return f(*args)
File "/opt/openenergymonitor/emonhub/src/emonhub_interfacer.py", line 99, in run
rxc = self.read()
File "/opt/openenergymonitor/emonhub/src/interfacers/EmonHubJeeInterfacer.py", line 84, in read
self._rx_buf = self._rx_buf + self._ser.readline().decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 1: invalid start byte
Interestingly (this was the first time I’d used this Pi for this), I then installed the emon-pi variant (which worked), but the exception disappeared! It now just does not work and sits.
2019-12-09 19:40:22,282 INFO MainThread EmonHub emonHub emon-pi variant v2.1.2
2019-12-09 19:40:22,291 INFO MainThread Opening hub...
2019-12-09 19:40:22,295 INFO MainThread Logging level set to DEBUG
2019-12-09 19:40:22,299 INFO MainThread Creating EmonHubJeeInterfacer 'RFM2Pi'
2019-12-09 19:40:22,308 DEBUG MainThread Opening serial port: /dev/ttyAMA0 @ 38400 bits/s
2019-12-09 19:40:24,342 ERROR MainThread Unable to create 'RFM2Pi' interfacer: 'utf-8' codec can't decode byte 0x80 in position 1: invalid start byte
2019-12-09 19:40:24,345 INFO MainThread Creating EmonHubMqttInterfacer 'MQTT'
2019-12-09 19:40:24,356 DEBUG MainThread Setting MQTT pubchannels: ['ToRFM12']
2019-12-09 19:40:24,359 DEBUG MainThread Setting MQTT subchannels: ['ToEmonCMS']
2019-12-09 19:40:24,362 INFO MainThread Setting MQTT node_format_enable: 1
2019-12-09 19:40:24,365 INFO MainThread Setting MQTT nodevar_format_enable: 1
2019-12-09 19:40:24,367 INFO MainThread Setting MQTT nodevar_format_basetopic: emon/
2019-12-09 19:40:24,374 INFO MainThread Creating EmonHubEmoncmsHTTPInterfacer 'emoncmsorg'
2019-12-09 19:40:24,379 DEBUG MainThread Setting emoncmsorg pubchannels: ['ToRFM12']
2019-12-09 19:40:24,382 DEBUG MainThread Setting emoncmsorg subchannels: ['ToEmonCMS']
2019-12-09 19:40:24,385 WARNING MainThread Setting emoncmsorg apikey: obscured
2019-12-09 19:40:24,388 INFO MainThread Setting emoncmsorg url: https://emoncms.org
2019-12-09 19:40:24,390 INFO MainThread Setting emoncmsorg senddata: 1
2019-12-09 19:40:24,393 INFO MainThread Setting emoncmsorg sendstatus: 1
Log of successful emon-pi start (same config file).
2019-12-09 19:46:36,631 INFO MainThread EmonHub emonHub emon-pi variant v2.1.2
2019-12-09 19:46:36,634 INFO MainThread Opening hub...
2019-12-09 19:46:36,637 INFO MainThread Logging level set to DEBUG
2019-12-09 19:46:36,641 INFO MainThread Creating EmonHubJeeInterfacer 'RFM2Pi'
2019-12-09 19:46:36,651 DEBUG MainThread Opening serial port: /dev/ttyAMA0 @ 9600 bits/s
2019-12-09 19:46:38,659 INFO MainThread RFM2Pi device firmware version & configuration: not available
2019-12-09 19:46:38,664 INFO MainThread Setting RFM2Pi frequency: 433 (4b)
2019-12-09 19:46:39,670 INFO MainThread Setting RFM2Pi group: 210 (210g)
2019-12-09 19:46:40,676 INFO MainThread Setting RFM2Pi quiet: 0 (0q)
2019-12-09 19:46:41,682 INFO MainThread Setting RFM2Pi baseid: 5 (5i)
2019-12-09 19:46:42,687 INFO MainThread Setting RFM2Pi calibration: 230V (1p)
2019-12-09 19:46:43,693 DEBUG MainThread Setting RFM2Pi subchannels: ['ToRFM12']
2019-12-09 19:46:43,702 DEBUG MainThread Setting RFM2Pi pubchannels: ['ToEmonCMS']
2019-12-09 19:46:43,709 INFO MainThread Creating EmonHubMqttInterfacer 'MQTT'
2019-12-09 19:46:43,725 DEBUG MainThread Setting MQTT subchannels: ['ToEmonCMS']
2019-12-09 19:46:43,715 DEBUG RFM2Pi acknowledged command: > 4b
2019-12-09 19:46:43,733 DEBUG MainThread Setting MQTT pubchannels: ['ToRFM12']
2019-12-09 19:46:43,738 INFO MainThread Setting MQTT nodevar_format_enable: 1
2019-12-09 19:46:43,742 INFO MainThread Setting MQTT node_format_enable: 1
2019-12-09 19:46:43,746 INFO MainThread Setting MQTT nodevar_format_basetopic: emon/
2019-12-09 19:46:43,752 INFO MainThread Creating EmonHubEmoncmsHTTPInterfacer 'emoncmsorg'
2019-12-09 19:46:43,760 DEBUG MainThread Setting emoncmsorg subchannels: ['ToEmonCMS']
2019-12-09 19:46:43,764 DEBUG MainThread Setting emoncmsorg pubchannels: ['ToRFM12']
2019-12-09 19:46:43,768 INFO MainThread Setting emoncmsorg url: https://emoncms.org
2019-12-09 19:46:43,772 INFO MainThread Setting emoncmsorg senddata: 1
2019-12-09 19:46:43,777 WARNING MainThread Setting emoncmsorg apikey: obscured
2019-12-09 19:46:43,781 INFO MainThread Setting emoncmsorg sendstatus: 1
2019-12-09 19:46:43,938 DEBUG RFM2Pi acknowledged command: > 210g
2019-12-09 19:46:44,153 DEBUG RFM2Pi 1 NEW FRAME : 19 205 0 0 0 124 1 23 0
2019-12-09 19:46:44,163 DEBUG RFM2Pi 1 Timestamp : 1575920804.15
2019-12-09 19:46:44,168 DEBUG RFM2Pi 1 From Node : 19
2019-12-09 19:46:44,171 DEBUG RFM2Pi 1 Values : [20.5, 0, 38, 2.3000000000000003]
2019-12-09 19:46:44,176 DEBUG RFM2Pi 1 Sent to channel(start)' : ToEmonCMS
2019-12-09 19:46:44,180 DEBUG RFM2Pi 1 Sent to channel(end)' : ToEmonCMS
Hi @borpin, good work, thank you very much. I’ve fixed that bug and bumped the version to 3 (hope that doesn’t step on any toes, it matches the compatible python version and it’s not like we’ll run out of numbers…). Thanks, Bruce
Version would I think be better as 3.0.0-beta so it can go to 3.0.0 when released. As it is a significant change, under semantic versioning, it should go to V3.0.0 when released.
cd /opt/openenergymonitor/emonhub
git checkout -b bwduncan-python3 emon-pi
git pull https://github.com/bwduncan/emonhub.git python3
sudo service emonhub restart
I get the error:
emonhub.service: Failed with result 'exit-code'.
Running emonhub manually:
pi@emonpi:/opt/openenergymonitor/emonhub $ /usr/local/bin/emonhub/emonhub.py --config-file=/etc/emonhub/emonhub.conf
Traceback (most recent call last):
File "/usr/local/bin/emonhub/emonhub.py", line 23, in <module>
import emonhub_setup as ehs
File "/opt/openenergymonitor/emonhub/src/emonhub_setup.py", line 13, in <module>
from configobj import ConfigObj
ModuleNotFoundError: No module named 'configobj'
I must be missing a step or testing the wrong version?
I think the python3-configobj package isn’t installed. The install.sh script installs this package and I think I was relying on that script being run as part of the update to get all the modules. Not sure if that’s a valid assumption. Anyway, can you try running the script and see if it works?