wmbusmeters / wmbusmeters

Read the wired or wireless mbus protocol to acquire utility meter readings.
GNU General Public License v3.0
951 stars 225 forks source link

Add support for rtl_tcp? #511

Open andriej opened 2 years ago

andriej commented 2 years ago

In most known package of librtlsdr there's rtl_tcp (which enables RTL on tcp and can be used on remote hosts). I have some cheap openwrt router which could be host for USB RTL stick while readings/parsing could be done remotely.

Is it doable to use it with wmbusmeters tho?

weetmuts commented 2 years ago

It seems like it would send quite a lot of traffic over the network.... if your openwrt router can run rtl_wmbus, then you can relay the decoded telegrams to wmbusmeters on a different computer.

On the openwrt router: rtl_sdr -f 868.95M -s 1600000 - 2>/dev/null | rtl_wmbus -p s -a | nc -u 192.168.1.777 4444

On 192.168.1.777: wmbusmeters 'rtlwmbus:CMD(nc -lku 4444)'

I suppose you could do something similar with rtl_tcp if your openwrt router cannot run rtl_wmbus.

Check the README for how rtl_wmbus is started and tips on using it in a pipe.

weetmuts commented 2 years ago

@andriej I got it working like this: On your router run: rtl_tcp -f 868.95M -s 1600000 -a 192.168.xx.xx on your computer run: nc 192.168.xx.xx 1234 | /usr/bin/rtl_wmbus -p s -a | wmbusmeters stdin:rtlwmbus

xx.xx is whatever your router network ip address is.

It should work with the nc 192 ... | rtlwmbus | wmbusmeters command inside rtlwmbus:CMD(nc .... ) but for some reason it does not. Something to debug...

Please test!

andriej commented 2 years ago

I'd love to test it, just wondering how to implement your way of work into running add-on in HA installation. I have to sleep it over, maybe clues will come - seems like solution is close :-)

andriej commented 2 years ago

Whatever I try to run addon with, I end up with:

Not a valid device "rtlwmbus:CMD("nc 192.168.x.x 1234|/usr/bin/rtl_wmbus -p s -a|wmbusmeters stdin:rtlwmbus ")"
[cmd] /run.sh exited 1
travnick commented 2 years ago

I try to ply with nc and wmbusmeters but without a success. This command terminates immediately

wmbusmeters --useconfig /etc

device in config file:

device=rtlwmbus:CMD(nc 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters stdin:rtlwmbus)

log output:

/var/log/wmbusmeters/wmbusmeters.log 
(serialcmd) closed /bin/sh pid=7513 fd=-1 (rtlwmbus)
[LOCKING] serial_devices_mutex close_all_do_not_remove ( 0)
[LOCKED]  serial_devices_mutex close_all_do_not_remove (close_all_do_not_remove 7509)
[UNLOCKING] serial_devices_mutex close_all_do_not_remove (close_all_do_not_remove 7509)
[UNLOCKED]  serial_devices_mutex close_all_do_not_remove ( 0)
[LOCKING] serial_devices_mutex remove_non_working_serial_devices ( 0)
[LOCKED]  serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 7509)
(serial) no devices working emergency exit!
[UNLOCKING] serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 7509)
[UNLOCKED]  serial_devices_mutex remove_non_working_serial_devices ( 0)

simply executing nc 192.168.1.2 1234 | rtl_wmbus -p s shows incoming data.

weetmuts commented 2 years ago

It seems like nc exits as soon as stdin is EOF. And stdin becomes EOF immediately when the background process is started. Add "-q -1" to prevent this from happing so try:

device=rtlwmbus:CMD(nc -q -1 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters stdin:rtlwmbus)

travnick commented 2 years ago

nc (netcat (The GNU Netcat) 0.7.1) does not have -q and -1 options.

Anyway I see some strange issues in logs:

$ wmbusmeters --use
(config) "# Remember to change auto here to the device you are going to use in production." ""
(config) "#device=rtlwmbus:868.9M" ""
(config) "#device=rtlwmbus:CMD(nc 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters --device=stdin:rtlwmbus)" ""
(config) "#device=rtl433:CMD(rtl_433 -d rtl_tcp:192.168.1.2:1234 -f 868.95M -s 1.2M -Y autolevel -Y squelch -R 104 -M level -M protocol -F csv)" ""
(config) "device" "rtlwmbus:CMD(nc 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters stdin:rtlwmbus)"
(config) "logtelegrams" "false"
(config) "format" "json"
(config) "meterfiles" "/var/lib/wmbusmeters/meter_readings"
(config) "meterfilesaction" "append"
(config) "logfile" "/var/log/wmbusmeters/wmbusmeters.log"
(config) "" ""
(config) loading meter file /etc/wmbusmeters.d/apator01946185.conf
(config) name=apator01946185
(config) type=apator162
(config) id=01946185
(config) key=<notprinted>
(wmbusmeters) using log file /var/log/wmbusmeters/wmbusmeters.log

So it says that there is one meter configured, but in log /var/log/wmbusmeters/wmbusmeters.log it says No meters configured:

(serial) received ascii "Started config rtlwmbus on stdin listening on any<0A>No meters configured. Printing id:s of all telegrams heard!<0A>"
[UNLOCKING] read_mutex receive (receive 69768)
[UNLOCKED]  read_mutex receive ( 0)
(rtlwmbus) checkRTLWMBusFrame "Started config rtlwmbus on stdin listening on any<0A>No meters configured. Printing id:s of all telegrams heard!<0A>"
(rtlwmbus) only text
(rtlwmbus) checkRTLWMBusFrame "No meters configured. Printing id:s of all telegrams heard!<0A>"
(rtlwmbus) only text
(wmbusmeters) version: HEAD_1.9.0
(config) store meter files in: "/var/lib/wmbusmeters/meter_readings"
(config) using device: rtlwmbus:CMD(nc 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters stdin:rtlwmbus) 
(config) number of meters: 1
[LOCKING] bus_devices_mutex check_for_bus_devices ( 0)
[LOCKED]  bus_devices_mutex check_for_bus_devices (check_for_bus_devices 69768)
[MAIN] checking for dead wmbus devices...
[LOCKING] event_loop_mutex eventLoop ( 0)
(serial) expecting devices to work
[UNLOCKING] bus_devices_mutex check_for_bus_devices (check_for_bus_devices 69768)
[UNLOCKED]  bus_devices_mutex check_for_bus_devices ( 0)
[LOCKING] bus_devices_mutex check_for_bus_devices ( 0)
[LOCKED]  bus_devices_mutex check_for_bus_devices (check_for_bus_devices 69768)
[LOCKED]  event_loop_mutex eventLoop (eventLoop 69768)
[MAIN] checking for dead wmbus devices...
(serial) expecting devices to work
[LOCKING] serial_devices_mutex list_file_descriptiors_to_listen_to ( 0)
[UNLOCKING] bus_devices_mutex check_for_bus_devices (check_for_bus_devices 69768)
[UNLOCKED]  bus_devices_mutex check_for_bus_devices ( 0)
[LOCKED]  serial_devices_mutex list_file_descriptiors_to_listen_to (list_file_descriptiors_to_listen_to 69768)
[LOCKING] serial_devices_mutex lookup (list_file_descriptiors_to_listen_to 69768)
[UNLOCKING] serial_devices_mutex list_file_descriptiors_to_listen_to (list_file_descriptiors_to_listen_to 69768)
[UNLOCKED]  serial_devices_mutex list_file_descriptiors_to_listen_to ( 0)
[LOCKED]  serial_devices_mutex lookup (lookup 69768)
[SERIAL] select timeout 1 s
[UNLOCKING] serial_devices_mutex lookup (lookup 69768)
[UNLOCKED]  serial_devices_mutex lookup ( 0)
(lookup) with cmd "rtlwmbus:CMD(nc 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters stdin:rtlwmbus)"
[LOCKING] bus_devices_mutex open_bus_device ( 0)
[LOCKED]  bus_devices_mutex open_bus_device (open_bus_device 69768)
(main) opening rtlwmbus:CMD(nc 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters stdin:rtlwmbus)
Started config rtlwmbus listening on none using CMD(nc 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters stdin:rtlwmbus)
(rtlwmbus) using command: nc 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters stdin:rtlwmbus
(rtlwmbus) opening cmd_0
[LOCKING] serial_devices_mutex opened ( 0)
[LOCKED]  serial_devices_mutex opened (opened 69768)
[LOCKING] serial_devices_mutex tickle (opened 69768)
[LOCKED]  serial_devices_mutex tickle (tickle 69768)
[UNLOCKING] serial_devices_mutex tickle (tickle 69768)
[UNLOCKED]  serial_devices_mutex tickle ( 0)
[UNLOCKING] serial_devices_mutex opened ( 0)
(serial) EVENT thread interrupted
[UNLOCKED]  serial_devices_mutex opened ( 0)
[LOCKING] serial_devices_mutex find_non_working_serial_devices ( 0)
(bgshell) exec background "/bin/sh"
(bgshell) arg "-c"
[LOCKED]  serial_devices_mutex find_non_working_serial_devices (find_non_working_serial_devices 69768)
(bgshell) arg "nc 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters stdin:rtlwmbus"
[UNLOCKING] serial_devices_mutex find_non_working_serial_devices (find_non_working_serial_devices 69768)
[UNLOCKED]  serial_devices_mutex find_non_working_serial_devices ( 0)
[LOCKING] serial_devices_mutex remove_non_working_serial_devices ( 0)
[LOCKED]  serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 69768)
[UNLOCKING] serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 69768)
[UNLOCKED]  serial_devices_mutex remove_non_working_serial_devices ( 0)
[LOCKING] serial_devices_mutex list_file_descriptiors_to_listen_to ( 0)
[LOCKED]  serial_devices_mutex list_file_descriptiors_to_listen_to (list_file_descriptiors_to_listen_to 69768)
[SERIAL] select read on fd 4
[UNLOCKING] serial_devices_mutex list_file_descriptiors_to_listen_to (list_file_descriptiors_to_listen_to 69768)
[UNLOCKED]  serial_devices_mutex list_file_descriptiors_to_listen_to ( 0)
[SERIAL] select timeout 1 s
(serialcmd) opened /bin/sh pid 69772 fd 4 (rtlwmbus)
(main) regular reset of rtlwmbus  using CMD(nc 192.168.1.2 1234 | rtl_wmbus -p s | wmbusmeters stdin:rtlwmbus) will happen every 82800 seconds
(wmbus) no alarm (expected activity) for rtlwmbus
[UNLOCKING] bus_devices_mutex open_bus_device (open_bus_device 69768)
[UNLOCKED]  bus_devices_mutex open_bus_device ( 0)
[LOCKING] timers_mutex start_regular_callback ( 0)
[LOCKED]  timers_mutex start_regular_callback (start_regular_callback 69768)
(serial) registered regular callback HOT_PLUG_DETECTOR(0) every 2 seconds
[UNLOCKING] timers_mutex start_regular_callback (start_regular_callback 69768)
[UNLOCKED]  timers_mutex start_regular_callback ( 0)
[LOCKING] bus_send_queue_mutex send_content ( 0)
[LOCKED]  bus_send_queue_mutex send_content (send_content 69768)
[UNLOCKING] bus_send_queue_mutex send_content (send_content 69768)
[UNLOCKED]  bus_send_queue_mutex send_content ( 0)
(serial) waiting for stop
[LOCKING] serial_devices_mutex wait_for_stop ( 0)
[LOCKED]  serial_devices_mutex wait_for_stop (wait_for_stop 69768)
[UNLOCKING] serial_devices_mutex wait_for_stop (wait_for_stop 69768)
[UNLOCKED]  serial_devices_mutex wait_for_stop ( 0)
[LOCKING] serial_devices_mutex find_triggering_file_descriptions ( 0)
[LOCKED]  serial_devices_mutex find_triggering_file_descriptions (find_triggering_file_descriptions 69768)
[SERIAL] select detected data available for reading on fd 4
[UNLOCKING] serial_devices_mutex find_triggering_file_descriptions (find_triggering_file_descriptions 69768)
[UNLOCKED]  serial_devices_mutex find_triggering_file_descriptions ( 0)
[LOCKING] read_mutex receive ( 0)
[LOCKED]  read_mutex receive (receive 69768)
(serial) received ascii "Started config rtlwmbus on stdin listening on any<0A>No meters configured. Printing id:s of all telegrams heard!<0A>"
[UNLOCKING] read_mutex receive (receive 69768)
[UNLOCKED]  read_mutex receive ( 0)
(rtlwmbus) checkRTLWMBusFrame "Started config rtlwmbus on stdin listening on any<0A>No meters configured. Printing id:s of all telegrams heard!<0A>"
(rtlwmbus) only text
(rtlwmbus) checkRTLWMBusFrame "No meters configured. Printing id:s of all telegrams heard!<0A>"
(rtlwmbus) only text
[LOCKING] serial_devices_mutex find_non_working_serial_devices ( 0)
[LOCKED]  serial_devices_mutex find_non_working_serial_devices (find_non_working_serial_devices 69768)
[UNLOCKING] serial_devices_mutex find_non_working_serial_devices (find_non_working_serial_devices 69768)
[UNLOCKED]  serial_devices_mutex find_non_working_serial_devices ( 0)
[LOCKING] serial_devices_mutex remove_non_working_serial_devices ( 0)
[LOCKED]  serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 69768)
[UNLOCKING] serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 69768)
[UNLOCKED]  serial_devices_mutex remove_non_working_serial_devices ( 0)
[LOCKING] serial_devices_mutex list_file_descriptiors_to_listen_to ( 0)
[LOCKED]  serial_devices_mutex list_file_descriptiors_to_listen_to (list_file_descriptiors_to_listen_to 69768)
[SERIAL] select read on fd 4
[UNLOCKING] serial_devices_mutex list_file_descriptiors_to_listen_to (list_file_descriptiors_to_listen_to 69768)
[UNLOCKED]  serial_devices_mutex list_file_descriptiors_to_listen_to ( 0)
[SERIAL] select timeout 1 s
[LOCKING] serial_devices_mutex find_triggering_file_descriptions ( 0)
[LOCKED]  serial_devices_mutex find_triggering_file_descriptions (find_triggering_file_descriptions 69768)
[SERIAL] select detected data available for reading on fd 4
[UNLOCKING] serial_devices_mutex find_triggering_file_descriptions (find_triggering_file_descriptions 69768)
[UNLOCKED]  serial_devices_mutex find_triggering_file_descriptions ( 0)
[LOCKING] read_mutex receive ( 0)
[LOCKED]  read_mutex receive (receive 69768)
(serial) received ascii "read(net): Zasoby chwilowo niedost?pne<0A>"
[UNLOCKING] read_mutex receive (receive 69768)
[UNLOCKED]  read_mutex receive ( 0)
(rtlwmbus) checkRTLWMBusFrame "read(net): Zasoby chwilowo niedost?pne<0A>"
(rtlwmbus) only text
[LOCKING] serial_devices_mutex find_non_working_serial_devices ( 0)
[LOCKED]  serial_devices_mutex find_non_working_serial_devices (find_non_working_serial_devices 69768)
[UNLOCKING] serial_devices_mutex find_non_working_serial_devices (find_non_working_serial_devices 69768)
[UNLOCKED]  serial_devices_mutex find_non_working_serial_devices ( 0)
[LOCKING] serial_devices_mutex remove_non_working_serial_devices ( 0)
[LOCKED]  serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 69768)
[UNLOCKING] serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 69768)
[UNLOCKED]  serial_devices_mutex remove_non_working_serial_devices ( 0)
[LOCKING] serial_devices_mutex list_file_descriptiors_to_listen_to ( 0)
[LOCKED]  serial_devices_mutex list_file_descriptiors_to_listen_to (list_file_descriptiors_to_listen_to 69768)
[SERIAL] select read on fd 4
[UNLOCKING] serial_devices_mutex list_file_descriptiors_to_listen_to (list_file_descriptiors_to_listen_to 69768)
[UNLOCKED]  serial_devices_mutex list_file_descriptiors_to_listen_to ( 0)
[SERIAL] select timeout 1 s
(serial) MAIN thread interrupted
[LOCKING] serial_devices_mutex wait_for_stop ( 0)
(serial) EVENT thread interrupted
[LOCKED]  serial_devices_mutex wait_for_stop (wait_for_stop 69768)
[LOCKING] serial_devices_mutex find_non_working_serial_devices (wait_for_stop 69768)
[UNLOCKING] serial_devices_mutex wait_for_stop (wait_for_stop 69768)
[UNLOCKED]  serial_devices_mutex wait_for_stop ( 0)
[LOCKED]  serial_devices_mutex find_non_working_serial_devices (find_non_working_serial_devices 69768)
(bgshell) 69772 exited with return code 0
[UNLOCKING] serial_devices_mutex find_non_working_serial_devices (find_non_working_serial_devices 69768)
[UNLOCKED]  serial_devices_mutex find_non_working_serial_devices ( 0)
(serial) closing non working fd=4 "cmd_0"
(wmbus) disconnected cmd_0 rtlwmbus
[LOCKING] serial_devices_mutex tickle ( 0)
[LOCKED]  serial_devices_mutex tickle (tickle 69768)
[UNLOCKING] serial_devices_mutex tickle (tickle 69768)
[UNLOCKED]  serial_devices_mutex tickle ( 0)
(serialcmd) closed /bin/sh pid=69772 fd=4 (rtlwmbus)
[LOCKING] serial_devices_mutex remove_non_working_serial_devices ( 0)
[LOCKED]  serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 69768)
(serial) no devices working emergency exit!
(serial) stopping manager
[UNLOCKING] serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 69768)
(serial) MAIN thread interrupted
[UNLOCKED]  serial_devices_mutex remove_non_working_serial_devices ( 0)
[LOCKING] serial_devices_mutex close_all_do_not_remove ( 0)
(serial) non working devices found, exiting.
[LOCKED]  serial_devices_mutex close_all_do_not_remove (close_all_do_not_remove 69768)
(serial) TIMER thread interrupted
(serial) event loop stopped!
[UNLOCKING] serial_devices_mutex close_all_do_not_remove (close_all_do_not_remove 69768)
[UNLOCKING] event_loop_mutex eventLoop (eventLoop 69768)
[UNLOCKED]  serial_devices_mutex close_all_do_not_remove ( 0)
[UNLOCKED]  event_loop_mutex eventLoop ( 0)
(wmbus) deleted rtlwmbus
[LOCKING] serial_devices_mutex tickle ( 0)
[LOCKED]  serial_devices_mutex tickle (tickle 69768)
[UNLOCKING] serial_devices_mutex tickle (tickle 69768)
[UNLOCKED]  serial_devices_mutex tickle ( 0)
(serialcmd) closed /bin/sh pid=69772 fd=-1 (rtlwmbus)
[LOCKING] serial_devices_mutex close_all_do_not_remove ( 0)
[LOCKED]  serial_devices_mutex close_all_do_not_remove (close_all_do_not_remove 69768)
[UNLOCKING] serial_devices_mutex close_all_do_not_remove (close_all_do_not_remove 69768)
[UNLOCKED]  serial_devices_mutex close_all_do_not_remove ( 0)
[LOCKING] serial_devices_mutex remove_non_working_serial_devices ( 0)
[LOCKED]  serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 69768)
(serial) no devices working emergency exit!
[UNLOCKING] serial_devices_mutex remove_non_working_serial_devices (remove_non_working_serial_devices 69768)
[UNLOCKED]  serial_devices_mutex remove_non_working_serial_devices ( 0)
chpego commented 1 year ago

Hello @andriej Do you have some news ?