Reading from a SDM120 meter using EmonHub

2022-02-08 08:50:50,913 DEBUG MQTT Publishing: emon/sdm120/RI 0.029
2022-02-08 08:50:50,914 INFO MQTT Publishing ‘node’ formatted msg
2022-02-08 08:50:50,915 DEBUG MQTT Publishing: emonhub/rx/sdm120/values 249.14,0.803,134.2,200,0.671,50.049,2563.558,592.177,7.669,249.26,0.555,-122.5,127.9,-0.959,50.049,0.392,327.92,0.029
2022-02-08 08:51:00,622 DEBUG SDM120 [248.98, 0.787, 128.9, 196.0, 0.658, 50.049, 2563.559, 592.177, 7.669, 248.98, 0.538, -124.6, 129.6, -0.965, 50.049, 0.392, 327.92, 0.029]
2022-02-08 08:51:00,623 DEBUG SDM120 21 NEW FRAME :
2022-02-08 08:51:00,624 DEBUG SDM120 21 Timestamp : 1644310260.020094
2022-02-08 08:51:00,624 DEBUG SDM120 21 From Node : sdm120
2022-02-08 08:51:00,625 DEBUG SDM120 21 Values : [248.98, 0.787, 128.9, 196, 0.658, 50.049, 2563.559, 592.177, 7.669, 248.98, 0.538, -124.6, 129.6, -0.965, 50.049, 0.392, 327.92, 0.029]
2022-02-08 08:51:00,626 DEBUG SDM120 21 Sent to channel(start)’ : ToEmonCMS
2022-02-08 08:51:00,627 DEBUG SDM120 21 Sent to channel(end)’ : ToEmonCMS
2022-02-08 08:51:00,794 DEBUG MQTT Publishing: emon/sdm120/V 248.98
2022-02-08 08:51:00,795 DEBUG MQTT Publishing: emon/sdm120/I 0.787
2022-02-08 08:51:00,797 DEBUG MQTT Publishing: emon/sdm120/P 128.9
2022-02-08 08:51:00,798 DEBUG MQTT Publishing: emon/sdm120/VA 196
2022-02-08 08:51:00,800 DEBUG MQTT Publishing: emon/sdm120/PF 0.658
2022-02-08 08:51:00,801 DEBUG MQTT Publishing: emon/sdm120/FR 50.049
2022-02-08 08:51:00,802 DEBUG MQTT Publishing: emon/sdm120/EI 2563.559
2022-02-08 08:51:00,804 DEBUG MQTT Publishing: emon/sdm120/EE 592.177
2022-02-08 08:51:00,805 DEBUG MQTT Publishing: emon/sdm120/RI 7.669
2022-02-08 08:51:00,806 DEBUG MQTT Publishing: emon/sdm120/V 248.98
2022-02-08 08:51:00,807 DEBUG MQTT Publishing: emon/sdm120/I 0.538
2022-02-08 08:51:00,807 DEBUG MQTT Publishing: emon/sdm120/P -124.6
2022-02-08 08:51:00,808 DEBUG MQTT Publishing: emon/sdm120/VA 129.6
2022-02-08 08:51:00,808 DEBUG MQTT Publishing: emon/sdm120/PF -0.965
2022-02-08 08:51:00,809 DEBUG MQTT Publishing: emon/sdm120/FR 50.049
2022-02-08 08:51:00,810 DEBUG MQTT Publishing: emon/sdm120/EI 0.392
2022-02-08 08:51:00,810 DEBUG MQTT Publishing: emon/sdm120/EE 327.92
2022-02-08 08:51:00,811 DEBUG MQTT Publishing: emon/sdm120/RI 0.029
2022-02-08 08:51:00,811 INFO MQTT Publishing ‘node’ formatted msg
2022-02-08 08:51:00,812 DEBUG MQTT Publishing: emonhub/rx/sdm120/values 248.98,0.787,128.9,196,0.658,50.049,2563.559,592.177,7.669,248.98,0.538,-124.6,129.6,-0.965,50.049,0.392,327.92,0.029

Thought I’d sent this yesterday but hadn’t realised the wifi had dropped out so it didn’t actually send.

I see what’s happening now. The problem is one that @TrystanLea will have to sort out.

I looked at the Github link; but I don’t understand Github and it made no sense whatsoever, and the code isn’t in the standard emonCMS. So I can’t offer a patch.

