The program receives and decodes C1,T1 or S1 telegrams (using the wireless mbus protocol) to acquire utility meter readings
 
 
 
 
 
 
Go to file
weetmuts 38c3287f68 Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
.travis.yml Added Travis-ci autobuild and test support. 2018-01-05 17:46:10 +01:00
CHANGES Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
HowToAddaNewMeter.txt Added explanation on how to add new meters. 2018-04-20 11:55:57 +02:00
LICENSE New difvif parser 2018-04-01 08:53:37 +02:00
Makefile Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
README.md Experiment with generating deb package. 2019-01-04 21:25:15 +01:00
XMLExtract.java Fix 2018-12-29 23:50:17 +01:00
aes.cc Initial commit. 2017-08-09 12:00:11 +02:00
aes.h Initial commit. 2017-08-09 12:00:11 +02:00
check.sh Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
cmdline.cc Updated Readme and copyrights. 2018-12-28 20:20:30 +01:00
cmdline.h Updated Readme and copyrights. 2018-12-28 20:20:30 +01:00
configure Added Travis-ci autobuild and test support. 2018-01-05 17:46:10 +01:00
crc.cc Added crc experiment file. 2018-04-01 09:09:49 +02:00
dvparser.cc Now parses dife bytes and more vife bytes. 2019-01-02 00:20:10 +01:00
dvparser.h Now parses dife bytes and more vife bytes. 2019-01-02 00:20:10 +01:00
main.cc Added address sanitizer to debug build and fixed memory errors. 2018-12-28 18:35:32 +01:00
manufacturers.h Added --oneshot and Telegram::print 2017-09-02 23:26:57 +02:00
meter_iperl.cc Added address sanitizer to debug build and fixed memory errors. 2018-12-28 18:35:32 +01:00
meter_multical21.cc Experiment with generating deb package. 2019-01-04 21:25:15 +01:00
meter_multical302.cc Added address sanitizer to debug build and fixed memory errors. 2018-12-28 18:35:32 +01:00
meter_omnipower.cc Added address sanitizer to debug build and fixed memory errors. 2018-12-28 18:35:32 +01:00
meter_supercom587.cc Added address sanitizer to debug build and fixed memory errors. 2018-12-28 18:35:32 +01:00
meters.cc Added iPerl water meter. 2018-11-23 09:04:31 +01:00
meters.h Added address sanitizer to debug build and fixed memory errors. 2018-12-28 18:35:32 +01:00
meters_common_implementation.h Added address sanitizer to debug build and fixed memory errors. 2018-12-28 18:35:32 +01:00
printer.cc Added --shell option to invoke shell commands. 2018-11-02 13:50:12 +01:00
printer.h Added --shell option to invoke shell commands. 2018-11-02 13:50:12 +01:00
serial.cc Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
serial.h Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
shell.cc Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
shell.h Added --shell option to invoke shell commands. 2018-11-02 13:50:12 +01:00
simulation_c1.txt Updated version nr to 0.8 2018-11-29 22:34:16 +01:00
simulation_t1.txt Added temperature support for multical21 and fixed im871a bug. 2018-11-29 22:25:50 +01:00
test.sh Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
testinternals.cc Now parses dife bytes and more vife bytes. 2019-01-02 00:20:10 +01:00
util.cc Added temperature support for multical21 and fixed im871a bug. 2018-11-29 22:25:50 +01:00
util.h Added address sanitizer to debug build and fixed memory errors. 2018-12-28 18:35:32 +01:00
wmbus.cc Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
wmbus.h Now parses dife bytes and more vife bytes. 2019-01-02 00:20:10 +01:00
wmbus_amb8465.cc Added address sanitizer to debug build and fixed memory errors. 2018-12-28 18:35:32 +01:00
wmbus_amb8465.h Added support for the Amber amb8465 wmbus usb dongle. 2018-02-28 22:14:16 +01:00
wmbus_im871a.cc Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
wmbus_im871a.h Added support for the Amber amb8465 wmbus usb dongle. 2018-02-28 22:14:16 +01:00
wmbus_simulator.cc Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
wmbus_utils.cc Fixed memory leak in shell. 2019-01-04 22:27:51 +01:00
wmbus_utils.h Improve difvif parser and other fixes. 2018-11-25 12:33:14 +01:00

README.md

wmbusmeters

The program receives and decodes C1 or T1 telegrams (using the wireless mbus protocol) to acquire utility meter readings. The readings can then be published using MQTT, inserted into a database or stored in a log file.

The program runs on GNU/Linux (standard x86) and Raspberry Pi (arm).

OS/Compiler Status
Linux G++ Build Status
wmbusmeters version: 0.8
Usage: wmbusmeters {options} (auto | /dev/ttyUSBx)] { [meter_name] [meter_type] [meter_id] [meter_key] }*

