Reading from a SDM120 meter using EmonHub

Agreed and that is how I think it should be.

The risk is, merging directly to master, if someone is running master and using SDM120 and decides to do an update while all this is going on, they could easily break their system and wonder why!

Before doing anything, I take a branch off master and update that branch. You can then easily merge to master once it all works. Of course I cannot merge directly anyway :laughing:.

they should be aware they are using the oem equivalent of a staging dev branch.

The only issue (aside from the names) is that (IMO) the repo’s should use/display the stable branch by default and only hotfixes PR’d to that repo, features and rewrites go from a feature branch to master (aka dev).

1 Like

Yes I agree that would help ensure most people use the stable branch, the current arrangement does encourage the use of master for those installing manually

1 Like

OK, so I:
a) flipped the A/B terminals on the RS485/USB converter (I can see me doing this again…)
b)applied your git pull
c)restarted emonhub

emonhub runs, but there doesn’t seem to be any SDM data.

disclaimer: I have played a bit with RPi and python in the past, but it’s few and far between, so while I can ssh and execute commands, I really have no idea what I’m doing. And a little knowledge is a dangerous thing - so best treat me like an idiot. Meanwhile, here’s a chunk of log:

2021-01-21 16:13:20,583 INFO     MainThread Exiting hub...
2021-01-21 16:13:32,335 INFO     MainThread Exit completed
2021-01-21 16:13:34,897 INFO     MainThread EmonHub emonHub (emon-pi variant) v2.1.5
2021-01-21 16:13:34,898 INFO     MainThread Opening hub...
2021-01-21 16:13:34,899 INFO     MainThread Logging level set to DEBUG
2021-01-21 16:13:34,900 INFO     MainThread Creating EmonHubJeeInterfacer 'RFM2Pi'
2021-01-21 16:13:34,902 DEBUG    MainThread Opening serial port: /dev/ttyAMA0 @ 38400 bits/s
2021-01-21 16:13:36,910 INFO     MainThread RFM2Pi device firmware version & configuration: not available
2021-01-21 16:13:36,911 INFO     MainThread Setting RFM2Pi baseid: 5 (5i)
2021-01-21 16:13:37,913 INFO     MainThread Setting RFM2Pi frequency: 433 (4b)
2021-01-21 16:13:38,916 INFO     MainThread Setting RFM2Pi group: 210 (210g)
2021-01-21 16:13:39,918 INFO     MainThread Setting RFM2Pi quiet: 1 (1q)
2021-01-21 16:13:40,920 INFO     MainThread Setting RFM2Pi calibration: 230V (1p)
2021-01-21 16:13:41,923 DEBUG    MainThread Setting RFM2Pi pubchannels: ['ToEmonCMS']
2021-01-21 16:13:41,924 DEBUG    MainThread Setting RFM2Pi subchannels: ['ToRFM12']
2021-01-21 16:13:41,927 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT'
2021-01-21 16:13:41,932 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-21 16:13:41,933 DEBUG    MainThread Setting MQTT pubchannels: ['ToRFM12']
2021-01-21 16:13:41,935 DEBUG    MainThread Setting MQTT subchannels: ['ToEmonCMS']
2021-01-21 16:13:41,936 INFO     MainThread Setting MQTT node_format_enable: 1
2021-01-21 16:13:41,937 INFO     MainThread Setting MQTT nodevar_format_enable: 1
2021-01-21 16:13:41,938 INFO     MainThread Setting MQTT nodevar_format_basetopic: emon/
2021-01-21 16:13:41,939 INFO     MainThread Creating EmonHubEmoncmsHTTPInterfacer 'emoncmsorg'
2021-01-21 16:13:41,941 DEBUG    MainThread Setting emoncmsorg pubchannels: ['ToRFM12']
2021-01-21 16:13:41,942 DEBUG    MainThread Setting emoncmsorg subchannels: ['ToEmonCMS']
2021-01-21 16:13:41,943 WARNING  MainThread Setting emoncmsorg apikey: obscured
2021-01-21 16:13:41,943 INFO     MainThread Setting emoncmsorg url: https://emoncms.org
2021-01-21 16:13:41,944 INFO     MainThread Setting emoncmsorg senddata: 1
2021-01-21 16:13:41,944 INFO     MainThread Setting emoncmsorg sendstatus: 1
2021-01-21 16:13:41,946 INFO     MainThread Creating EmonHubSDM120Interfacer 'SDM120'
2021-01-21 16:13:41,958 INFO     MainThread Connecting to SDM120 device=/dev/ttyUSB0 baud=2400
2021-01-21 16:13:41,961 INFO     MainThread Setting SDM120 read_interval: 10
2021-01-21 16:13:41,962 INFO     MainThread Setting SDM120 nodename: SDM120
2021-01-21 16:13:41,962 INFO     MainThread Setting SDM120 prefix: 
2021-01-21 16:13:41,963 DEBUG    MainThread Setting SDM120 pubchannels: ['ToEmonCMS']
2021-01-21 16:13:42,037 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-21 16:13:42,141 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-21 16:13:42,249 DEBUG    RFM2Pi     1 NEW FRAME : OK 5 238 252 232 255 214 252 2 93 0 0 0 0 0 0 0 0 0 0 0 0 249 224 0 0 (-0)
2021-01-21 16:13:42,252 DEBUG    RFM2Pi     1 Timestamp : 1611245622.249539
2021-01-21 16:13:42,253 DEBUG    RFM2Pi     1 From Node : 5
2021-01-21 16:13:42,253 DEBUG    RFM2Pi     1    Values : [-786, -24, -810, 238.1, 0, 0, 0, 0, 0, 0, 57593]
2021-01-21 16:13:42,254 DEBUG    RFM2Pi     1 Sent to channel(start)' : ToEmonCMS
2021-01-21 16:13:42,254 DEBUG    RFM2Pi     1 Sent to channel(end)' : ToEmonCMS
2021-01-21 16:13:42,358 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-21 16:13:42,441 INFO     MQTT       Connecting to MQTT Server
2021-01-21 16:13:42,462 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-21 16:13:42,545 INFO     MQTT       connection status: Connection successful
2021-01-21 16:13:42,546 DEBUG    MQTT       CONACK => Return code: 0
2021-01-21 16:13:42,557 DEBUG    emoncmsorg Buffer size: 1
2021-01-21 16:13:42,648 INFO     MQTT       on_subscribe
2021-01-21 16:13:44,688 DEBUG    RFM2Pi     2 NEW FRAME : OK 5 234 252 233 255 211 252 36 93 0 0 0 0 0 0 0 0 0 0 0 0 252 224 0 0 (-0)
2021-01-21 16:13:44,690 DEBUG    RFM2Pi     2 Timestamp : 1611245624.688024
2021-01-21 16:13:44,691 DEBUG    RFM2Pi     2 From Node : 5
2021-01-21 16:13:44,691 DEBUG    RFM2Pi     2    Values : [-790, -23, -813, 238.44, 0, 0, 0, 0, 0, 0, 57596]
2021-01-21 16:13:44,692 DEBUG    RFM2Pi     2 Sent to channel(start)' : ToEmonCMS
2021-01-21 16:13:44,693 DEBUG    RFM2Pi     2 Sent to channel(end)' : ToEmonCMS
2021-01-21 16:13:44,964 DEBUG    MQTT       Publishing: emon/emonpi/power1 -790
2021-01-21 16:13:44,966 DEBUG    MQTT       Publishing: emon/emonpi/power2 -23
2021-01-21 16:13:44,968 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -813
2021-01-21 16:13:44,970 DEBUG    MQTT       Publishing: emon/emonpi/vrms 238.44
2021-01-21 16:13:44,972 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-21 16:13:44,974 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-21 16:13:44,976 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-21 16:13:44,978 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-21 16:13:44,979 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-21 16:13:44,981 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-21 16:13:44,982 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 57596
2021-01-21 16:13:44,984 INFO     MQTT       Publishing 'node' formatted msg
2021-01-21 16:13:44,984 DEBUG    MQTT       Publishing: emonhub/rx/5/values -790,-23,-813,238.44,0,0,0,0,0,0,57596
2021-01-21 16:13:49,642 DEBUG    RFM2Pi     3 NEW FRAME : OK 5 234 252 233 255 211 252 44 93 0 0 0 0 0 0 0 0 0 0 0 0 0 225 0 0 (-0)
2021-01-21 16:13:49,645 DEBUG    RFM2Pi     3 Timestamp : 1611245629.642466
2021-01-21 16:13:49,645 DEBUG    RFM2Pi     3 From Node : 5
2021-01-21 16:13:49,646 DEBUG    RFM2Pi     3    Values : [-790, -23, -813, 238.52, 0, 0, 0, 0, 0, 0, 57600]
2021-01-21 16:13:49,647 DEBUG    RFM2Pi     3 Sent to channel(start)' : ToEmonCMS
2021-01-21 16:13:49,647 DEBUG    RFM2Pi     3 Sent to channel(end)' : ToEmonCMS
2021-01-21 16:13:49,757 DEBUG    MQTT       Publishing: emon/emonpi/power1 -790
2021-01-21 16:13:49,758 DEBUG    MQTT       Publishing: emon/emonpi/power2 -23
2021-01-21 16:13:49,760 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -813
2021-01-21 16:13:49,761 DEBUG    MQTT       Publishing: emon/emonpi/vrms 238.52
2021-01-21 16:13:49,762 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-21 16:13:49,764 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-21 16:13:49,765 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-21 16:13:49,766 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-21 16:13:49,768 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-21 16:13:49,769 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-21 16:13:49,771 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 57600
2021-01-21 16:13:49,772 INFO     MQTT       Publishing 'node' formatted msg
2021-01-21 16:13:49,773 DEBUG    MQTT       Publishing: emonhub/rx/5/values -790,-23,-813,238.52,0,0,0,0,0,0,57600
2021-01-21 16:13:53,877 DEBUG    RFM2Pi     5 NEW FRAME : OK 23 56 0 0 0 158 3 31 0 1 0 0 0 (-65)
2021-01-21 16:13:53,880 DEBUG    RFM2Pi     5 Timestamp : 1611245633.877559
2021-01-21 16:13:53,881 DEBUG    RFM2Pi     5 From Node : 23
2021-01-21 16:13:53,881 DEBUG    RFM2Pi     5    Values : [5.6000000000000005, 0, 92.60000000000001, 3.1, 1]
2021-01-21 16:13:53,882 DEBUG    RFM2Pi     5      RSSI : -65
2021-01-21 16:13:53,882 DEBUG    RFM2Pi     5 Sent to channel(start)' : ToEmonCMS
2021-01-21 16:13:53,883 DEBUG    RFM2Pi     5 Sent to channel(end)' : ToEmonCMS
2021-01-21 16:13:54,114 DEBUG    MQTT       Publishing: emon/emonth5/temperature 5.6000000000000005
2021-01-21 16:13:54,115 DEBUG    MQTT       Publishing: emon/emonth5/external temperature 0
2021-01-21 16:13:54,117 DEBUG    MQTT       Publishing: emon/emonth5/humidity 92.60000000000001
2021-01-21 16:13:54,118 DEBUG    MQTT       Publishing: emon/emonth5/battery 3.1
2021-01-21 16:13:54,120 DEBUG    MQTT       Publishing: emon/emonth5/pulsecount 1
2021-01-21 16:13:54,121 DEBUG    MQTT       Publishing: emon/emonth5/rssi -65
2021-01-21 16:13:54,122 INFO     MQTT       Publishing 'node' formatted msg
2021-01-21 16:13:54,123 DEBUG    MQTT       Publishing: emonhub/rx/23/values 5.6000000000000005,0,92.60000000000001,3.1,1,-65
2021-01-21 16:13:54,693 DEBUG    RFM2Pi     6 NEW FRAME : OK 5 234 252 231 255 209 252 25 93 0 0 0 0 0 0 0 0 0 0 0 0 3 225 0 0 (-0)
2021-01-21 16:13:54,695 DEBUG    RFM2Pi     6 Timestamp : 1611245634.692925