What’s happening is the code doesn’t apply the “addresses” suffix from the configuration in post no. 112 to the node names, with the result that, as pointed out by @m2ts in post 116, both sets of values are written to the same feed, and the second value to arrive (most times it will be address 2 - not always) will overwrite the first.

So I’m afraid only @TrystanLea, as far as I know, will be able to help you. Sorry.


I’ve just noticed this:

That problem might actually be related?

Thanks for your assistance.
My original suggestion of a delay is redundant now I see that both meters are actually being read. It seems from later on in the thread, that development has moved toward using MBUS meters.
Hopefully Trystan will find some time to tweak things - I’m not sure from post 116 that he was aware that reading two meters was actually working and it was just that they weren’t assigned separate nodenames? It feels like the solution is agonisingly close! From reading various threads on this site, I get the impression that @borpin @Bill.Thomson or @pb66 may be able to conjure up a solution if I can entice any of those folks to weigh in?

I can help with Modbus issues, but I stopped running emonCMS about 4 years ago, so I’m
not up to speed on it any more. :frowning_face:

I will try and have a look at this in a bit! Looks like it should not be too hard like you say!

1 Like

This is the easy fix I think, it just adds the address as part of the input name:
https://github.com/openenergymonitor/emonhub/commit/2fd1b848928c012e81f53306d0441e390a1f7abf

You can just pull in the latest version of the minimalmodbus_address branch to test this…

It’s probably not the best long term solution as it only supports multiple identical modbus meters.

Here’s another potentially better solution that should allow multiple modbus meters with different registers:

Branch is called: minimalmodbus_multiple_meters
https://github.com/openenergymonitor/emonhub/tree/minimalmodbus_multiple_meters

Example emonhub.conf entry:

[[modbus]]
    Type = EmonHubMinimalModbusInterfacer
    [[[init_settings]]]
        device = /dev/ttyUSB0
        baud = 2400
    [[[runtimesettings]]]
        pubchannels = ToEmonCMS,
        read_interval = 10
        nodename = sdm120
        # prefix = sdm_
        [[[[meters]]]]
            [[[[[sdm120a]]]]]
                address = 1
                registers = 0,6,12,18,30,70,72,74,76
                names = V,I,P,VA,PF,FR,EI,EE,RI
                precision = 2,3,1,1,3,3,3,3,3
            [[[[[sdm120b]]]]]
                address = 2
                registers = 0,6,12,18,30,70,72,74,76
                names = V,I,P,VA,PF,FR,EI,EE,RI
                precision = 2,3,1,1,3,3,3,3,3

I haven’t fully tested this yet, the first part of the code appears to work fine, but not tried on actual meters.

Looking forward to trying these solutions. Unfortunately I powered down my install thinking it had crashed when in reality it was still writing to the sd card it was running on. This broke the card and I am now part way through trying to reinstall the OS and the EmonCMS stack onto a new card… :roll_eyes:

Hi, I have hit a snag and could use some guidance please! I reinstalled the OS and EmonCMS to a new card but could not get Emonhub to start. I tried re-installing and that proved too much for the SD card which promptly gave up the ghost. That was the 4th card I have worked through so I decided to reinstall the lot onto an Acer Aspire One with a physical hard disk. Unfortunately, I get the same problem with Emonhub…

The log from the install script:

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting paho-mqtt
  Using cached https://www.piwheels.org/simple/paho-mqtt/paho_mqtt-1.6.1-py3-none-any.whl
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.21.0)
Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 143, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 338, in run
    resolver.resolve(requirement_set)
  File "/usr/lib/python3/dist-packages/pip/_internal/resolve.py", line 102, in resolve
    self._resolve_one(requirement_set, req)
  File "/usr/lib/python3/dist-packages/pip/_internal/resolve.py", line 261, in _resolve_one
    check_dist_requires_python(dist)
  File "/usr/lib/python3/dist-packages/pip/_internal/utils/packaging.py", line 55, in check_dist_requires_python
    if not check_requires_python(requires_python):
  File "/usr/lib/python3/dist-packages/pip/_internal/utils/packaging.py", line 33, in check_requires_python
    return python_version in requires_python_specifier
  File "/usr/share/python-wheels/packaging-19.0-py2.py3-none-any.whl/packaging/specifiers.py", line 676, in __contains__
    return self.contains(item)
  File "/usr/share/python-wheels/packaging-19.0-py2.py3-none-any.whl/packaging/specifiers.py", line 681, in contains
    item = parse(item)
  File "/usr/share/python-wheels/packaging-19.0-py2.py3-none-any.whl/packaging/version.py", line 28, in parse
    return Version(version)
  File "/usr/share/python-wheels/packaging-19.0-py2.py3-none-any.whl/packaging/version.py", line 219, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting RPi.GPIO

