From 05e2de13da293b22bd552b82ee33b542624b46dc Mon Sep 17 00:00:00 2001 From: Pablo Date: Mon, 16 Oct 2023 08:03:32 +0200 Subject: [PATCH 1/2] Fixes for C100X compatibility --- mqtt_scripts/README.md | 2 +- mqtt_scripts/StartMqttSend | 7 ++++--- mqtt_scripts/TcpDump2Mqtt | 2 +- mqtt_scripts/filter.py | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mqtt_scripts/README.md b/mqtt_scripts/README.md index 7cd9021..8264fad 100644 --- a/mqtt_scripts/README.md +++ b/mqtt_scripts/README.md @@ -2,7 +2,7 @@ The goal of this guide is to export to an MQTT broker (mosquitto or others) the commands managed by the BTicino C100X/C300X video door entry unit, in order to allow integration of the system into a home automation software (eg: Homeassistant). -These scripts use utilities already present in the video door entry unit (mosquitto_pub, mosquitto_sub, python3, tcpdump), in fact it is not necessary to install any additional software. +These scripts use utilities already present in the video door entry unit (mosquitto_pub, mosquitto_sub, python 2/3, tcpdump), in fact it is not necessary to install any additional software. To export the commands of the video door entry unit to the network in MQTT I have prepared the following script files diff --git a/mqtt_scripts/StartMqttSend b/mqtt_scripts/StartMqttSend index dd1f9b2..6fbd5ea 100755 --- a/mqtt_scripts/StartMqttSend +++ b/mqtt_scripts/StartMqttSend @@ -1,9 +1,10 @@ #!/bin/sh +python="$( [ -x '/usr/bin/python' ] && echo '/usr/bin/python' || echo '/usr/bin/python3')" if [ -n "${MQTT_USER}" ]; then - /usr/sbin/tcpdump -i lo -U not udp and not icmp and not port 5007 and not port 5060 and not port 20000 and not dst port 30006 -A -q -l 2>&1 | /usr/bin/python3 /home/root/filter.py | /usr/bin/mosquitto_pub -l -h ${MQTT_HOST} -p ${MQTT_PORT} -u ${MQTT_USER} -P ${MQTT_PASS} -t ${TOPIC_DUMP} + /usr/sbin/tcpdump -i lo -U not udp and not icmp and not port 5007 and not port 5060 and not port 20000 and not dst port 30006 -A -q -l 2>&1 | "${python}" /home/root/filter.py | /usr/bin/mosquitto_pub -l -h ${MQTT_HOST} -p ${MQTT_PORT} -u ${MQTT_USER} -P ${MQTT_PASS} -t ${TOPIC_DUMP} elif [ -n "${MQTT_CAFILE}" ]; then - /usr/sbin/tcpdump -i lo -U not udp and not icmp and not port 5007 and not port 5060 and not port 20000 and not dst port 30006 -A -q -l 2>&1 | /usr/bin/python3 /home/root/filter.py | /usr/bin/mosquitto_pub -l -h ${MQTT_HOST} -p ${MQTT_PORT} -t ${TOPIC_DUMP} --cafile ${MQTT_CAFILE} --cert ${MQTT_CERTFILE} --key ${MQTT_KEYFILE} + /usr/sbin/tcpdump -i lo -U not udp and not icmp and not port 5007 and not port 5060 and not port 20000 and not dst port 30006 -A -q -l 2>&1 | "${python}" /home/root/filter.py | /usr/bin/mosquitto_pub -l -h ${MQTT_HOST} -p ${MQTT_PORT} -t ${TOPIC_DUMP} --cafile ${MQTT_CAFILE} --cert ${MQTT_CERTFILE} --key ${MQTT_KEYFILE} else - /usr/sbin/tcpdump -i lo -U not udp and not icmp and not port 5007 and not port 5060 and not port 20000 and not dst port 30006 -A -q -l 2>&1 | /usr/bin/python3 /home/root/filter.py | /usr/bin/mosquitto_pub -l -h ${MQTT_HOST} -p ${MQTT_PORT} -t ${TOPIC_DUMP} + /usr/sbin/tcpdump -i lo -U not udp and not icmp and not port 5007 and not port 5060 and not port 20000 and not dst port 30006 -A -q -l 2>&1 | "${python}" /home/root/filter.py | /usr/bin/mosquitto_pub -l -h ${MQTT_HOST} -p ${MQTT_PORT} -t ${TOPIC_DUMP} fi diff --git a/mqtt_scripts/TcpDump2Mqtt b/mqtt_scripts/TcpDump2Mqtt index 7606a44..f51c2ad 100755 --- a/mqtt_scripts/TcpDump2Mqtt +++ b/mqtt_scripts/TcpDump2Mqtt @@ -12,7 +12,7 @@ function kill_childs() { echo "Killed mosquitto_pub process with PID $PID" fi - PID="$(ps -edf | grep python3 | grep filter.py | awk '{print $2}')" + PID="$(ps -edf | grep python | grep filter.py | awk '{print $2}')" if [ -n "${PID}" ]; then kill $PID > /dev/null echo "Killed filter.py process with PID $PID" diff --git a/mqtt_scripts/filter.py b/mqtt_scripts/filter.py index 37d8820..36351c3 100644 --- a/mqtt_scripts/filter.py +++ b/mqtt_scripts/filter.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import sys import time +from __future__ import print_function for line in sys.stdin: if "##" in line: From a9d3a978fa62aed097b9719655120caf3f191134 Mon Sep 17 00:00:00 2001 From: Pablo Date: Mon, 30 Oct 2023 14:14:29 +0100 Subject: [PATCH 2/2] Import must be in first line --- mqtt_scripts/filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mqtt_scripts/filter.py b/mqtt_scripts/filter.py index 36351c3..09258c4 100644 --- a/mqtt_scripts/filter.py +++ b/mqtt_scripts/filter.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import print_function import sys import time -from __future__ import print_function for line in sys.stdin: if "##" in line: