Reading from a SDM120 meter using EmonHub

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

Ah, that’s better, thank you.
A little bit further forward…

2021-01-22 18:45:01,562 INFO     MainThread Exiting hub...
2021-01-22 18:45:07,412 DEBUG    SDM120     []
2021-01-22 18:45:07,513 INFO     MainThread Exit completed
2021-01-22 18:45:09,029 INFO     MainThread EmonHub emonHub (emon-pi variant) v2.1.5
2021-01-22 18:45:09,030 INFO     MainThread Opening hub...
2021-01-22 18:45:09,030 INFO     MainThread Logging level set to DEBUG
2021-01-22 18:45:09,031 INFO     MainThread Creating EmonHubJeeInterfacer 'RFM2Pi'
2021-01-22 18:45:09,032 DEBUG    MainThread Opening serial port: /dev/ttyAMA0 @ 38400 bits/s
2021-01-22 18:45:11,045 INFO     MainThread RFM2Pi device firmware version: OK
2021-01-22 18:45:11,046 INFO     MainThread RFM2Pi device current settings:  5 232 245 155 255 131 245 182 90 0 0 0 0 0 0 0 0 0 0 0 0 42 1 2 0 (-0)
2021-01-22 18:45:11,047 INFO     MainThread Setting RFM2Pi baseid: 5 (5i)
2021-01-22 18:45:12,049 INFO     MainThread Setting RFM2Pi frequency: 433 (4b)
2021-01-22 18:45:13,051 INFO     MainThread Setting RFM2Pi group: 210 (210g)
2021-01-22 18:45:14,054 INFO     MainThread Setting RFM2Pi quiet: 1 (1q)
2021-01-22 18:45:15,056 INFO     MainThread Setting RFM2Pi calibration: 230V (1p)
2021-01-22 18:45:16,058 DEBUG    MainThread Setting RFM2Pi pubchannels: ['ToEmonCMS']
2021-01-22 18:45:16,059 DEBUG    MainThread Setting RFM2Pi subchannels: ['ToRFM12']
2021-01-22 18:45:16,061 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT'
2021-01-22 18:45:16,065 DEBUG    MainThread Setting MQTT pubchannels: ['ToRFM12']
2021-01-22 18:45:16,067 DEBUG    MainThread Setting MQTT subchannels: ['ToEmonCMS']
2021-01-22 18:45:16,068 INFO     MainThread Setting MQTT node_format_enable: 1
2021-01-22 18:45:16,069 INFO     MainThread Setting MQTT nodevar_format_enable: 1
2021-01-22 18:45:16,070 INFO     MainThread Setting MQTT nodevar_format_basetopic: emon/
2021-01-22 18:45:16,073 INFO     MainThread Creating EmonHubEmoncmsHTTPInterfacer 'emoncmsorg'
2021-01-22 18:45:16,081 DEBUG    MainThread Setting emoncmsorg pubchannels: ['ToRFM12']
2021-01-22 18:45:16,082 DEBUG    MainThread Setting emoncmsorg subchannels: ['ToEmonCMS']
2021-01-22 18:45:16,083 WARNING  MainThread Setting emoncmsorg apikey: obscured
2021-01-22 18:45:16,083 INFO     MainThread Setting emoncmsorg url: https://emoncms.org
2021-01-22 18:45:16,084 INFO     MainThread Setting emoncmsorg senddata: 1
2021-01-22 18:45:16,085 INFO     MainThread Setting emoncmsorg sendstatus: 1
2021-01-22 18:45:16,079 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-22 18:45:16,088 INFO     MainThread Creating EmonHubSDM120Interfacer 'SDM120'
2021-01-22 18:45:16,097 INFO     MainThread Connecting to SDM120 device=/dev/ttyUSB0 baud=2400
2021-01-22 18:45:16,099 INFO     MainThread Setting SDM120 read_interval: 10
2021-01-22 18:45:16,099 INFO     MainThread Setting SDM120 nodename: sdm120
2021-01-22 18:45:16,100 INFO     MainThread Setting SDM120 prefix: 
2021-01-22 18:45:16,100 INFO     MainThread Setting SDM120 datafields: total_demand_current,maximum_total_demand_current,total_energy_active,total_energy_reactive
2021-01-22 18:45:16,101 INFO     MainThread Setting SDM120 names: total_demand_current,maximum_total_demand_current,total_energy_active,total_energy_reactive
2021-01-22 18:45:16,101 INFO     MainThread Setting SDM120 precision: 3,3,3,3
2021-01-22 18:45:16,101 DEBUG    MainThread Setting SDM120 pubchannels: ['ToEmonCMS']
2021-01-22 18:45:16,190 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-22 18:45:16,293 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-22 18:45:16,397 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-22 18:45:16,505 DEBUG    RFM2Pi     1 NEW FRAME : OK 5 209 245 155 255 108 245 172 90 0 0 0 0 0 0 0 0 0 0 0 0 53 1 2 0 (-0)
2021-01-22 18:45:16,508 DEBUG    RFM2Pi     1 Timestamp : 1611341116.505266
2021-01-22 18:45:16,509 DEBUG    RFM2Pi     1 From Node : 5
2021-01-22 18:45:16,509 DEBUG    RFM2Pi     1    Values : [-2607, -101, -2708, 232.12, 0, 0, 0, 0, 0, 0, 131381]
2021-01-22 18:45:16,510 DEBUG    RFM2Pi     1 Sent to channel(start)' : ToEmonCMS
2021-01-22 18:45:16,510 DEBUG    RFM2Pi     1 Sent to channel(end)' : ToEmonCMS
2021-01-22 18:45:16,574 INFO     MQTT       Connecting to MQTT Server
2021-01-22 18:45:16,614 DEBUG    RFM2Pi     device settings updated: E i5 g210 @ 433 MHz q1 USA 0
2021-01-22 18:45:16,679 INFO     MQTT       connection status: Connection successful
2021-01-22 18:45:16,680 DEBUG    MQTT       CONACK => Return code: 0
2021-01-22 18:45:16,688 DEBUG    emoncmsorg Buffer size: 1
2021-01-22 18:45:16,783 INFO     MQTT       on_subscribe
2021-01-22 18:45:20,544 DEBUG    RFM2Pi     3 NEW FRAME : OK 5 216 245 155 255 115 245 179 90 0 0 0 0 0 0 0 0 0 0 0 0 65 1 2 0 (-0)
2021-01-22 18:45:20,547 DEBUG    RFM2Pi     3 Timestamp : 1611341120.544605
2021-01-22 18:45:20,548 DEBUG    RFM2Pi     3 From Node : 5
2021-01-22 18:45:20,548 DEBUG    RFM2Pi     3    Values : [-2600, -101, -2701, 232.19, 0, 0, 0, 0, 0, 0, 131393]
2021-01-22 18:45:20,549 DEBUG    RFM2Pi     3 Sent to channel(start)' : ToEmonCMS
2021-01-22 18:45:20,550 DEBUG    RFM2Pi     3 Sent to channel(end)' : ToEmonCMS
2021-01-22 18:45:20,706 DEBUG    MQTT       Publishing: emon/emonpi/power1 -2600
2021-01-22 18:45:20,708 DEBUG    MQTT       Publishing: emon/emonpi/power2 -101
2021-01-22 18:45:20,709 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -2701
2021-01-22 18:45:20,711 DEBUG    MQTT       Publishing: emon/emonpi/vrms 232.19
2021-01-22 18:45:20,712 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-22 18:45:20,714 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-22 18:45:20,716 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-22 18:45:20,717 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-22 18:45:20,719 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-22 18:45:20,721 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-22 18:45:20,722 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 131393
2021-01-22 18:45:20,724 INFO     MQTT       Publishing 'node' formatted msg
2021-01-22 18:45:20,725 DEBUG    MQTT       Publishing: emonhub/rx/5/values -2600,-101,-2701,232.19,0,0,0,0,0,0,131393
2021-01-22 18:45:25,577 DEBUG    RFM2Pi     4 NEW FRAME : OK 5 208 245 155 255 107 245 165 90 0 0 0 0 0 0 0 0 0 0 0 0 76 1 2 0 (-0)
2021-01-22 18:45:25,579 DEBUG    RFM2Pi     4 Timestamp : 1611341125.577614
2021-01-22 18:45:25,580 DEBUG    RFM2Pi     4 From Node : 5
2021-01-22 18:45:25,580 DEBUG    RFM2Pi     4    Values : [-2608, -101, -2709, 232.05, 0, 0, 0, 0, 0, 0, 131404]
2021-01-22 18:45:25,581 DEBUG    RFM2Pi     4 Sent to channel(start)' : ToEmonCMS
2021-01-22 18:45:25,581 DEBUG    RFM2Pi     4 Sent to channel(end)' : ToEmonCMS
2021-01-22 18:45:25,673 DEBUG    MQTT       Publishing: emon/emonpi/power1 -2608
2021-01-22 18:45:25,674 DEBUG    MQTT       Publishing: emon/emonpi/power2 -101
2021-01-22 18:45:25,676 DEBUG    MQTT       Publishing: emon/emonpi/power1pluspower2 -2709
2021-01-22 18:45:25,677 DEBUG    MQTT       Publishing: emon/emonpi/vrms 232.05
2021-01-22 18:45:25,679 DEBUG    MQTT       Publishing: emon/emonpi/t1 0
2021-01-22 18:45:25,680 DEBUG    MQTT       Publishing: emon/emonpi/t2 0
2021-01-22 18:45:25,681 DEBUG    MQTT       Publishing: emon/emonpi/t3 0
2021-01-22 18:45:25,683 DEBUG    MQTT       Publishing: emon/emonpi/t4 0
2021-01-22 18:45:25,684 DEBUG    MQTT       Publishing: emon/emonpi/t5 0
2021-01-22 18:45:25,686 DEBUG    MQTT       Publishing: emon/emonpi/t6 0
2021-01-22 18:45:25,687 DEBUG    MQTT       Publishing: emon/emonpi/pulsecount 131404
2021-01-22 18:45:25,688 INFO     MQTT       Publishing 'node' formatted msg
2021-01-22 18:45:25,689 DEBUG    MQTT       Publishing: emonhub/rx/5/values -2608,-101,-2709,232.05,0,0,0,0,0,0,131404
2021-01-22 18:45:27,394 ERROR    SDM120     Error parsing data: 'str' object cannot be interpreted as an integer
2021-01-22 18:45:30,520 DEBUG    RFM2Pi     6 NEW FRAME : OK 5 206 245 156 255 106 245 219 90 0 0 0 0 0 0 0 0 0 0 0 0 88 1 2 0 (-0)
2021-01-22 18:45:30,523 DEBUG    RFM2Pi     6 Timestamp : 1611341130.520433
2021-01-22 18:45:30,524 DEBUG    RFM2Pi     6 From Node : 5
2021-01-22 18:45:30,524 DEBUG    RFM2Pi     6    Values : [-2610, -100, -2710, 232.59, 0, 0, 0, 0, 0, 0, 131416]
2021-01-22 18:45:30,525 DEBUG    RFM2Pi     6 Sent to channel(start)' : ToEmonCMS
2021-01-22 18:45:30,526 DEBUG    RFM2Pi     6 Sent to channel(end)' : ToEmonCMS
2021-01-22 18:45:30,751 DEBUG    MQTT     

