Emonhub with Jeelink in Ubuntu: can't decode byte

Hello
I am trying to replace a dead Raspi that was running my old “emohub” system.
I want to replace it with a Ubuntu 18.04 LTS virtual machine reading data from a Jeelink.

I have successfully installed Emoncms and Emonhub into the Ubuntu VM.
I edited the file /opt/openenergymonitor/emonhub/conf/emonhub.conf to let the service point to the Jeelink.
Upon emonhub service restart I can see the Jeelink flashing once (this means that emonhub is trying to initialize it).
The problem is that I get the infamous “can’t decode byte” error:

2020-08-11 07:37:02,682 DEBUG    MainThread Opening serial port: /dev/ttyUSB0 @ 9600 bits/s
2020-08-11 07:37:04,685 ERROR    MainThread Unable to create 'RFM2Pi' interfacer: 'utf-8' codec can't decode byte 0xa8 in position 5
: invalid start byte

I updated emonhub from emoncms… no improvement. Error is still there.

My config is this:

[[RFM2Pi]]
    Type = EmonHubJeeInterfacer
    [[[init_settings]]]
        com_port = /dev/ttyUSB0
        com_baud = 9600                      # 9600 for old RFM12Pi modules (I am replacing a very old RFM12pi)
    [[[runtimesettings]]]
        pubchannels = ToEmonCMS,
        subchannels = ToRFM12,

        group = 210
        frequency = 868	       # settings from my old Raspi conf file
        baseid = 15                              # emonPi / emonBase nodeID
        quiet = false                            # Report incomplete RF packets (no implemented on emonPi)
        calibration = 230V                      # (UK/EU: 230V, US: 110V)
        # interval =  0  

Any idea?
Thanks in advance.
Franz

Welcome, Franz, to the OEM forum.

Have you searched here for “decode byte”. There are several threads that might help you.

I’m not an expert in that area, so I cannot help you directly.

Thanks for the reply. I searched for the “decode byte” error but cannot find a definitive solution.
Latest posts on the issue are dated 2019 and I guess that the solution should have entered the official sw distribution channel.
If this is not the case I think I need to experiment and edit the “EmonHubJeeInterfacer.py” file.

Check syslog and see if there is a Python exception message.

[edit]

Try a try catch round the initialisation

Have you tried other speeds? It used to be hardcoded to 38400 (or just comment it out as that is the default).

Thanks for the suggestion.
Tried a catch before the init instruction but no exception is raised
try:
super().init(name, com_port, com_baud)
except InitError:
self._log.warning(“Failed init”)

self._log.warning("initialized i guess")

and this is what I get:
2020-08-11 14:04:55,057 INFO MainThread Creating EmonHubJeeInterfacer ‘RFM2Pi’
2020-08-11 14:04:55,073 DEBUG MainThread Opening serial port: /dev/ttyUSB0 @ 9600 bits/s
2020-08-11 14:04:55,073 WARNING MainThread initialized i guess
2020-08-11 14:04:57,076 ERROR MainThread Unable to create ‘RFM2Pi’ interfacer: ‘utf-8’ codec can’t decode byte 0x8c in position 1
2: invalid start byte

Commented out the baud rate: it defaults to 38400 but the error is the same…
Maybe my JeeLink is strange. This is what I ordered: JeeLink RFM12B 868MHz - PCA301
Do you think it is suitable for emonhub? (my system uses te 868Mhz frequency)

Did you do this?

Honestly, no idea.

I’m no python expert, but are you sure that is right? Try just except:

I think it must be failing somewhere in the init.

@bwduncan, any ideas?

Was that running a JeeLink too or is that a new addition?

IIRC a stock JeeLink v3 runs at a baud of 57600.

Also, you should delete or comment out this line in the emonhub.conf

As it means nothing to any other (Jee based) device except an emonPi.

1 Like

Interesting! It certainly looks like the wrong baud. Try a miniterm and see if the data are readable:

python3 -m serial.tools.miniterm /dev/ttyUSB0 57600