You could try putting it back the other way, it is best to make changes one at a time. Although we did see the failure with the symlink in place so I’m not sure it will work.

@TrystanLea has also made some other changes since and the debug line that was previously being reached (but failing) is no longer there so we can’t easily compare

I think the issue might be in this bit as anywhere else leads to an error message or exception

                            for i in read_keys:
                                if i in r:
                                    c.names.append(self._SDM120_settings['prefix']+read_keys[i][0])
                                    c.realdata.append(round(r[i],read_keys[i][1]))

comparing keys with strings?? I don’t know what the raw r is like.

Thanks @srt, that’s a pain, I’m sure I remember seeing the key error voltage error in you earlier post before, but cant remember now how I solved it or what the reason was.

I have the latest code running and working well on my SDM120 here, so I dont think its that code necessarily.

You could try running this code manually @srt

import sdm_modbus, time

device = sdm_modbus.SDM120(device="/dev/ttyUSB0", baud=2400)

last_reading = 0

while True:

    if (time.time()-last_reading)>=10.0:
        last_reading = time.time()
    
        if device.connected():
            r = device.read_all(sdm_modbus.registerType.INPUT)
            for i in r:
                print(i+" "+str(r[i]))
            # print ("%f %f %f %f %f" % (r['voltage'],r['power_active'],r['power_factor'],r['frequency'],r['import_energy_active']))
            
    time.sleep(0.1) 