thanks @srt, could you try updating again, i’ve made a couple of minor changes.

git pull origin sdm120_datafield_config

That seems to have done the trick.
Under ‘Inputs’ we now have a menu named sdm120, with 4 inputs, total_demand_current, maximum_total_demand_current, total_energy_active, & total_energy_reactive.
They all have data. I’m assuming all will be straightforward from here - thank you both very much for all your help with this.

1 Like

Personally I think rs485 is pretty robust, I always tend to use Cat5e cable and have not had any troubles, even on very long runs with multiple devices, so I doubt a 0.5m run of 2-core will be an issue and I do not connect ground wires either. There are competing beliefs on this point, for and against, some of my devices don’t even have a 3rd “ground” terminal.

Although the diagram does only show 2 (albeit screened) cores it does show not only one but 2 termination resistors, however, many rs485 adapters (but not all) do have one inbuilt, sometimes with a switch or link. All my adapters do have one inbuilt termination resister but I have never noticed a benefit when introducing a second one, so even this requirement I take with a pinch of salt.

But, although I believe the rs485 networks to be pretty forgiving, flexible and robust, I am aware that I may be just sitting pretty, in the safe zones and may need to implement changes one day under some circumstance. So when debugging I do tend to try these things, if for no other reason than to confirm my interpretation of the “rules” isn’t the issue.

I think you still have a little way to go if you are unable to get basic values such as “voltage” and “current” etc, I have yet to find a modbus energy meter that doesn’t report those values, let alone a sdm120, I have 2 and Trystan has one, all three do “voltage” and all the manuals and guide I can find for the sdm120, all show “voltage” is reported regardless of any other differences.

Now you have some values, try adding “voltage” to the datafields entry in emonhub.conf to see if that works now.

I’m bordering on thinking this is a library issue, if for no other reason than it seems incomplete. It should return something under all circumstances, if there’s an error it should say so, when something is done there should be a positive indication eg data, or at least a message. Modbus is 2way comms, there is no scenario where the device will not respond (to the master ie the sdm_modbud code), if it timesout or doesn’t respond that is an issue that sdm_modbus must relay to the user.

Great, out of interest, where did you buy the SDM120? Is it an Eastron original? Seems a shame not to have the real time power, power factor etc that mine reads…

It might require what @pb66 suggests to get at the other reads, Id be interested to hear if you get any more results if you did decided to investigate that further.