The emonhub log looks like:

Feb 11 17:22:03 raspberry systemd[1]: Starting emonHub data multiplexer...
Feb 11 17:22:04 raspberry systemd[1]: Started emonHub data multiplexer.
Feb 11 17:22:31 raspberry emonhub.py[593]: Traceback (most recent call last):
Feb 11 17:22:31 raspberry emonhub.py[593]:   File "/usr/local/bin/emonhub/emonhub.py", line 26, in 
Feb 11 17:22:31 raspberry emonhub.py[593]:     from interfacers import *
Feb 11 17:22:31 raspberry emonhub.py[593]:   File "/opt/openenergymonitor/emonhub/src/interfacers/EmonHubMqttInterfacer.py", line 33, in 
Feb 11 17:22:31 raspberry emonhub.py[593]:     import paho.mqtt.client as mqtt
Feb 11 17:22:31 raspberry emonhub.py[593]: ModuleNotFoundError: No module named 'paho'
Feb 11 17:22:31 raspberry systemd[1]: emonhub.service: Main process exited, code=exited, status=1/FAILURE
Feb 11 17:22:31 raspberry systemd[1]: emonhub.service: Failed with result 'exit-code'.
Feb 11 17:22:36 raspberry systemd[1]: emonhub.service: Service RestartSec=5s expired, scheduling restart.
Feb 11 17:22:36 raspberry systemd[1]: emonhub.service: Failed to schedule restart job: Unit var-log.mount not found.
Feb 11 17:22:36 raspberry systemd[1]: emonhub.service: Failed with result 'exit-code'.

Thanks for looking.

[Formatted for presentation. Moderator - RW]

When posting code or output, please put 3 ‘backticks’ (normally found at the top left of the keyboard) on a line of their own before the code, and 3 more backticks also on a line of their own after the code:

```
code
```

If it is something like php you can add a language identifier after the first 3 backticks: ```php or even ```text if you don’t want any language markup applied.

Have fixed the paho error by:
cd /usr/local/bin/emonhub
sudo pip install paho-mqtt -t ./

But emonhub says there is no module named minimalmodbus and continues to give me the errors posted above.

My knowledge of Github is non-existent, but I think there’s some magic inferred in this quote (my emphasis) that somebody familiar with it needs to tell you about.

I have downloaded minimalmodbus.py from github and pasted that into /opt/openenergymonitor/emonhub/src.

I now have values from both modbus meters showing on the inputs page with the prefix of either 1 or 2 as per Trystan’s post 152.

When I try the multiple address branch and emonhub config so per post 153, I get critical main thread error parsing emonhub.conf. Parsing failed with several errors.

It sounds as if you’re almost there. I think @TrystanLea will need to see the errors from emonHub.

Minimalmodbus needs to be installed via the same method as paho-mqtt
i.e. sudo pip install minimalmodbus

If that’s what you did, then disregard this post.

Did you update your emonhub config to reflect the example I gave above? any chance there’s an error in your copy and paste?

[[modbus]]
    Type = EmonHubMinimalModbusInterfacer
    [[[init_settings]]]
        device = /dev/ttyUSB0
        baud = 2400
    [[[runtimesettings]]]
        pubchannels = ToEmonCMS,
        read_interval = 10
        nodename = sdm120
        # prefix = sdm_
        [[[[meters]]]]
            [[[[[sdm120a]]]]]
                address = 1
                registers = 0,6,12,18,30,70,72,74,76
                names = V,I,P,VA,PF,FR,EI,EE,RI
                precision = 2,3,1,1,3,3,3,3,3
            [[[[[sdm120b]]]]]
                address = 2
                registers = 0,6,12,18,30,70,72,74,76
                names = V,I,P,VA,PF,FR,EI,EE,RI
                precision = 2,3,1,1,3,3,3,3,3

I did the following:

cd /opt/openenergymonitor/emonhub
git fetch --all
git checkout minimalmodbus_multiple_meters
git pull
sudo service emonhub restart

My emonhub.conf looks like:

[interfacers]

#[[SDM230]]
 #   Type = EmonHubMinimalModbusInterfacer
  #  [[[init_settings]]]
   #     device = /dev/ttyUSB0
    #    baud = 9600
