2017-08-06 17:20:59 +00:00
# wmbusmeters
2019-06-16 20:07:22 +00:00
The program receives and decodes C1,T1 or S1 telegrams
2017-08-09 10:00:11 +00:00
(using the wireless mbus protocol) to acquire
2018-11-25 11:33:14 +00:00
utility meter readings. The readings can then be published using
2019-02-26 08:33:10 +00:00
MQTT, curled to a REST api, inserted into a database or stored in a log file.
2019-04-28 11:55:21 +00:00
[FAQ/WIKI/MANUAL pages ](https://weetmuts.github.io/wmbusmeterswiki/ )
2018-01-05 16:54:51 +00:00
2019-03-12 19:37:25 +00:00
The program runs on GNU/Linux, MacOSX and Raspberry Pi.
2018-12-28 19:31:52 +00:00
2019-02-23 21:17:00 +00:00
| OS | Status |
| ------------ |:-------------:|
|GNU/Linux & MacOSX| [![Build Status ](https://travis-ci.org/weetmuts/wmbusmeters.svg?branch=master )](https://travis-ci.org/weetmuts/wmbusmeters) |
2017-08-30 12:14:18 +00:00
2019-01-04 22:07:52 +00:00
| Static Scan | Status |
| ------------- |:-------------:|
|Linux G++| [![Build Status ](https://scan.coverity.com/projects/14774/badge.svg )](https://scan.coverity.com/projects/weetmuts-wmbusmeters) |
2019-02-26 08:33:10 +00:00
# Run as a daemon
2019-04-03 15:31:51 +00:00
Remove the wmbus dongle (im871a,amb8465) or the generic rtlsdr dongle (RTL2838) from your computer.
2019-02-26 08:33:10 +00:00
2019-02-26 08:35:15 +00:00
`make; sudo make install` will install wmbusmeters as a daemon that starts
2019-02-26 08:33:10 +00:00
automatically when an appropriate wmbus usb dongle is inserted in the computer.
2019-03-12 19:57:13 +00:00
(Note! make install only works for GNU/Linux. For MacOSX try to start
`wmbusmetersd /tmp/thepidfile` from a script instead.)
2019-02-26 08:33:10 +00:00
Check the config file /etc/wmbusmeters.conf:
```
loglevel=normal
device=auto
logtelegrams=false
2019-04-03 15:31:51 +00:00
format=json
2019-02-26 21:19:16 +00:00
meterfiles=/var/log/wmbusmeters/meter_readings
2019-04-03 15:31:51 +00:00
meterfilesaction=overwrite
2019-06-20 12:28:52 +00:00
meterfilesnaming=name
2019-02-26 08:33:10 +00:00
logfile=/var/log/wmbusmeters/wmbusmeters.log
2019-04-03 15:31:51 +00:00
shell=/usr/bin/mosquitto_pub -h localhost -t wmbusmeters/$METER_ID -m "$METER_JSON"
2019-02-26 08:33:10 +00:00
```
Then add a meter file in /etc/wmbusmeters.d/MyTapWater
2017-08-31 09:15:12 +00:00
```
2019-02-26 08:33:10 +00:00
name=MyTapWater
type=multical21
id=12345678
key=00112233445566778899AABBCCDDEEFF
```
Now plugin your wmbus dongle. Wmbusmeters should start automatically,
check with `tail -f /var/log/syslog` and `tail -f /var/log/wmbusmeters/wmbusmeters.log`
2019-04-03 15:31:51 +00:00
(If you are using an rtlsdr dongle, then make sure the binaries /usr/bin/rtl_sdr and
/usr/bin/rtl_wmbus exists and are executable.)
2019-02-26 08:33:10 +00:00
The latest reading of the meter can also be found here: /var/log/wmbusmeters/meter_readings/MyTapWater
2019-03-05 20:19:05 +00:00
You can use several ids using `id=1111111,2222222,3333333` or you can listen to all
2019-06-06 16:16:24 +00:00
meters of a certain type `id=*` or you can suffix with star `id=8765*` to match
all meters with a given prefix.
2019-03-05 20:19:05 +00:00
2019-05-21 16:00:21 +00:00
If you are running on a Raspberry PI with flash storage and you relay the data to
another computer using a shell command (mosquitto_pub or curl or similar) then you might want to remove
`meterfiles` and `meterfilesaction` to minimize the writes to the local flash file system.
2019-02-26 08:33:10 +00:00
# Run using config files
If you cannot install as a daemon, then you can also start
wmbusmeters in your terminal using the config files in /etc/wmbusmeters.
```
2019-03-01 14:41:11 +00:00
wmbusmeters --useconfig=/
2019-02-26 08:33:10 +00:00
```
Or you can start wmbusmeters with your own config files:
```
wmbusmeters --useconfig=/home/me/.config/wmbusmeters
```
The files/dir should then be located here:
`/home/me/.config/wmbusmeters/etc/wmbusmeters.conf` and
`/home/me/.config/wmbusmeters/etc/wmbusmeters.d`
2019-06-11 16:52:41 +00:00
When running using config files then you can trigger a reload of the config files
2019-06-11 17:15:12 +00:00
using `sudo killall -HUP wmbusmetersd` or `killall -HUP wmbusmeters`
2019-06-11 16:52:41 +00:00
depending on if you are running as a daemon or not.
2019-02-26 08:34:21 +00:00
# Running without config files, good for experimentation and test.
2019-02-26 08:33:10 +00:00
```
2019-06-11 17:12:01 +00:00
wmbusmeters version: 0.9.9
2019-06-06 15:28:20 +00:00
Usage: wmbusmeters {options} < device > ( [meter_name] [meter_type]{:< modes > } [meter_id] [meter_key] )*
2019-02-26 21:19:16 +00:00
As < options > you can use:
2019-05-04 20:39:45 +00:00
--addconversions=< unit > ,< unit > change/add units for the meter output
2019-02-26 21:19:16 +00:00
--debug for a lot of information
--exitafter=< time > exit program after time, eg 20h, 10m 5s
--format=< hr / json / fields > for human readable, json or semicolon separated fields
2019-06-06 15:28:20 +00:00
--listento=< mode > tell the wmbus dongle to listen to this single link mode where mode can be
c1,t1,s1,s1m,n1a,n1b,n1c,n1d,n1e,n1f
--listento=c1,t1,s1 tell the wmbus dongle to listen to these link modes
different dongles support different combinations of modes
--c1 --t1 --s1 --s1m ... another way to set the link mode for the dongle
2019-02-26 21:19:16 +00:00
--logfile=< file > use this file instead of stdout
--logtelegrams log the contents of the telegrams for easy replay
--meterfiles=< dir > store meter readings in dir
--meterfilesaction=(overwrite|append) overwrite or append to the meter readings file
2019-06-20 12:28:52 +00:00
--meterfilesnaming=(name|id|name-id) the meter file is the meter's: name, id or name-id
2019-03-12 19:37:25 +00:00
--n1a to --n1f listen to N1 messages (perhaps)
2019-02-26 21:19:16 +00:00
--oneshot wait for an update from each meter, then quit
--separator=< c > change field separator to c
--shell=< cmdline > invokes cmdline with env variables containing the latest reading
--shellenvs list the env variables available for the meter
--useconfig=< dir > load config files from dir/etc
--verbose for more information
2019-04-03 15:31:51 +00:00
As a < device > you can use: auto
which will look for the links /dev/im87a,/dev/amb8475 and /dev/rtlsdr (the
links are automatically generated by udev if you have run the install scripts.)
and start wmbusmeters with the proper tty device or rtlwmbus background process.
2019-02-26 21:19:16 +00:00
2019-04-03 15:31:51 +00:00
As a < device > you can also use: the exact /dev/ttyUSB0 to your dongle if you do not want
to install the udev rule.
2019-02-26 21:19:16 +00:00
2019-04-03 15:31:51 +00:00
As a < device > you can also use: rtlwmbus
to spawn the background process: "rtl_sdr -f 868.95M -s 1600000 - 2>/dev/null | rtl_wmbus"
You can also use: rtlwmbus:868.9M to use this fq instead. Fq tuning can sometimes
be necessary. Or you can specify the entire background process command line: "rtlwmbus:< commandline > "
2019-02-26 21:19:16 +00:00
As meter quadruples you specify:
< meter_name > a mnemonic for this particular meter
< meter_type > one of the supported meters
2019-06-06 15:28:20 +00:00
(can be suffixed with :< mode > to specify which mode you expect the meter to use when transmitting)
2019-02-26 21:19:16 +00:00
< meter_id > an 8 digit mbus id, usually printed on the meter
< meter_key > an encryption key unique for the meter
if the meter uses no encryption, then supply ""
2019-02-26 08:33:10 +00:00
2018-12-28 19:20:30 +00:00
Supported water meters:
Kamstrup Multical 21 (multical21)
Kamstrup flowIQ 3100 (flowiq3100)
Sontex Supercom 587 (supercom587)
Sensus iPERL (iperl)
2019-03-22 18:01:05 +00:00
Apator at-wmbus-16-2 (apator162) (non-standard protocol)
2019-05-04 20:39:45 +00:00
Water meter Techem MK Radio 3 (mkradio3) (non-standard protocol)
2018-12-28 19:20:30 +00:00
2019-05-22 18:06:05 +00:00
Supported heat cost allocators:
2019-03-01 14:51:54 +00:00
Qundis Q caloric (qcaloric)
2019-06-11 17:12:01 +00:00
Innotas EurisII (eurisii)
2019-03-01 14:51:54 +00:00
2019-05-04 06:52:25 +00:00
Supported heat meter:
2019-05-04 20:39:45 +00:00
Heat meter Techem Vario 4 (vario451) (non-standard protocol)
2019-05-04 06:52:25 +00:00
2019-03-20 21:16:45 +00:00
Supported electricity meters:
2019-04-03 15:31:51 +00:00
Tauron Amiplus (amiplus) (includes vendor apator and echelon)
2019-03-20 21:16:45 +00:00
2018-12-28 19:20:30 +00:00
Work in progress:
Heat meter Kamstrup Multical 302 (multical302)
2019-03-20 21:16:45 +00:00
Electricity meter Kamstrup Omnipower (omnipower)
2017-08-31 09:15:12 +00:00
```
2017-08-09 10:00:11 +00:00
2019-06-11 16:52:41 +00:00
The wmbus dongles imst871a can only listen on one type of wmbus telegrams at a time.
Thus you can listen to multiple meters as long as they all require the same radio mode C1 or T1.
2019-07-07 19:51:47 +00:00
However if you use amb8465 or rtlwmbus, then you can listen to both C1 and T1 telegrams at the same time. Alas rtl_wmbus does have problems receiving C1 telegrams, T1 telegrams work ok though.
2017-08-09 10:02:42 +00:00
2018-03-05 11:21:55 +00:00
# Usage examples
2017-09-02 21:26:57 +00:00
2017-08-31 09:15:12 +00:00
```
2019-06-06 15:31:41 +00:00
wmbusmeters /dev/ttyUSB0 MyTapWater multical21:c1 12345678 00112233445566778899AABBCCDDEEFF
2017-08-31 09:15:12 +00:00
```
2019-03-12 20:00:29 +00:00
wmbusmeters will detect which kind of dongle is connected to
/dev/ttyUSB0. It can be either an IMST 871a dongle or an Amber
Wireless AMB8465. If you have performed `make install` or added the
udev rules yourself, then you can use auto instead of the exact usb
device.
2018-02-28 21:14:16 +00:00
2019-06-06 15:31:41 +00:00
(The :c1 can be left out, since multical21 only transmits c1 telegrams. The suffix
with the expected link mode might be necessary for other meters, like apator162 for example.)
2017-08-31 09:15:12 +00:00
Example output:
2018-03-05 11:21:55 +00:00
2019-01-27 23:08:47 +00:00
`MyTapWater 12345678 6.388 m3 6.377 m3 0.000 m3/h 8°C 23°C DRY(dry 22-31 days) 2018-03-05 12:02.50`
2018-11-29 21:32:31 +00:00
2019-01-27 23:08:47 +00:00
(Here the multical21 itself, is configured to send target volume, therefore the max flow is 0.000 m3/h.)
2017-08-31 09:15:12 +00:00
2019-02-26 21:19:16 +00:00
Example format json output:
2017-08-09 10:02:42 +00:00
2019-02-26 21:19:16 +00:00
`wmbusmeters --format=json auto MyTapWater multical21 12345678 00112233445566778899AABBCCDDEEFF MyHeater multical302 22222222 00112233445566778899AABBCCDDEEFF`
2017-08-09 10:00:11 +00:00
2019-01-27 23:08:47 +00:00
`{"media":"cold water","meter":"multical21","name":"MyTapWater","id":"12345678","total_m3":6.388,"target_m3":6.377,"max_flow_m3h":0.000,"flow_temperature":8,"external_temperature":23,"current_status":"DRY","time_dry":"22-31 days","time_reversed":"","time_leaking":"","time_bursting":"","timestamp":"2018-02-08T09:07:22Z"}`
2018-03-05 11:14:23 +00:00
2018-11-02 18:20:52 +00:00
`{"media":"heat","meter":"multical302","name":"MyHeater","id":"22222222","total_kwh":0.000,"total_volume_m3":0.000,"current_kw":"0.000","timestamp":"2018-02-08T09:07:22Z"}`
2018-03-05 11:14:23 +00:00
2019-04-03 15:31:51 +00:00
Example format fields output and use rtlsdr dongle with rtlwmbus tuned to 868.9MHz instead of the
default 868.95MHz.
2018-03-05 11:21:55 +00:00
2019-04-03 15:31:51 +00:00
`wmbusmeters --format=fields rtlwmbus:868.9M GreenhouseWater multical21 33333333 ""`
2018-03-05 11:14:23 +00:00
2019-01-27 23:08:47 +00:00
`GreenhouseTapWater;33333333;9999.099;77.712;0.000;11;31;;2018-03-05 12:10.24`
2017-08-31 08:58:39 +00:00
2018-11-02 12:50:12 +00:00
Eaxmple of using the shell command to publish to MQTT:
2018-11-02 18:08:56 +00:00
`wmbusmeters --shell='HOME=/home/you mosquitto_pub -h localhost -t water -m "$METER_JSON"' auto GreenhouseWater multical21 33333333 ""`
2018-11-02 12:50:12 +00:00
Eaxmple of using the shell command to inject data into postgresql database:
2018-11-02 18:08:56 +00:00
`wmbusmeters --shell="psql waterreadings -c \"insert into readings values ('\$METER_ID',\$METER_TOTAL_M3,'\$METER_TIMESTAMP') \" " auto MyColdWater multical21 12345678 ""`
2018-11-02 12:50:12 +00:00
2018-11-02 18:08:56 +00:00
You can have multiple shell commands and they will be executed in the order you gave them on the commandline.
Note that to single quotes around the command is necessary to pass the env variable names into wmbusmeters.
2019-03-12 19:50:05 +00:00
To list the shell env variables available for your meter, add --shellenvs to the commandline:
`wmbusmeters --shellenvs auto Water iperl 12345678 ""`
which outputs:
```
Environment variables provided to shell for meter iperl:
METER_JSON
METER_TYPE
METER_ID
METER_TOTAL_M3
METER_MAX_FLOW_M3H
METER_TIMESTAMP
```
2018-11-02 12:50:12 +00:00
2019-07-07 20:16:02 +00:00
Note that the METER_TIMESTAMP and the timestamp in the json output, is in UTC format, this is not your localtime.
However the hr and fields output will print your localtime.
2019-05-21 13:36:57 +00:00
You can add `shell=commandline` to a meter file stored in wmbusmeters.d, then this meter will use
this shell command instead of the command stored in wmbusmeters.conf.
2018-02-28 21:14:16 +00:00
You can use `--debug` to get both verbose output and the actual data bytes sent back and forth with the wmbus usb dongle.
2018-03-05 11:21:55 +00:00
If the meter does not use encryption of its meter data, then enter an empty key on the command line.
(you must enter "")
2019-02-26 21:19:16 +00:00
`wmbusmeters --format=json --meterfiles auto MyTapWater multical21 12345678 ""`
2018-03-05 11:21:55 +00:00
2018-12-28 15:07:24 +00:00
If you have a Multical21 meter and you have received a KEM file and its password,
2019-04-03 15:31:51 +00:00
from your water municipality, then you can use the utils/XMLExtract.java utility to get
2018-12-28 15:07:24 +00:00
the meter key from the KEM file. You need to unzip the the KEM file first though,
if it is zipped.
2018-03-05 11:21:55 +00:00
You can run wmbusmeters with --logtelegrams to get log output that can be placed in a simulation.txt
file. You can then run wmbusmeter and instead of auto (or an usb device) provide the simulationt.xt
file as argument. See test.sh for more info.
2019-06-11 17:12:01 +00:00
If you do not specify any meters on the command line, then wmbusmeters
will listen and print the header information of any telegram it hears.
You must specify the listening mode.
With an rtlwmbus or amb8465 dongle: `wmbusmeters --listento=c1,t1 auto`
2019-07-07 19:51:47 +00:00
(Alas rtl_wmbus does have problems receiving C1 telegrams, T1 telegrams work ok though.)
2019-06-11 17:12:01 +00:00
With an imst871a dongle: `wmbusmeters --listento=c1 auto`
2019-03-12 19:37:25 +00:00
# Builds and runs on GNU/Linux and MacOSX (with recent XCode)
2018-03-05 11:21:55 +00:00
`make && make test`
Binary generated: `./build/wmbusmeters`
2019-03-12 19:37:25 +00:00
`make HOST=arm` to cross compile from GNU/Linux to Raspberry PI.
2017-08-09 10:02:42 +00:00
2017-08-31 09:15:12 +00:00
Binary generated: `./build_arm/wmbusmeters`
2017-08-09 10:00:11 +00:00
2017-08-31 09:15:12 +00:00
`make DEBUG=true`
2017-08-09 10:02:42 +00:00
2017-08-31 09:15:12 +00:00
Binary generated: `./build_debug/wmbusmeters`
2017-08-09 10:00:11 +00:00
2017-08-31 09:15:12 +00:00
`make DEBUG=true HOST=arm`
2017-08-09 10:02:42 +00:00
2017-08-31 09:15:12 +00:00
Binary generated: `./build_arm_debug/wmbusmeters`
2017-08-09 10:02:42 +00:00
2019-01-04 20:25:15 +00:00
`make HOST=arm dist`
(Work in progress...)
Binary generated: `./wmbusmeters_0.8_armhf.deb`
2017-09-02 21:26:57 +00:00
# System configuration
2019-03-22 06:31:25 +00:00
`make install` installs the files:
2017-09-02 21:26:57 +00:00
2019-03-22 06:31:25 +00:00
`/etc/wmbusmeters.conf`
`/usr/bin/wmbusmeters`
`/usr/sbin/wmbusmetersd`
`/etc/systemd/system/wmbusmeters.service`
`/etc/udev/rules.d/99-wmbus-usb-serial.rules`
`/etc/logrotate.d/wmbusmeters`
creates these directories:
`/etc/wmbusmeters.d`
`/var/log/wmbusmeters/meter_readings`
and adds the user `wmbusmeters` with no login account.
This means that when a im871a/amb8465 dongle is inserted, then the
appropriate /dev/im871a or /dev/amb8465 link is created. Also the
wmbusmeters daemon will be automatically started/stopped whenever the
im871a/amb8465 dongle is inserted/removed, and the daemon starts when
the computer boots, if the dongle is already inserted.
2019-02-26 21:19:16 +00:00
If you do not want the daemon to start automatically, simply edit
2019-03-22 06:31:25 +00:00
/dev/udev/rules.d/99-wmbus-usb-serial.rules and remove
`,TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters.service"` from each
line.
2018-02-28 21:14:16 +00:00
2019-02-26 21:19:16 +00:00
You can also start/stop the daemon with `sudo systemctl start wmbusmeters`
2019-06-11 17:15:12 +00:00
and trigger the daemon to reload the config files with `sudo killall -HUP wmbusmetersd`
2017-08-09 10:00:11 +00:00
2018-04-20 09:55:57 +00:00
# Source code
2018-02-28 21:14:16 +00:00
The source code is modular and it should be relatively straightforward to add more receivers and meters.
2017-08-09 10:00:11 +00:00
2018-04-20 09:55:57 +00:00
Read for example the text file: HowToAddaNewMeter.txt
2019-05-04 20:39:45 +00:00
# Caveat
If you do not get proper readings from the meters with non-standard protocols. apator162, mkradio3, vario451
then you have to open an issue here and help out by logging a lot of messages and reverse engineer them
even more..... :-/
2017-09-02 21:26:57 +00:00
# Good documents on the wireless mbus protocol:
2018-12-28 19:20:30 +00:00
https://oms-group.org/download4all/
2017-09-02 21:26:57 +00:00
http://www.m-bus.com/files/w4b21021.pdf
2017-08-09 10:02:42 +00:00
2017-08-09 10:00:11 +00:00
https://www.infineon.com/dgdl/TDA5340_AN_WMBus_v1.0.pdf
2017-08-09 10:02:42 +00:00
2017-08-09 10:00:11 +00:00
http://fastforward.ag/downloads/docu/FAST_EnergyCam-Protocol-wirelessMBUS.pdf
2017-08-30 18:08:02 +00:00
http://www.multical.hu/WiredMBus-water.pdf
2017-09-02 21:26:57 +00:00
http://uu.diva-portal.org/smash/get/diva2:847898/FULLTEXT02.pdf
2018-04-01 06:53:37 +00:00
http://projekter.aau.dk/projekter/da/studentthesis/wireless-mbus-based-extremely-low-power-protocol-for-wireless-communication-with-water-meters(6e1139d5-6f24-4b8a-a727-9bc108012bcc).html
2017-08-09 10:00:11 +00:00
The AES source code is copied from:
2017-08-09 10:02:42 +00:00
2017-08-09 10:00:11 +00:00
https://github.com/kokke/tiny-AES128-C
2017-08-31 08:58:39 +00:00
TODO: CRC checks are still missing. If the wrong AES key
is supplied you probably get zero readings and
sometimes warnings about wrong type of frames.
2018-04-01 06:54:53 +00:00
There is also a lot of wmbus protocol implementation details that
probably are missing. They will be added to the program
as we figure out how the meters send their data.