The M-BUS or "meter bus" field bus is the widely used standard for recording consumption values. M-BUS systems always consist of an M-BUS master, which collects the data from the connected consumption meters, which contain a corresponding slave interface.
Since the data transmission works physically different in both directions, different interfaces are needed for the master and the slaves. In this example I want to show how to create a simple M-BUS slave with the help of our M-BUS slave FeatherWings and a Feather microcontroller board. This can be useful if you want to provide your own measured values to an existing M-BUS master.
{gallery}My Gallery Title |
---|
REPLACE THIS TEXT WITH YOUR IMAGE IMAGE TITLE: THEN IMAGE DESCRIPTION |
REPLACE THIS TEXT WITH YOUR IMAGE IMAGE TITLE: THEN IMAGE DESCRIPTION |
REPLACE THIS TEXT WITH YOUR IMAGE IMAGE TITLE: THEN IMAGE DESCRIPTION |
I have created a code example for a simple slave. For the encryption of the individual data blocks I use the M-BUS payload library from Allwize.
Consumption values can be added or edited in the Encode_Payload() function. In this example I simply used constants for the measured values to not need additional hardware for the demo. Of course you can replace these constants with real measured values in your own programs. Be careful with MBUS codes of the "Device" domain. This code does not work or is already contained in the header of the protocol.
You can view the structure of the header in mbusslave.cpp and change parameters, e.g. the manufacturer ID, if necessary.
The default baud rate, default bus address and id of the device can be adjusted in mbusslave.h.
The code was tested with the following feather boards:
- Adafruit Feather Huzzah32
- Adafruit Feather nRF52840
- Adafruit Feather M0 Express
- Sparkfun ESP32 Thing Plus
- Sparkfun Thing Plus RP2040
For the test you need a MBUS master, which supplies the MBUS and can exchange data with the slave. For example you can use a Raspberry Pi with libmbus and our MBUS Master HAT.
Another possibility is to use a PC interface and a M-BUS Master simulator e.g. Lorus Free.