Create a file called sdm120.py and copy the contents into that file:

nano sdm120.py (right click and then paste)

Run the script with:

python3 sdm120.py
1 Like

You may need to stop emonhub first:

sudo service emonhub stop

OK, did that - process never ends, have to kill it with ctrl c

I have a thing about ifs without elses

Without the else, you don’t know if the read read nothing or the device isn’t connected :frowning:

fwiw I did add an else: print("nothing here") line, but it never printed.
Yep, that’s about my level!

Try this Sean, I’ve padded the script out with lots of debug prints. I haven’t tested it so I apologise in advance for any typos and booboo’s etc. I hope I’ve covered all routes and should print under any circumstance and tell us what’s happening.

import sdm_modbus, time

print("Testing the sdm130 code")

try:
    device = sdm_modbus.SDM120(device="/dev/ttyUSB0", baud=2400)
    print("Initiated the connection")
except Exception as e:
    print("Exiting as unable to initialise connection: " + str(e))
    exit()
     
last_reading = 0

while True:

    if (time.time()-last_reading)>=10.0:

        last_reading = int(time.time())
        print(str(last_reading) + " It's time to read")
    
        if device.connected():
            print(str(last_reading) + " We're still connected")

            try:
                r = device.read_all(sdm_modbus.registerType.INPUT)
                print(str(last_reading) + " We read the device and got: "+ str(r))
            except Exception as e:
                print(str(last_reading) + " Failed to read: " + str(e))
                break


            try:
                for i in r:
                    print(str(last_reading) + " -- " + str(i) + ": " + str(r[i]))
            except Exception as e:
                print(str(last_reading) + " Failed to parse: " + str(e))
                continue
         
        else:
            print(str(last_reading) + " Not currently connected")       
            
    time.sleep(0.1) 

