mbmd
ModBus Measurement Daemon - simple reading of data from ModBus meters and grid inverters
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
2 of 36 committers (5.6%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.0%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
ModBus Measurement Daemon - simple reading of data from ModBus meters and grid inverters
Basic Info
Statistics
- Stars: 265
- Watchers: 20
- Forks: 92
- Open Issues: 54
- Releases: 8
Topics
Metadata Files
README.md
ModBus Measurement Daemon
A daemon for collecting measurement data from smart meters and grid inverters over modbus.
mbmd provides an http interface to smart meters and grid inverters with modbus interface.
Meter readings are made accessible through REST API and MQTT.
Modbus communication is possible over RS485 connections as well as TCP sockets.
mbmd was originally developer by Mathias Dalheimer under the name of gosdm. Previous releases are still available.
Table of Contents
Requirements
You'll need: * A supported Modbus/RTU smart meter OR an supported Modbus/TCP SunSpec-compatible grid inverter. * In case of Modbus/RTU: A USB RS485 adapter. See USB-ISO-RS485 project for a home-grown adapter. * Optionally an RS485 to Ethernet converter (see SO discussion)
Installation
Using the precompiled binaries
Precompiled release packages are available. Download the right package for the target platform and unzip.
Building from source
mbmd is developed in Go and requires ^1.16. To build from source two steps are needed:
- use
make installto install the build tools (make sure$GOPATH/binis part of the path to make the installed tools accessible for the next step) - then run
make buildwhich creates the./mbmdbinary
To cross-build for a different archtecture (e.g. Raspberry Pi), use
GOOS=linux GOARCH=arm GOARM=5 make build
Running
To get help on the various command line options run
mbmd -h
The full documentation is available in the docs folder. A typical invocation looks like this:
$ ./bin/mbmd run -a /dev/ttyUSB0 -d janitza:26,sdm:1
2017/01/25 16:34:26 config: creating RTU connection via /dev/ttyUSB0 (9600baud, 8N1)
2017/01/25 16:34:26 httpd: starting api at :8080
This call queries a Janitza B23 meter with ID 26 and an Eastron SDM meter at ID 1. Not all devices are by default configured to use ID 1. The default device IDs depend on the meter type and documented in the meter's manual.
To use RTU devices with RS485/Ethernet adapters, add the --rtu switch to configure mbmd to use the TCP connection with RTU data format:
❯ ./bin/mbmd run -a rs485.fritz.box:23 --rtu -d sdm:1
2020/01/02 10:43:53 mbmd unknown version (unknown commit)
2020/01/02 10:43:53 config: creating RTU over TCP connection for rs485.fritz.box:23
2020/01/02 10:43:53 initialized device SDM1.1: {SDM Eastron SDM meters }
2020/01/02 10:43:53 httpd: starting api at :8080
If you use the -v commandline switch you can see
modbus traffic and the current readings on the command line. At
http://localhost:8080 you can see an embedded
web page that updates itself with the latest values:

Run using Docker
Alternatively run mbmd using the Docker image:
docker run -p 8080:8080 --device=/dev/ttyUSB0 volkszaehler/mbmd run -a /dev/ttyUSB0 -u 0.0.0.0:8080 -d sdm:1
To mount the config file into the docker container use -v $(pwd)/mbmd.yaml:/etc/mbmd.yaml.
Raspberry Pi
Download the ARM package for usage with Raspberry Pi and copy the binary
into /usr/local/bin. The following sytemd unit can be used to
start mbmd as service (put this into a new file /etc/systemd/system/mbmd.service):
[Unit]
Description=mbmd
After=syslog.target
After=network-online.target
[Service]
ExecStart=/usr/local/bin/mbmd run -a /dev/ttyAMA0
Restart=always
[Install]
WantedBy=multi-user.target
You might need to adjust the -a parameter depending on where your
RS485 adapter is connected. Then, use
systemctl start mbmd
to test your installation. If you're satisfied use
systemctl enable mbmd
to start the service at boot time automatically.
WARNING: When using an FTDI-based USB-RS485 adaptor the
Raspberry Pi might become unreachable after a while. This is most likely not
an issue with the RS485-USB adaptor or this software, but because of a
bug in the Raspberry Pi kernel.
To fix switch the internal dwc USB hub of the Raspberry Pi to
USB1.1 by adding the following parameter to /boot/cmdline.txt:
dwc_otg.speed=1
Detecting connected meters
MODBUS/RTU does not provide a mechanism to discover devices. There is no
reliable way to detect all attached devices.
As workaround mbmd scan attempts to read the L1 voltage from all
device IDs and reports which one replied correctly (i.e. 110/230V +/-10%):
./mbmd scan -a /dev/ttyUSB0
2017/06/21 10:22:34 Starting bus scan
2017/06/21 10:22:35 Device 1: n/a
...
2017/07/27 16:16:39 Device 21: SDM type device found, L1 voltage: 234.86
2017/07/27 16:16:40 Device 22: n/a
2017/07/27 16:16:40 Device 23: n/a
2017/07/27 16:16:40 Device 24: n/a
2017/07/27 16:16:40 Device 25: n/a
2017/07/27 16:16:40 Device 26: Janitza type device found, L1 voltage: 235.10
...
2017/07/27 16:17:25 Device 247: n/a
2017/07/27 16:17:25 Found 2 active devices:
2017/07/27 16:17:25 * slave address 21: type SDM
2017/07/27 16:17:25 * slave address 26: type JANITZA
2017/07/27 16:17:25 WARNING: This lists only the devices that responded to a known L1 voltage request. Devices with different function code definitions might not be detected.
API
Rest API
mbmd provides a convenient REST API. Supported endpoints under /api are:
/api/last/{ID}latest data for device/api/avg/{ID}averaged data over last minute/api/statusdaemon status
Both device APIs can also be called without the device id to return data for all connected devices.
Monitoring
The /api/status endpoint provides the following information:
$ curl http://localhost:8080/api/status
{
"StartTime": "2017-01-25T16:35:50.839829945+01:00",
"UpTime": 65587.177092186,
"Goroutines": 11,
"Memory": {
"Alloc": 1568344,
"HeapAlloc": 1568344
},
"Modbus": {
"TotalModbusRequests": 1979122,
"ModbusRequestRatePerMinute": 1810.5264666764785,
"TotalModbusErrors": 738,
"ModbusErrorRatePerMinute": 0.6751319688261972
},
"ConfiguredMeters": [
{
"Id": 26,
"Type": "JANITZA",
"Status": "available"
}
]
}
This is a snapshot of a process running over night, along with the error statistics during that timeframe. The process queries continuously, the cabling is not a shielded, twisted wire but something that I had laying around. With proper cabling the error rate should be lower, though.
Websocket API
Data read from the meters can be observed by clients in realtime using the Websocket API. As soon as new readings are available, they are pushed to connected websocket clients.
The websocket API is available on /ws. All connected clients receive status and
meter updates for all connected meters without further subscription.
MQTT API
Another option for receiving client updates is by using the built-in MQTT publisher.
By default, readings are published at /mbmd/<unique id>/<reading>. Rate limiting is possible.
Homie API
Homie is an MQTT convention for IoT/M2M. mbmd publishes all devices and readings using the Homie protocol. This allows systems like e.g. OpenHAB to auto-discover devices operated by mbmd:

InfluxDB support
There is also the option to directly insert the data into an influxdb database by using the command-line options available. InfluxDB 1.8 and 2.0 are currently supported. to enable this, add the --influx-database and the --influx-url commandline parameter. More advanced configuration is available, to learn more checkout the mbmd_run.md documentation
Supported Devices
mbmd supports a range of DIN rail meters and grid inverters.
Modbus RTU Meters
The meters have slightly different capabilities. The EASTRON SDM630 offers a lot of features, while the smaller devices only support basic features. The table below gives an overview (please consult the manuals for definitive guidance):
| Meter | Phases | Voltage | Current | Power | Power Factor | Total Import | Total Export | Per-phase Import/Export | Line/Neutral THD | |---|---|---|---|---|---|---|---|---|---| | EM24 | 3 | + | + | + | + | + | + | +/- | - | | EM24_E1 | 3 | + | + | + | + | + | + | +/- | - | | SDM54 | 3 | + | + | + | + | + | + | + | + | | SDM72 | 3 | - | - | + | - | + | + | - | - | | SDM120/220 | 1 | + | + | + | + | + | + | - | - | | SDM530 | 3 | + | + | + | + | + | + | - | - | | SDM630 | 3 | + | + | + | + | + | + | + | + | | Inepro PRO1/2 | 1 | + | + | + | + | + | + | - | - | | Inepro PRO380 | 3 | + | + | + | + | + | + | + | - | | Janitza B23-312 | 3 | + | + | + | + | + | + | - | - | | DZG DVH4013 | 3 | + | + | - | - | + | + | - | - | | SBC ALE3 | 3 | + | + | + | + | + | + | - | - | | ABB A/B-Series | 3 | + | + | + | + | + | + | + | + | | BE MPM3MP | 3 | + | + | + | + | + | + | - | - | | KOSTAL Smart Energy Meter | 3 | + | + | + | + | + | + | + | - | | ORNO WE-504/514/515 | 1 | + | + | + | + | + | - | - | - | | ORNO WE-516/517 | 3 | + | + | + | + | + | + | + | - | | ORNO WE-525/526 | 1 | + | + | + | + | + | + | - | - | | iEM3000 Series | 3 | + | + | + | + | + | + | (+) | + | | B+G e-tech WS100 | 1 | + | + | + | - | + | + | - | - | | B+G e-tech DS100 | 3 | + | + | + | + | + | + | + | + |
- EM24: Compact (4TE), 3P meter with RS-485 interface.
- EM24_E1: Compact (4TE), 3P meter with Ethernet interface.
- SDM54: Compact (3TE), 3P meter with a lot of features. Can be configured using the builtin display.
- SDM72: Compact (4TE), 3P meter with bare minium of total measurements, no currents. Can be configured using the builtin display.
- SDM120: Cheap and small (1TE), but communication parameters can only be set over MODBUS, which is currently not supported by this project. You can use e.g. SDM120C to change parameters.
- SDM220, SDM230: More comfortable (2TE), can be configured using the builtin display.
- SDM530: Very big (7TE) - takes up a lot of space, but all connections are on the underside of the meter.
- SDM630: v1 and v2, both MID and non-MID. Compact (4TE) and with lots of features. Can be configured for 1P2 (single phase with neutral), 3P3 (three phase without neutral) and 3P4 (three phase with neutral) systems.
- Inepro PRO1/2: Small (1TE) MID meter up to 100A (Pro2). External tariff input possible (2T versions).
- Inepro PRO380: Compact (4TE) MID meter with extensive features. Can be connected 3P4W, 3P3W and 1P2W. Includes per-direction active/reactive energy consumption and supports two tariffs. Energy resolution is 2 digits per kWh.
- Janitza B23-312: These meters have a higher update rate than the Eastron devices, but they are more expensive. The -312 variant is the one with a MODBUS interface.
- DZG DVH4013: This meter does not provide raw phase power measurements and only aggregated import/export measurements. The meter is only partially implemented and not recommended. By default, the meter communicates using 9600 8E1. The meter ID is derived from the serial number taking the last two numbers of the serial number (top right of the device), e.g. 23, and add one (24). Assume this is a hexadecimal number and convert it to decimal (36). Use this as the meter ID.
- SBC ALE3: This compact Saia Burgess Controls meter is comparable to the SDM630. It has two tariffs, both import and export depending on meter version and compact (4TE). It's often used with Viessmann heat pumps.
- BE MPM3PM: Compact (4TE) three phase meter.
- KOSTAL Smart Energy Meter: Slave device for Kostal grid inverters. Known bug in inverter firmware with Total Export Energy.
- ORNO WE-504/514/515: Low cost single phase meter By default, the meter communicates using 9600 8E1. The meter ID is 1. Meter ID, bus speed and other parameters are configurable via Software(Windows only) WE-515 has a lithium battery and multi-tariff support, WE-514 does not support tariff zones.
- ORNO WE-516/517: Low cost three phase meter. By default, the meter communicates using 9600 8E1. The meter ID is 1. Meter ID, bus speed and other parameters are configurable via Software(Windows only) WE-517 has a lithium battery and multi-tariff support, WE-516 does not support tariff zones.
- Schneider Electric iEM3000 Series: Professional meter with loads of configurable max/average measurements with timestamp functionality.
- B+G e-tech WS100: Cheap and small (1TE), 1P MID meter.
- B+G e-tech DS100: Looks to be similar potent as SDM630 if not better, very cheap in Germany (below 50€) Able to set higher Baudrate than SDM630 so measurements can be taken more often. There is also a MID Version and Multi Traif ("-30B") Version. (https://data.xn--stromzhler-v5a.eu/manuals/bgds100seriede.pdf)
Modbus TCP Grid Inverters
Apart from meters, SunSpec-compatible grid inverters connected over TCP are supported, too. SunSpec defines a default register layout for accessing the devices.
Supported inverters include popular devices from SolarEdge (SE3000, SE9000) and SMA (Sunny Boy and Sunny TriPower).
In case of TCP connection, the adapter parameter becomes the hostname and port:
./mbmd run -a 192.168.0.44:502 -d SMA:23
SunSpec devices can host multiple subdevices, e.g. to expose a meter attached to an inverter. To access a subdevice, append its id to the slave id:
./mbmd run -a 192.168.0.44:502 -d FRONIUS:1.0 -d FRONIUS:1.1
Releases
Download the lastest release from github.com/volkszaehler/mbmd/releases.
Owner
- Name: volkszaehler.org project
- Login: volkszaehler
- Kind: organization
- Location: Germany
- Website: https://volkszaehler.org
- Repositories: 7
- Profile: https://github.com/volkszaehler
Open Source Smart Metering platform
GitHub Events
Total
- Issues event: 11
- Watch event: 26
- Issue comment event: 63
- Push event: 8
- Pull request review event: 10
- Pull request review comment event: 15
- Pull request event: 23
- Fork event: 9
Last Year
- Issues event: 11
- Watch event: 26
- Issue comment event: 63
- Push event: 8
- Pull request review event: 10
- Pull request review comment event: 15
- Pull request event: 23
- Fork event: 9
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| andig | c****e@g****e | 317 |
| Mathias Dalheimer | md@g****t | 127 |
| dependabot-preview[bot] | 2****] | 19 |
| dependabot[bot] | 4****] | 11 |
| Sebastian Chrostek | s****n@c****t | 5 |
| guido4096 | g****o@n****e | 4 |
| Alexander Klauer | A****r@i****e | 3 |
| tobima | m****l@t****e | 2 |
| sirtet | t****o@k****h | 2 |
| premultiply | 4****y | 2 |
| Rainer Poisel | r****r@h****m | 2 |
| Richie B2B | r****d@v****g | 2 |
| beldeczki | 7****i | 2 |
| Tobias Müller | T****r@t****o | 2 |
| Jelle Victoor | v****e@g****m | 2 |
| Alex | 6****r | 2 |
| Andre G | a****d | 1 |
| Andreas Antes | a****s@g****e | 1 |
| sicheste | s****e | 1 |
| meyerd | m****d@m****e | 1 |
| korpa | k****a | 1 |
| kiezematze | m****h@a****e | 1 |
| bilbolodz | b****o@l****l | 1 |
| bbiegun | b****n@g****m | 1 |
| air-ii | w****i@g****m | 1 |
| Oleksandr Chykysh | m****s@g****m | 1 |
| Michael Panzer | p****l@g****m | 1 |
| Kristian Mide | f****s@m****k | 1 |
| Karsten Hinz | k****n@i****e | 1 |
| Karl Szmutny | s****w@p****e | 1 |
| and 6 more... | ||
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 139
- Total pull requests: 236
- Average time to close issues: about 2 months
- Average time to close pull requests: about 1 month
- Total issue authors: 90
- Total pull request authors: 43
- Average comments per issue: 3.88
- Average comments per pull request: 1.0
- Merged pull requests: 180
- Bot issues: 3
- Bot pull requests: 52
Past Year
- Issues: 6
- Pull requests: 23
- Average time to close issues: about 1 month
- Average time to close pull requests: 14 days
- Issue authors: 6
- Pull request authors: 10
- Average comments per issue: 1.83
- Average comments per pull request: 2.7
- Merged pull requests: 15
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- bilbolodz (11)
- andig (9)
- bikeymouse (5)
- isarrider (4)
- wing84 (3)
- bbiegun (3)
- dependabot-preview[bot] (3)
- jarau-de (3)
- sirtet (3)
- mkmt (3)
- ChristianSteffens (2)
- wisekki (2)
- kereis (2)
- stepsolar (2)
- RichieB2B (2)
Pull Request Authors
- andig (115)
- dependabot-preview[bot] (26)
- dependabot[bot] (25)
- guido4096 (7)
- isarrider (6)
- BMOD89 (5)
- beldeczki (4)
- twam (4)
- RichieB2B (3)
- chrostek (3)
- ambanmba (2)
- premultiply (2)
- bilbolodz (2)
- air-ii (2)
- kiezematze (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
- Total downloads: unknown
- Total docker downloads: 363,251
- Total dependent packages: 4
- Total dependent repositories: 18
- Total versions: 13
proxy.golang.org: github.com/volkszaehler/mbmd
- Homepage: https://github.com/volkszaehler/mbmd
- Documentation: https://pkg.go.dev/github.com/volkszaehler/mbmd#section-documentation
- License: BSD-3-Clause
-
Latest release: v0.0.0-20231215091549-af16b1f597b9
published about 2 years ago
Rankings
Dependencies
- actions/checkout v3 composite
- actions/setup-go v3 composite
- golangci/golangci-lint-action v3 composite
- alpine latest build
- golang 1.18-alpine build
- github.com/andig/gosunspec v0.0.0-20211108155140-af2e73b86e71
- github.com/cpuguy83/go-md2man/v2 v2.0.2
- github.com/deepmap/oapi-codegen v1.11.0
- github.com/dmarkham/enumer v1.5.6
- github.com/eclipse/paho.mqtt.golang v1.4.1
- github.com/felixge/httpsnoop v1.0.3
- github.com/fsnotify/fsnotify v1.5.4
- github.com/google/go-github v17.0.0+incompatible
- github.com/google/go-querystring v1.1.0
- github.com/google/uuid v1.3.0
- github.com/gorilla/handlers v1.5.1
- github.com/gorilla/mux v1.8.0
- github.com/gorilla/websocket v1.5.0
- github.com/grid-x/modbus v0.0.0-20220829110112-006eee73392e
- github.com/grid-x/serial v0.0.0-20211107191517-583c7356b3aa
- github.com/hashicorp/go-version v1.6.0
- github.com/hashicorp/hcl v1.0.0
- github.com/inconshreveable/mousetrap v1.0.1
- github.com/influxdata/influxdb-client-go v1.4.0
- github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf
- github.com/magiconair/properties v1.8.6
- github.com/mitchellh/mapstructure v1.5.0
- github.com/pascaldekloe/name v1.0.1
- github.com/pelletier/go-toml v1.9.5
- github.com/pelletier/go-toml/v2 v2.0.5
- github.com/pkg/errors v0.9.1
- github.com/russross/blackfriday/v2 v2.1.0
- github.com/spf13/afero v1.9.2
- github.com/spf13/cast v1.5.0
- github.com/spf13/cobra v1.5.0
- github.com/spf13/jwalterweatherman v1.1.0
- github.com/spf13/pflag v1.0.5
- github.com/spf13/viper v1.13.0
- github.com/subosito/gotenv v1.4.1
- github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e
- golang.org/x/exp v0.0.0-20230118134722-a68e582fa157
- golang.org/x/mod v0.6.0
- golang.org/x/net v0.1.0
- golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde
- golang.org/x/sys v0.1.0
- golang.org/x/text v0.4.0
- golang.org/x/tools v0.2.0
- gopkg.in/ini.v1 v1.67.0
- gopkg.in/yaml.v2 v2.4.0
- gopkg.in/yaml.v3 v3.0.1
- 621 dependencies