Add more meter quadruplets to listen to more meters.
Add --verbose for detailed debug information.
    --robot or --robot=json for json output.
    --robot=fields for semicolon separated fields.
    --separator=X change field separator to X.
    --meterfiles=dir to create status files below dir,
          named dir/meter_name, containing the latest reading.
    --meterfiles defaults dir to /tmp.
    --c1 or --t1 listen to C1 or T1 messages
    --shell=cmd invokes cmd with env variables containing the latest reading.
    --shellenvs list the env variables available for the meter.
    --oneshot wait for an update from each meter, then quit.
    --exitafter=20h program exits after running for twenty hours,
          or 10m for ten minutes or 5s for five seconds.

Specifying auto as the device will automatically look for usb
wmbus dongles on /dev/im871a and /dev/amb8465.

Supported water meters:
Kamstrup Multical 21 (multical21)
Kamstrup flowIQ 3100 (flowiq3100)
Sontex Supercom 587 (supercom587)
Sensus iPERL (iperl)

Work in progress:
Heat meter Kamstrup Multical 302 (multical302)
Electricity meter Kamstrup Omnipower (omnipower)

No meter quadruplets means listen for telegram traffic and print any id heard, but you have to specify if you want to listen using radio mode C1 or T1. E.g.

wmbusmeters --t1 /dev/ttyUSB0

You can listen to multiple meters as long as they all require the same radio mode C1 or T1. So (currently) you cannot listen to a multical21 and a supercom587 with a single dongle at the same time.

Usage examples

wmbusmeters /dev/ttyUSB0 MyTapWater multical21 12345678 00112233445566778899AABBCCDDEEFF

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 setup the udev rules below, then you can use auto instead of /dev/ttyUSB0.

Example output:

MyTapWater 12345678 6.388 m3 6.377 m3 8°C 23°C DRY(dry 22-31 days) 2018-03-05 12:02.50

(Temperature is only sent every 8 message. Until such a full message has been received, the temperature is reported as -°C in the human readable output, and as 127°C in the robot outputs and json.)

Example robot json output:

wmbusmeters --robot=json auto MyTapWater multical21 12345678 00112233445566778899AABBCCDDEEFF MyHeater multical302 22222222 00112233445566778899AABBCCDDEEFF

{"media":"cold water","meter":"multical21","name":"MyTapWater","id":"12345678","total_m3":6.388,"target_m3":6.377,"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"}

{"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"}

Example robot fields output:

wmbusmeters --robot=fields auto GreenhouseWater multical21 33333333 ""

GreenhouseTapWater;33333333;9999.099;77.712;11;31;;2018-03-05 12:10.24

Eaxmple of using the shell command to publish to MQTT:

wmbusmeters --shell='HOME=/home/you mosquitto_pub -h localhost -t water -m "$METER_JSON"' auto GreenhouseWater multical21 33333333 ""

Eaxmple of using the shell command to inject data into postgresql database:

wmbusmeters --shell="psql waterreadings -c \"insert into readings values ('\$METER_ID',\$METER_TOTAL_M3,'\$METER_TIMESTAMP') \" " auto MyColdWater multical21 12345678 ""

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.

You can use --debug to get both verbose output and the actual data bytes sent back and forth with the wmbus usb dongle.

If the meter does not use encryption of its meter data, then enter an empty key on the command line. (you must enter "")

wmbusmeters --robot --meterfiles auto MyTapWater multical21 12345678 ""

If you have a Multical21 meter and you have received a KEM file and its password, from your water municipality, then you can use the XMLExtract.java utility to get the meter key from the KEM file. You need to unzip the the KEM file first though, if it is zipped.

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.

Builds and runs on GNU/Linux:

make && make test

Binary generated: ./build/wmbusmeters

make HOST=arm

Binary generated: ./build_arm/wmbusmeters

make DEBUG=true

Binary generated: ./build_debug/wmbusmeters

make DEBUG=true HOST=arm

Binary generated: ./build_arm_debug/wmbusmeters

make HOST=arm dist

(Work in progress...) Binary generated: ./wmbusmeters_0.8_armhf.deb

System configuration

Add yourself to the dialout group to get access to the newly plugged in im871A USB stick. Or even better, add this udev rule:

Create the file: /etc/udev/rules.d/99-usb-serial.rules with the content

SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="im871a",MODE="0660", GROUP="yourowngroup"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="amb8465",MODE="0660", GROUP="yourowngroup"

When you insert the wmbus USB dongle, a properly named symlink will be created: either /dev/im871a or /dev/amb8465. These symlinks are necessary if you want to pass "auto" to wmbusmeters instead of the exact serial port /dev/ttyUSBx.

Source code

The source code is modular and it should be relatively straightforward to add more receivers and meters.

Read for example the text file: HowToAddaNewMeter.txt

Good documents on the wireless mbus protocol:

https://oms-group.org/download4all/

http://www.m-bus.com/files/w4b21021.pdf

https://www.infineon.com/dgdl/TDA5340_AN_WMBus_v1.0.pdf

http://fastforward.ag/downloads/docu/FAST_EnergyCam-Protocol-wirelessMBUS.pdf

http://www.multical.hu/WiredMBus-water.pdf

http://uu.diva-portal.org/smash/get/diva2:847898/FULLTEXT02.pdf

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

The AES source code is copied from:

https://github.com/kokke/tiny-AES128-C

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.

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.