print("Good-bye!")

[edit - I’ve just looked in my box of modbus meters and I do have a couple of sdm120’s that I have read successfully with my own more universal modbus scripts, so if you’re still struggling tomorrow PM I will see if I can hook one up and run this script too. I do not have an emonbase/emonsd set up currently so cannot easily try the emonhub interfacer but I can at least check the code above.

[edit - I’ve made minor formatting changes to the print statements for output readability, 26/1/21]

Thank you Paul, this is great - gives enough continuous feedback to fault-find. (Which consisted of swapping A/B terminals back to where they were in the first place. Yes, I hear your ‘told you so’…)
Now getting good readings via the script, but still nothing in emonhub.
A snip from terminal:

1611301633.5775619It's time to read
1611301633.5775619We're still connected
1611301633.5775619We read the device and got: {'total_demand_current': 0.37746480107307434, 'maximum_total_demand_current': 0.4836726188659668, 'total_energy_active': 1.0, 'total_energy_reactive': 3.239000082015991}
1611301633.5775619total_demand_current: 0.37746480107307434

1611301633.5775619maximum_total_demand_current: 0.4836726188659668

1611301633.5775619total_energy_active: 1.0

1611301633.5775619total_energy_reactive: 3.239000082015991

1611301643.6536613It's time to read
1611301643.6536613We're still connected
1611301643.6536613We read the device and got: {'total_demand_current': 0.37749338150024414, 'maximum_total_demand_current': 0.4836726188659668, 'total_energy_active': 1.0, 'total_energy_reactive': 3.239000082015991}
1611301643.6536613total_demand_current: 0.37749338150024414

1611301643.6536613maximum_total_demand_current: 0.4836726188659668

1611301643.6536613total_energy_active: 1.0

1611301643.6536613total_energy_reactive: 3.239000082015991

1611301653.732548It's time to read
1611301653.732548We're still connected

and from emonhub after restarting

2021-01-22 07:42:46,386 INFO     MainThread Exiting hub...
2021-01-22 07:42:47,314 DEBUG    SDM120     []
2021-01-22 07:42:47,416 INFO     MainThread Exit completed
2021-01-22 07:49:29,162 INFO     MainThread EmonHub emonHub (emon-pi variant) v2.1.5
2021-01-22 07:49:29,163 INFO     MainThread Opening hub...
2021-01-22 07:49:29,163 INFO     MainThread Logging level set to DEBUG
2021-01-22 07:49:29,164 INFO     MainThread Creating EmonHubJeeInterfacer 'RFM2Pi'
2021-01-22 07:49:29,165 DEBUG    MainThread Opening serial port: /dev/ttyAMA0 @ 38400 bits/s
2021-01-22 07:49:31,176 INFO     MainThread RFM2Pi device firmware version: OK
2021-01-22 07:49:31,177 INFO     MainThread RFM2Pi device current settings:  23 21 0 0 0 201 3 31 0 1 0 0 0 (-64)
2021-01-22 07:49:31,178 INFO     MainThread Setting RFM2Pi baseid: 5 (5i)
2021-01-22 07:49:32,180 INFO     MainThread Setting RFM2Pi frequency: 433 (4b)
2021-01-22 07:49:33,182 INFO     MainThread Setting RFM2Pi group: 210 (210g)
2021-01-22 07:49:34,184 INFO     MainThread Setting RFM2Pi quiet: 1 (1q)
2021-01-22 07:49:35,186 INFO     MainThread Setting RFM2Pi calibration: 230V (1p)
2021-01-22 07:49:36,189 DEBUG    MainThread Setting RFM2Pi pubchannels: ['ToEmonCMS']
2021-01-22 07:49:36,190 DEBUG    MainThread Setting RFM2Pi subchannels: ['ToRFM12']
2021-01-22 07:49:36,191 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT'
2021-01-22 07:49:36,196 DEBUG    MainThread Setting MQTT pubchannels: ['ToRFM12']
2021-01-22 07:49:36,197 DEBUG    MainThread Setting MQTT subchannels: ['ToEmonCMS']
2021-01-22 07:49:36,198 INFO     MainThread Setting MQTT node_format_enable: 1
2021-01-22 07:49:36,199 INFO     MainThread Setting MQTT nodevar_format_enable: 1
2021-01-22 07:49:36,199 INFO     MainThread Setting MQTT nodevar_format_basetopic: emon/
2021-01-22 07:49:36,201 INFO     MainThread Creating EmonHubEmoncmsHTTPInterfacer 'emoncmsorg'
2021-01-22 07:49:36,203 DEBUG    MainThread Setting emoncmsorg pubchannels: ['ToRFM12']
2021-01-22 07:49:36,204 DEBUG    MainThread Setting emoncmsorg subchannels: ['ToEmonCMS']
2021-01-22 07:49:36,205 WARNING  MainThread Setting emoncmsorg apikey: obscured
2021-01-22 07:49:36,206 INFO     MainThread Setting emoncmsorg url: https://emoncms.org
2021-01-22 07:49:36,206 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-22 07:49:36,207 INFO     MainThread Setting emoncmsorg senddata: 1
2021-01-22 07:49:36,208 INFO     MainThread Setting emoncmsorg sendstatus: 1
2021-01-22 07:49:36,209 INFO     MainThread Creating EmonHubSDM120Interfacer 'SDM120'
2021-01-22 07:49:36,219 INFO     MainThread Connecting to SDM120 device=/dev/ttyUSB0 baud=2400
2021-01-22 07:49:36,221 INFO     MainThread Setting SDM120 read_interval: 10
2021-01-22 07:49:36,222 INFO     MainThread Setting SDM120 nodename: SDM120
2021-01-22 07:49:36,222 INFO     MainThread Setting SDM120 prefix: 
2021-01-22 07:49:36,223 DEBUG    MainThread Setting SDM120 pubchannels: ['ToEmonCMS']
2021-01-22 07:49:36,313 DEBUG    RFM2Pi     1 NEW FRAME : OK 5 183 253 234 255 161 253 112 93 0 0 0 0 0 0 0 0 0 0 0 0 153 115 1 0 (-0)
2021-01-22 07:49:36,315 DEBUG    RFM2Pi     1 Timestamp : 1611301776.313008
2021-01-22 07:49:36,315 DEBUG    RFM2Pi     1 From Node : 5
2021-01-22 07:49:36,316 DEBUG    RFM2Pi     1    Values : [-585, -22, -607, 239.20000000000002, 0, 0, 0, 0, 0, 0, 95129]
2021-01-22 07:49:36,316 DEBUG    RFM2Pi     1 Sent to channel(start)' : ToEmonCMS
2021-01-22 07:49:36,317 DEBUG    RFM2Pi     1 Sent to channel(end)' : ToEmonCMS
2021-01-22 07:49:36,420 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-22 07:49:36,502 INFO     MQTT       Connecting to MQTT Server
2021-01-22 07:49:36,524 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-22 07:49:36,607 INFO     MQTT       connection status: Connection successful
2021-01-22 07:49:36,608 DEBUG    MQTT       CONACK => Return code: 0
2021-01-22 07:49:36,610 DEBUG    emoncmsorg Buffer size: 1
2021-01-22 07:49:36,628 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-22 07:49:36,710 INFO     MQTT       on_subscribe
2021-01-22 07:49:36,732 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-22 07:49:37,040 DEBUG    RFM2Pi     2 NEW FRAME : OK 5 186 253 235 255 165 253 72 93 0 0 0 0 0 0 0 0 0 0 0 0 155 115 1 0 (-0)
2021-01-22 07:49:37,043 DEBUG    RFM2Pi     2 Timestamp : 1611301777.040672
2021-01-22 07:49:37,044 DEBUG    RFM2Pi     2 From Node : 5
2021-01-22 07:49:37,044 DEBUG    RFM2Pi     2    Values : [-582, -21, -603, 238.8, 0, 0, 0, 0, 0, 0, 95131]
2021-01-22 07:49:37,045 DEBUG    RFM2Pi     2 Sent to channel(start)' : ToEmonCMS
2021-01-22 07:49:37,046 DEBUG    RFM2Pi     2 Sent to channel(end)' : ToEmonCMS
2021-01-22 07:49:37,113 DEBUG    MQTT       Publishing: emon/emonpi/power1 -582
2021-01-22 07:49:37,115 DEBUG    MQTT       Publishing: emon/emonpi/power2 -21
2021-01-22 07:49:37,117 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -603
2021-01-22 07:49:37,118 DEBUG    MQTT       Publishing: emon/emonpi/vrms 238.8
2021-01-22 07:49:37,120 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-22 07:49:37,122 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-22 07:49:37,124 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-22 07:49:37,126 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-22 07:49:37,128 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-22 07:49:37,130 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-22 07:49:37,132 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 95131
2021-01-22 07:49:37,133 INFO     MQTT       Publishing 'node' formatted msg
2021-01-22 07:49:37,134 DEBUG    MQTT       Publishing: emonhub/rx/5/values -582,-21,-603,238.8,0,0,0,0,0,0,95131
2021-01-22 07:49:41,977 DEBUG    RFM2Pi     4 NEW FRAME : OK 5 184 253 234 255 162 253 114 93 0 0 0 0 0 0 0 0 0 0 0 0 158 115 1 0 (-0)
2021-01-22 07:49:41,980 DEBUG    RFM2Pi     4 Timestamp : 1611301781.977602
2021-01-22 07:49:41,981 DEBUG    RFM2Pi     4 From Node : 5
2021-01-22 07:49:41,981 DEBUG    RFM2Pi     4    Values : [-584, -22, -606, 239.22, 0, 0, 0, 0, 0, 0, 95134]
2021-01-22 07:49:41,982 DEBUG    RFM2Pi     4 Sent to channel(start)' : ToEmonCMS
2021-01-22 07:49:41,982 DEBUG    RFM2Pi     4 Sent to channel(end)' : ToEmonCMS
2021-01-22 07:49:42,076 DEBUG    MQTT       Publishing: emon/emonpi/power1 -584
2021-01-22 07:49:42,077 DEBUG    MQTT       Publishing: emon/emonpi/power2 -22
2021-01-22 07:49:42,079 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -606
2021-01-22 07:49:42,080 DEBUG    MQTT       Publishing: emon/emonpi/vrms 239.22
2021-01-22 07:49:42,082 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-22 07:49:42,083 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-22 07:49:42,085 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-22 07:49:42,087 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-22 07:49:42,088 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-22 07:49:42,090 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-22 07:49:42,091 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 95134
2021-01-22 07:49:42,093 INFO     MQTT       Publishing 'node' formatted msg
2021-01-22 07:49:42,093 DEBUG    MQTT       Publishing: emonhub/rx/5/values -584,-22,-606,239.22,0,0,0,0,0,0,95134
2021-01-22 07:49:47,028 DEBUG    RFM2Pi     5 NEW FRAME : OK 5 188 253 234 255 166 253 115 93 0 0 0 0 0 0 0 0 0 0 0 0 161 115 1 0 (-0)
2021-01-22 07:49:47,031 DEBUG    RFM2Pi     5 Timestamp : 1611301787.028673
2021-01-22 07:49:47,032 DEBUG    RFM2Pi     5 From Node : 5
2021-01-22 07:49:47,032 DEBUG    RFM2Pi     5    Values : [-580, -22, -602, 239.23000000000002, 0, 0, 0, 0, 0, 0, 95137]
2021-01-22 07:49:47,033 DEBUG    RFM2Pi     5 Sent to channel(start)' : ToEmonCMS
2021-01-22 07:49:47,033 DEBUG    RFM2Pi     5 Sent to channel(end)' : ToEmonCMS
2021-01-22 07:49:47,152 DEBUG    MQTT       Publishing: emon/emonpi/power1 -580
2021-01-22 07:49:47,153 DEBUG    MQTT       Publishing: emon/emonpi/power2 -22
2021-01-22 07:49:47,155 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -602
2021-01-22 07:49:47,157 DEBUG    MQTT       Publishing: emon/emonpi/vrms 239.23000000000002
2021-01-22 07:49:47,158 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-22 07:49:47,159 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-22 07:49:47,161 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-22 07:49:47,162 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-22 07:49:47,164 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-22 07:49:47,165 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-22 07:49:47,167 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 95137
2021-01-22 07:49:47,168 INFO     MQTT       Publishing 'node' formatted msg
2021-01-22 07:49:47,169 DEBUG    MQTT       Publishing: emonhub/rx/5/values -580,-22,-602,239.23000000000002,0,0,0,0,0,0,95137
2021-01-22 07:49:47,419 DEBUG    SDM120     []
2021-01-22 07:49:51,974 DEBUG    RFM2Pi     7 NEW FRAME : OK 5 189 253 235 255 168 253 184 93 0 0 0 0 0 0 0 0 0 0 0 0 163 115 1 0 (-0)
2021-01-22 07:49:51,976 DEBUG    RFM2Pi     7 Timestamp : 1611301791.973919
2021-01-22 07:49:51,976 DEBUG    RFM2Pi     7 From Node : 5
2021-01-22 07:49:51,977 DEBUG    RFM2Pi     7    Values : [-579, -21, -600, 239.92000000000002, 0, 0, 0, 0, 0, 0, 95139]
2021-01-22 07:49:51,977 DEBUG    RFM2Pi     7 Sent to channel(start)' : ToEmonCMS
2021-01-22 07:49:51,977 DEBUG    RFM2Pi     7 Sent to channel(end)' : ToEmonCMS
2021-01-22 07:49:52,108 DEBUG    MQTT       Publishing: emon/emonpi/power1 -579
2021-01-22 07:49:52,110 DEBUG    MQTT       Publishing: emon/emonpi/power2 -21
2021-01-22 07:49:52,111 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -600
2021-01-22 07:49:52,113 DEBUG    MQTT       Publishing: emon/emonpi/vrms 239.92000000000002
2021-01-22 07:49:52,114 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-22 07:49:52,116 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-22 07:49:52,117 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-22 07:49:52,119 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-22 07:49:52,120 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-22 07:49:52,121 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-22 07:49:52,123 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 95139
2021-01-22 07:49:52,125 INFO     MQTT       Publishing 'node' formatted msg
2021-01-22 07:49:52,126 DEBUG    MQTT       Publishing: emonhub/rx/5/values -579,-21,-600,239.92000000000002,0,0,0,0,0,0,95139
2021-01-22 07:49:57,006 DEBUG    RFM2Pi     8 NEW FRAME : OK 5 187 253 234 255 165 253 68 93 0 0 0 0 0 0 0 0 0 0 0 0 166 115 1 0 (-0)
2021-01-22 07:49:57,008 DEBUG    RFM2Pi     8 Timestamp : 1611301797.005850
2021-01-22 07:49:57,009 DEBUG    RFM2Pi     8 From Node : 5
2021-01-22 07:49:57,009 DEBUG    RFM2Pi     8    Values : [-581, -22, -603, 238.76, 0, 0, 0, 0, 0, 0, 95142]
2021-01-22 07:49:57,010 DEBUG    RFM2Pi     8 Sent to channel(start)' : ToEmonCMS
2021-01-22 07:49:57,011 DEBUG    RFM2Pi     8 Sent to channel(end)' : ToEmonCMS
2021-01-22 07:49:57,164 DEBUG    MQTT       Publishing: emon/emonpi/power1 -581
2021-01-22 07:49:57,166 DEBUG    MQTT       Publishing: emon/emonpi/power2 -22
2021-01-22 07:49:57,168 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -603
2021-01-22 07:49:57,169 DEBUG    MQTT       Publishing: emon/emonpi/vrms 238.76
2021-01-22 07:49:57,171 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-22 07:49:57,173 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-22 07:49:57,174 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-22 07:49:57,176 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-22 07:49:57,177 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-22 07:49:57,178 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-22 07:49:57,179 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 95142
2021-01-22 07:49:57,181 INFO     MQTT       Publishing 'node' formatted msg
2021-01-22 07:49:57,181 DEBUG    MQTT       Publishing: emonhub/rx/5/values -581,-22,-603,238.76,0,0,0,0,0,0,95142
2021-01-22 07:49:57,401 DEBUG    SDM120     []
2021-01-22 07:50:02,048 DEBUG    RFM2Pi     10 NEW FRAME : OK 5 195 253 236 255 175 253 0 93 0 0 0 0 0 0 0 0 0 0 0 0 168 115 1 0 (-0)
2021-01-22 07:50:02,051 DEBUG    RFM2Pi     10 Timestamp : 1611301802.048171
2021-01-22 07:50:02,051 DEBUG    RFM2Pi     10 From Node : 5
2021-01-22 07:50:02,052 DEBUG    RFM2Pi     10    Values : [-573, -20, -593, 238.08, 0, 0, 0, 0, 0, 0, 95144]
2021-01-22 07:50:02,052 DEBUG    RFM2Pi     10 Sent to channel(start)' : ToEmonCMS
2021-01-22 07:50:02,054 DEBUG    RFM2Pi     10 Sent to channel(end)' : ToEmonCMS
2021-01-22 07:50:02,321 DEBUG    MQTT       Publishing: emon/emonpi/power1 -573
2021-01-22 07:50:02,322 DEBUG    MQTT       Publishing: emon/emonpi/power2 -20
2021-01-22 07:50:02,323 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -593
2021-01-22 07:50:02,325 DEBUG    MQTT       Publishing: emon/emonpi/vrms 238.08
2021-01-22 07:50:02,326 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-22 07:50:02,327 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-22 07:50:02,328 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-22 07:50:02,330 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-22 07:50:02,332 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-22 07:50:02,333 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-22 07:50:02,334 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 95144
2021-01-22 07:50:02,335 INFO     MQTT       Publishing 'node' formatted msg
2021-01-22 07:50:02,336 DEBUG    MQTT       Publishing: emonhub/rx/5/values -573,-20,-593,238.08,0,0,0,0,0,0,95144
2021-01-22 07:50:06,621 DEBUG    emoncmsorg Buffer size: 6
2021-01-22 07:50:06,989 DEBUG    RFM2Pi     11 NEW FRAME : OK 5 191 253 233 255 168 253 241 92 0 0 0 0 0 0 0 0 0 0 0 0 171 115 1 0 (-0)
2021-01-22 07:50:06,991 DEBUG    RFM2Pi     11 Timestamp : 1611301806.988850
2021-01-22 07:50:06,992 DEBUG    RFM2Pi     11 From Node : 5
2021-01-22 07:50:06,993 DEBUG    RFM2Pi     11    Values : [-577, -23, -600, 237.93, 0, 0, 0, 0, 0, 0, 95147]
2021-01-22 07:50:06,993 DEBUG    RFM2Pi     11 Sent to channel(start)' : ToEmonCMS
2021-01-22 07:50:06,994 DEBUG    RFM2Pi     11 Sent to channel(end)' : ToEmonCMS
2021-01-22 07:50:07,070 DEBUG    MQTT       Publishing: emon/emonpi/power1 -577
2021-01-22 07:50:07,071 DEBUG    MQTT       Publishing: emon/emonpi/power2 -23
2021-01-22 07:50:07,073 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -600
2021-01-22 07:50:07,074 DEBUG    MQTT       Publishing: emon/emonpi/vrms 237.93
2021-01-22 07:50:07,076 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-22 07:50:07,078 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-22 07:50:07,079 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-22 07:50:07,081 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-22 07:50:07,082 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-22 07:50:07,083 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-22 07:50:07,085 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 95147
2021-01-22 07:50:07,087 INFO     MQTT       Publishing 'node' formatted msg
2021-01-22 07:50:07,088 DEBUG    MQTT       Publishing: emonhub/rx/5/values -577,-23,-600,237.93,0,0,0,0,0,0,95147
2021-01-22 07:50:07,372 DEBUG    SDM120     []
2021-01-22 07:50:12,038 DEBUG    RFM2Pi     13 NEW FRAME : OK 5 189 253 233 255 166 253 224 92 0 0 0 0 0 0 0 0 0 0 0 0 173 115 1 0 (-0)
2021-01-22 07:50:12,040 DEBUG    RFM2Pi     13 Timestamp : 1611301812.037661
2021-01-22 07:50:12,041 DEBUG    RFM2Pi     13 From Node : 5
2021-01-22 07:50:12,042 DEBUG    RFM2Pi     13    Values : [-579, -23, -602, 237.76, 0, 0, 0, 0, 0, 0, 95149]
2021-01-22 07:50:12,042 DEBUG    RFM2Pi     13 Sent to channel(start)' : ToEmonCMS
2021-01-22 07:50:12,043 DEBUG    RFM2Pi     13 Sent to channel(end)' : ToEmonCMS
2021-01-22 07:50:12,236 DEBUG    MQTT       Publishing: emon/emonpi/power1 -579
2021-01-22 07:50:12,237 DEBUG    MQTT       Publishing: emon/emonpi/power2 -23
2021-01-22 07:50:12,239 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -602
2021-01-22 07:50:12,240 DEBUG    MQTT       Publishing: emon/emonpi/vrms 237.76
2021-01-22 07:50:12,242 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-22 07:50:12,243 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-22 07:50:12,245 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-22 07:50:12,247 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-22 07:50:12,248 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-22 07:50:12,250 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-22 07:50:12,251 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 95149
2021-01-22 07:50:12,253 INFO     MQTT       Publishing 'node' formatted msg
2021-01-22 07:50:12,253 DEBUG    MQTT       Publishing: emonhub/rx/5/values -579,-23,-602,237.76,0,0,0,0,0,0,95149

So, there’s data, but emonhub isn’t reading it.

Interesting, it looks your meter is not reporting any of the parameters that I had selected, perhaps we need to move forwards with @pb66’s definable datafields suggestion.

I dont quite understand why my basic script did not give you anything but Paul’s verbose version did? what am I missing there?

I doubt the meter is any different, I suspect either the sdm_modbus library has some short comings and/or Sean’s bus is outside the tolerances of the sdm_modbus timings. There are some physical things to try like adding a common ground between the master and slave if Sean hasn’t already done so, or perhaps a termination resister is needed (or not needed if Sean has fitted one). Even the cable type and length can make a difference.

I do have experience with reading sdm120’s with modbus but I use minimalmodbus rather than a device specific library. I have 2 or 3 different USB masters but not the one Sean has.

There are lots of question raised by the results I suspect the main reason your script didn’t return data was because the A+B lines were reversed since we tried swapping them previously. However, how your script and/or sdm_modbus library were able to create a connection that wouldn’t work without creating a message or failing is an issue. Also when the “read_all” was called why only a few of the many values were returned, and a different few to what you saw seems a bit random.

There seems to be 2 register tables within the sdm_modbus docs

the differences being this group

They seem to include the values Sean is seeing but you’re missing so IF there are differences in your devices, I guess Sean has the extended table and yours has the shorter table. BUT I have seen undocumented “hidden” registers on devices before so it maybe that the devices are the same. Especially as Sean’s definitely isn’t returning a full dataset. Do you get all 14 of the shorter set? Or any of the extended set?

I think the only way to be sure might be to use minimalmodbus to make some direct readings, the error messages and data payloads are very informative. But isn’t anywhere near as high level as sdm_modbus.

1 Like

I suspect your script was not at fault; I had reversed the A/B inputs to the RS485/USB thing before I ran your script. When I first ran Pauls, I got nothing, so I switched the A/B inputs back, at which point Pauls script started reporting. I haven’t retried yours since, but suspect it will now report fine. If it’s useful, I can do that?

Nope - the terminals are there, but the interface guide showed only 2 conductors, so that’s all I used. Cable is scrap 2-core unshielded data cable, but only about 0.5m long (if that).

absolutely

1 Like

There seem to be 2 different specs depending on the meter type.

1 Like

I’ve had a go at putting together the option to define datafields, names and precision as discussed above.
Its in a development branch as this is a rough first draft.

@srt I wonder if you could try the following:

cd /opt/openenergymonitor/emonhub
git checkout sdm120_datafield_config

Then change emonhub.conf SDM120 config too:

[[SDM120]]
    Type = EmonHubSDM120Interfacer
    [[[init_settings]]]
        device = /dev/ttyUSB0
        baud = 2400
    [[[runtimesettings]]]
        pubchannels = ToEmonCMS,
        read_interval = 10
        nodename = sdm120
        # prefix = sdm_
        datafields = total_demand_current,maximum_total_demand_current,total_energy_active,total_energy_reactive
        names = total_demand_current,maximum_total_demand_current,total_energy_active,total_energy_reactive
        precision = 3,3,3,3

Finally restart emonhub:

sudo service emonhub restart

That will hopefully work, I think ideally we have a default read all mode without this config stage, Il have a look at that again.

pi@emonpi:/opt/openenergymonitor/emonhub $ git checkout sdm120_datafield_config
error: pathspec 'sdm120_datafield_config' did not match any file(s) known to git
pi@emonpi:/opt/openenergymonitor/emonhub $ 

do a

git fetch --all

first.

Then a checkout, then a pull.

cd /opt/openenergymonitor/emonhub
git fetch --all
git checkout sdm120_datafield_config
git pull