#    [[[runtimesettings]]]
 #       pubchannels = ToEmonCMS,
  #      read_interval = 10
   #     nodename = SDM230
    #   addresses = 1,2,
     #  registers = 12,72,74,342
      # names = Active power W, Import active energy kWh, Export active energy kWh, Total active energy kWh
      # precision = 1,1,1,1

[[modbus]]
    Type = EmonHubMinimalModbusInterfacer
    [[[init_settings]]]
        device = /dev/ttyUSB0
        baud = 9600
    [[[runtimesettings]]]
        pubchannels = ToEmonCMS,
        read_interval = 10
        nodename = sdm120
        # prefix = sdm_
        [[[[meters]]]]
            [[[[[sdm120a]]]]]
                address = 1
                registers = 0,6
                names = V,I
                precision = 2,3
            [[[[[sdm120b]]]]]
                address = 2
                registers = 0,6
                names = V,I
                precision = 2,3
             

[[MQTT]]

Baud is 9600 on my meters. I’m just reading a couple of values to make clean up easier on inputs page when I revert to your first method which is working (commented out section above).

Log looks like:

2022-02-15 11:42:39,668 INFO     MainThread EmonHub emonHub (emon-pi variant) v2.2.6
2022-02-15 11:42:39,672 INFO     MainThread Opening hub...
2022-02-15 11:42:39,674 INFO     MainThread Logging level set to DEBUG
2022-02-15 11:42:39,675 INFO     MainThread Creating EmonHubMinimalModbusInterfacer 'modbus'
2022-02-15 11:42:39,776 INFO     MainThread Connecting to Modbus device=/dev/ttyUSB0 baud=9600
2022-02-15 11:42:39,795 INFO     MainThread Setting modbus read_interval: 10
2022-02-15 11:42:39,796 INFO     MainThread Setting modbus nodename: sdm120
2022-02-15 11:42:39,797 INFO     MainThread Setting modbus prefix: 
2022-02-15 11:42:39,798 INFO     MainThread Setting modbus address: 1
2022-02-15 11:42:39,799 ERROR    MainThread Unable to create 'modbus' interfacer: sequence item 0: expected str instance, int found
2022-02-15 11:42:39,800 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT'
2022-02-15 11:42:39,802 DEBUG    MainThread Setting MQTT pubchannels: ['ToRFM12']
2022-02-15 11:42:39,802 DEBUG    MainThread Setting MQTT subchannels: ['ToEmonCMS']
2022-02-15 11:42:39,803 INFO     MainThread Setting MQTT node_format_enable: 1
2022-02-15 11:42:39,804 INFO     MainThread Setting MQTT nodevar_format_enable: 1
2022-02-15 11:42:39,805 INFO     MainThread Setting MQTT nodevar_format_basetopic: emon/
2022-02-15 11:42:39,805 INFO     MainThread Setting MQTT node_JSON_enable: 0
2022-02-15 11:42:39,807 INFO     MainThread Creating EmonHubEmoncmsHTTPInterfacer 'emoncmsorg'
2022-02-15 11:42:39,809 DEBUG    MainThread Setting emoncmsorg pubchannels: ['ToRFM12']
2022-02-15 11:42:39,809 DEBUG    MainThread Setting emoncmsorg subchannels: ['ToEmonCMS']
2022-02-15 11:42:39,810 WARNING  MainThread Setting emoncmsorg apikey: obscured
2022-02-15 11:42:39,811 INFO     MainThread Setting emoncmsorg url: https://emoncms.org
2022-02-15 11:42:39,812 INFO     MainThread Setting emoncmsorg senddata: 1
2022-02-15 11:42:39,813 INFO     MainThread Setting emoncmsorg sendstatus: 1

Parsing errors seem to have stopped, just getting unable to create modbus interfacer now.

2 Likes

Hello @MBC sorry for taking such a long time to get back to you. I’ve pushed up some more changes to this interfacer, it should hopefully solve the issue.

That’s fixed it! I can now read different registers on each meter :smiley:
Many thanks for sorting it. I will make a new post with my notes on how to set up emoncms with multiple meters so that other folks can hopefully set it all up more easily.

Thanks again, Mark.

Fantastic. Appreciate your efforts on this as about to dig into interfacing with several SDM120 Modbus myself

I have put my notes in a new topic if you want to take a look :slight_smile:

Installing Emoncms onto a PC (or Mac) and using with multiple modbus meters (e.g. SDM230)

1 Like