As @pb66 says, only 57600 should display anything sensible. It’s slightly surprising that it managed to decode 5 bytes (0-4) before finding one outside the valid range. It would be useful to see the data being returned. Trying logging it. You’ll obviously have to split the decode from the readline.

There is no InitError exception that I’m aware of, although i suspect the failure is not in the superclass init, but probably on one of the decode lines further down…

1 Like

Hello.
Nice find! the miniterm at 57600 seems fine and displays “[pcaSerial.10.1]” and a series of “available commands”.
If I run the terminal at 9600 then the output is garbage.
Emonhub is happy if I set 57600 on the baudrate.
I guess the initialization cannot change the baudrate.
Maybe I should try to upgrade my network to 57600 (even if that could mean shorter communication range).

Thanks Paul!
The problem seems to be in the initialization. Setting baudrate to 57600 makes emohbub happy.
Deleting the “calibration” variable did not make any improvement.

I did not find any python related exception in syslog (any specific string to search?)

My old emonPi died (raspberry LAN is broken) and I am trying to replace it using a Ubuntu VM.
In this way I can experiment with emonhub and emoncms in a pc environment.

Thanks very much for your help
Francesco

Great! Glad it’s working.

The code needs to know the baud rate the other side is using. In that sense it cannot “change” the baud rate because the device already knows what baud rate it is sending.

Which network are you referring to?

Good. Do you still get the same error?

Yes that is exactly what the setting is doing - setting the serial baud rate.

No need. This is just the speed the Serial port is communicating with the Jeelink device.

Ah! I was making a conceptual error!
The baudrate is between emoncms and the Jeelink (I thought it was the baudrate “on air”).
No more decode error now .
On the log I get this now:
2020-08-12 09:44:51,915 INFO MainThread Creating EmonHubJeeInterfacer ‘RFM2Pi’
2020-08-12 09:44:51,932 DEBUG MainThread Opening serial port: /dev/ttyUSB0 @ 57600 bits/s
2020-08-12 09:44:53,935 WARNING MainThread Device communication error - check settings
2020-08-12 09:44:53,936 INFO MainThread Setting RFM2Pi baseid: 15 (15i)

The warning above suggests me that emoncms cannot find the correct end of string “\r\n”.
Can this cause problems?
I am asking because I still cannot receive data from my emontx…

What else do you see in the logs after that point? Is there any response from the JeeLink seen in the logs?

If not, then try
a) a power cycle to restart everything cleanly after setting the correct baud (assuming it is correct at this stage)
b) using miniterm as previously suggested to see what output the JeeLink is providing, that will confirm whether it is recieving any data first. And also confirm the output formatting etc so we can see if there are any oddities that emonhub may not like, JeeLink is outside our control and not often used, although I have used them with no troubles what so ever, I now have custom FW on mine and do not run the current OEM emonHub so I cannot test the compatibility for you.

Post the logs and/or the miniterm output here for us to help you further.

Now I am trying to figure out why I cannot get data from my EmonTX
In the emonhub logs I get some random “unreliable content” like this
Discarding RX frame ‘unreliable content’? 24 61 1 231 13 195 227 157 24 180 183
I do not get any valid frame

I am sure that emontx is sending data (emonglcd receives the data correctly) but for some reason emonhub is unable to get it.
JeeLink is is set in this way:
— Settings: /dev/ttyUSB0 57600,8,N,1
— RTS: active DTR: active BREAK: inactive
— CTS: inactive DSR: inactive RI: inactive CD: inactive
— software flow control: inactive
— hardware flow control: inactive
— serial input encoding: UTF-8
— serial output encoding: UTF-8
— EOL: CRLF
— filters: default

Extended log:

2020-08-13 06:46:32,979 INFO     MainThread EmonHub emonHub (emon-pi variant) v2.1.5
2020-08-13 06:46:32,979 INFO     MainThread Opening hub...
2020-08-13 06:46:32,979 INFO     MainThread Logging level set to DEBUG
2020-08-13 06:46:32,979 INFO     MainThread Creating EmonHubJeeInterfacer 'RFM2Pi' 
2020-08-13 06:46:32,994 DEBUG    MainThread Opening serial port: /dev/ttyUSB0 @ 57600 bits/s
2020-08-13 06:46:34,996 WARNING  MainThread Device communication error - check settings
2020-08-13 06:46:34,996 INFO     MainThread Setting RFM2Pi baseid: 15 (15i)
2020-08-13 06:46:35,998 INFO     MainThread Setting RFM2Pi frequency: 868 (8b)
2020-08-13 06:46:36,999 INFO     MainThread Setting RFM2Pi group: 210 (210g)
2020-08-13 06:46:38,001 INFO     MainThread Setting RFM2Pi quiet: 0 (0q)
2020-08-13 06:46:39,003 INFO     MainThread Setting RFM2Pi calibration: 230V (1p)
2020-08-13 06:46:40,005 DEBUG    MainThread Setting RFM2Pi pubchannels: ['ToEmonCMS']
2020-08-13 06:46:40,005 DEBUG    MainThread Setting RFM2Pi subchannels: ['ToRFM12']
2020-08-13 06:46:40,005 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT' 
2020-08-13 06:46:40,006 DEBUG    MainThread Setting MQTT pubchannels: ['ToRFM12']
2020-08-13 06:46:40,006 DEBUG    MainThread Setting MQTT subchannels: ['ToEmonCMS']
2020-08-13 06:46:40,006 INFO     MainThread Setting MQTT node_format_enable: 1
2020-08-13 06:46:40,006 INFO     MainThread Setting MQTT nodevar_format_enable: 0
2020-08-13 06:46:40,006 INFO     MainThread Setting MQTT nodevar_format_basetopic: emon/
2020-08-13 06:46:40,006 INFO     MainThread Creating EmonHubEmoncmsHTTPInterfacer 'emoncmsorg' 
2020-08-13 06:46:40,006 DEBUG    MainThread Setting emoncmsorg interval: 30
2020-08-13 06:46:40,006 DEBUG    MainThread Setting emoncmsorg pubchannels: ['ToRFM12']
2020-08-13 06:46:40,006 DEBUG    MainThread Setting emoncmsorg subchannels: ['ToEmonCMS']
2020-08-13 06:46:40,006 INFO     MainThread Setting emoncmsorg apikey: set
2020-08-13 06:46:40,007 INFO     MainThread Setting emoncmsorg url: https://127.0.0.1
2020-08-13 06:46:40,007 INFO     MainThread Setting emoncmsorg senddata: 1
2020-08-13 06:46:40,007 INFO     MainThread Setting emoncmsorg sendstatus: 1
2020-08-13 06:46:40,613 DEBUG    RFM2Pi     acknowledged command: <n> a    - turn activity LED on PB1 on or off
2020-08-13 06:46:40,714 DEBUG    RFM2Pi     acknowledged command: <n> c    - config (0=fill, 1=load, 2=save, 3=erase)
2020-08-13 06:46:40,815 DEBUG    RFM2Pi     acknowledged command: <n> d    - turn off device <n>
2020-08-13 06:46:40,916 DEBUG    RFM2Pi     acknowledged command: <n> e    - turn on device <n>
2020-08-13 06:46:41,017 DEBUG    RFM2Pi     acknowledged command: 0x<hhhh> h    - set center frequency (Example 0xA6FE == Frequency - 868.9500MHz
2020-08-13 06:46:41,118 DEBUG    RFM2Pi     acknowledged command: <n> p    - poll device <n>
2020-08-13 06:46:41,219 DEBUG    RFM2Pi     acknowledged command: <n> r    - list recordings
2020-08-13 06:46:41,320 DEBUG    RFM2Pi     acknowledged command: <n> q    - quiet mode (1=suppress TX and bad packets)
2020-08-13 06:46:41,421 DEBUG    RFM2Pi     acknowledged command: <n> v    - version and configuration report
2020-08-13 06:46:42,228 DEBUG    RFM2Pi     acknowledged command: <n> a    - turn activity LED on PB1 on or off
2020-08-13 06:46:42,329 DEBUG    RFM2Pi     acknowledged command: <n> c    - config (0=fill, 1=load, 2=save, 3=erase)
2020-08-13 06:46:42,430 DEBUG    RFM2Pi     acknowledged command: <n> d    - turn off device <n>
2020-08-13 06:46:42,531 DEBUG    RFM2Pi     acknowledged command: <n> e    - turn on device <n>
2020-08-13 06:46:42,633 DEBUG    RFM2Pi     acknowledged command: 0x<hhhh> h    - set center frequency (Example 0xA6FE == Frequency - 868.9500MHz
2020-08-13 06:46:42,734 DEBUG    RFM2Pi     acknowledged command: <n> p    - poll device <n>
2020-08-13 06:46:42,836 DEBUG    RFM2Pi     acknowledged command: <n> r    - list recordings
2020-08-13 06:46:42,937 DEBUG    RFM2Pi     acknowledged command: <n> q    - quiet mode (1=suppress TX and bad packets)
2020-08-13 06:46:43,039 DEBUG    RFM2Pi     acknowledged command: <n> v    - version and configuration report
2020-08-13 06:46:43,844 DEBUG    RFM2Pi     acknowledged command: <n> a    - turn activity LED on PB1 on or off
2020-08-13 06:46:43,945 DEBUG    RFM2Pi     acknowledged command: <n> c    - config (0=fill, 1=load, 2=save, 3=erase)
2020-08-13 06:46:44,046 DEBUG    RFM2Pi     acknowledged command: <n> d    - turn off device <n>
2020-08-13 06:46:44,147 DEBUG    RFM2Pi     acknowledged command: <n> e    - turn on device <n>
2020-08-13 06:46:44,248 DEBUG    RFM2Pi     acknowledged command: 0x<hhhh> h    - set center frequency (Example 0xA6FE == Frequency - 868.9500MHz
2020-08-13 06:46:44,349 DEBUG    RFM2Pi     acknowledged command: <n> p    - poll device <n>
2020-08-13 06:46:44,450 DEBUG    RFM2Pi     acknowledged command: <n> r    - list recordings
2020-08-13 06:46:44,551 DEBUG    RFM2Pi     acknowledged command: <n> q    - quiet mode (1=suppress TX and bad packets)
2020-08-13 06:46:44,652 DEBUG    RFM2Pi     acknowledged command: <n> v    - version and configuration report
2020-08-13 06:46:56,433 DEBUG    RFM2Pi     Discarding RX frame 'unreliable content'? 24 31 194 205 158 31 136 97 63 161 4
2020-08-13 06:52:55,326 DEBUG    RFM2Pi     Discarding RX frame 'unreliable content'? 24 62 195 160 66 231 176 16 211 30 227
2020-08-13 06:57:21,870 DEBUG    RFM2Pi     Discarding RX frame 'unreliable content'? 24 224 40 80 163 99 231 227 158 255 128
2020-08-13 07:18:01,766 DEBUG    RFM2Pi     Discarding RX frame 'unreliable content'? 24 153 167 129 173 207 253 228 27 142 81
2020-08-13 07:26:36,190 DEBUG    RFM2Pi     Discarding RX frame 'unreliable content'? 24 209 43 111 114 255 78 124 102 156 255

For future reference, when posting code or bash output, put in 3 ‘backticks’ (found at the top left of the keyboard normally) on a line on their own, then the code, then 3 more backticks on a line following the code.

    ```
    code
    ```

If it is something like php you can add a language identifier that after the first 3 backticks so ```php

You are still not communicating correctly with the JeeLink device. Sorry, don’t know why or how to.

[edit]
What Jeelink device do you have?

@Robert.Wall, is it necessary to load an appropriate sketch onto the Jeelink device?

I have a JeeLink RFM12B 868MHz - PCA301 fhem
Querying the version using miniterm I get [pcaSerial.10.1]