Per Stenebo
2014-10-17 16:46:31
2017-12-30 13:41:19
libmbus
libmbus: M-bus Library from Raditex Control | hemsida | github | python-mbus: Python wrapper for libmbus |
Install libmbus on Ubuntu
Download prebuilt binaries for 64 bit computers:
wget http://www.rscada.se/public-dist/libmbus1_0.8.0_amd64.deb
wget http://www.rscada.se/public-dist/libmbus-dev_0.8.0_amd64.deb
Install: sudo dpkg -i libmbus1_0.8.0_amd64.deb libmbus-dev_0.8.0_amd64.deb
Check path: which mbus-tcp-scan
/usr/bin/mbus-tcp-scan
Install libmbus on Raspberry Pi (Raspian OS)
Tested 2014-10-17 on Raspberry Pi model B+ with Raspbian OS, kernel 3.12.28+ #709 PREEMPT Mon Sep 8 15:28:00 BST 2014 armv6l GNU/Linux
sudo apt-get install libtool automake
Dependencies: autotools-dev libltdl-dev autoconf m4
Download and unpack:
wget https://github.com/rscada/libmbus/archive/0.8.0.zip unzip 0.8.0.zip cd libmbus-0.8.0
Configure:
autoheader && aclocal && libtoolize --ltdl --copy --force && automake --add-missing --copy && autoconf ./configure
Compile and install:
make sudo make install
Check path: which mbus-tcp-scan
/usr/local/bin/mbus-tcp-scan
Use libmbus
mbus-serial-scan
usage: mbus-serial-scan [-d] [-b BAUDRATE] device optional flag -d for debug printout optional flag -b for selecting baudrate
mbus-serial-scan -b 2400 /dev/ttyUSB0 Found a M-Bus device at address 17
mbus-serial-request-data
usage: mbus-serial-request-data [-d] [-b BAUDRATE] device mbus-address optional flag -d for debug printout optional flag -b for selecting baudrate
mbus-serial-request-data -b 2400 /dev/ttyUSB0 17
Problems
Problem
mbus-serial-scan
mbus-serial-scan: error while loading shared libraries: libmbus.so.0: cannot open shared object file: No such file or directory
Search the file: sudo find / | grep libmbus.so.0
/usr/local/lib/libmbus.so.0
export PATH=$PATH:/usr/local/lib
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/local/lib
Still same error, to be continued on github.
On another Ubuntu machine with libmbus installed from prebuilt binay it's located in /usr/lib/libmbus.so.0
Solution
Make a soft link between current position and expected position:
sudo ln -s /usr/local/lib/libmbus.so.0 /usr/lib/libmbus.so.0
Problem
mbus-serial-scan -b 2400 /dev/ttyUSB0
mbus_serial_connect: failed to open tty.mbus_connect_serial: Failed to setup serial connection to M-bus gateway on /dev/ttyUSB0.
Failed to setup connection to M-bus gateway
Solution
Run as root: sudo mbus-serial-scan -b 2400 /dev/ttyUSB0
Debug
Add the -d switch to output debug info.
sudo mbus-serial-scan -d -b 2400 /dev/ttyUSB0 Scanning primary addresses: 0 [2014-10-21 09:43:49] SEND (005): 10 40 00 40 16 1 [2014-10-21 09:43:49] SEND (005): 10 40 01 41 16 2 [2014-10-21 09:43:49] SEND (005): 10 40 02 42 16 3 [2014-10-21 09:43:49] SEND (005): 10 40 03 43 16 4 [2014-10-21 09:43:49] SEND (005): 10 40 04 44 16 5 [2014-10-21 09:43:50] SEND (005): 10 40 05 45 16 6 [2014-10-21 09:43:50] SEND (005): 10 40 06 46 16 7 [2014-10-21 09:43:50] SEND (005): 10 40 07 47 16 8 [2014-10-21 09:43:50] SEND (005): 10 40 08 48 16 9 [2014-10-21 09:43:50] SEND (005): 10 40 09 49 16 10 [2014-10-21 09:43:51] SEND (005): 10 40 0A 4A 16 11 [2014-10-21 09:43:51] SEND (005): 10 40 0B 4B 16 12 [2014-10-21 09:43:51] SEND (005): 10 40 0C 4C 16 13 [2014-10-21 09:43:51] SEND (005): 10 40 0D 4D 16 14 [2014-10-21 09:43:51] SEND (005): 10 40 0E 4E 16 [2014-10-21 09:43:52] RECV (001): E5 Found a M-Bus device at address 14 15 [2014-10-21 09:43:52] SEND (005): 10 40 0F 4F 16 16 [2014-10-21 09:43:52] SEND (005): 10 40 10 50 16 17 [2014-10-21 09:43:52] SEND (005): 10 40 11 51 16 18 [2014-10-21 09:43:52] SEND (005): 10 40 12 52 16 19 [2014-10-21 09:43:53] SEND (005): 10 40 13 53 16 20 [2014-10-21 09:43:53] SEND (005): 10 40 14 54 16 21 [2014-10-21 09:43:53] SEND (005): 10 40 15 55 16 22 [2014-10-21 09:43:53] SEND (005): 10 40 16 56 16
sudo mbus-serial-request-data -d -b 2400 /dev/ttyUSB0 14 [2014-10-21 09:46:53] SEND (005): 10 5B 0E 69 16 [2014-10-21 09:46:53] RECV (085): 68 4F 4F 68 08 0E 72 14 00 00 30 2E 13 01 04 03 0A 00 00 0C 03 95 70 00 00 0C 03 41 00 00 00 04 28 00 00 00 00 04 38 00 00 00 00 0C 10 83 09 83 02 0C 10 31 65 01 00 04 58 29 56 00 00 04 5C 81 59 00 00 04 22 00 00 00 00 04 6D 15 2E C1 19 01 FD 17 0A B3 16 mbus_frame_print: Dumping M-Bus frame [type 4, 85 bytes]: 68 4F 4F 68 08 0E 72 14 00 00 30 2E 13 01 04 03 0A 00 00 0C 03 95 70 00 00 0C 03 41 00 00 00 04 28 00 00 00 00 04 38 00 00 00 00 0C 10 83 09 83 02 0C 10 31 65 01 00 04 58 29 56 00 00 04 5C 81 59 00 00 04 22 00 00 00 00 04 6D 15 2E C1 19 01 FD 17 0A B3 16 ..... M-bus data .....