Skip to content

Commit

Permalink
Merge pull request #26 from PabloCamp0s/main
Browse files Browse the repository at this point in the history
Support both python3 (C300X) and python2 (C100X)
  • Loading branch information
fquinto committed Jan 27, 2024
2 parents be770f8 + a9d3a97 commit 52fba10
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mqtt_scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions mqtt_scripts/StartMqttSend
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion mqtt_scripts/TcpDump2Mqtt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions mqtt_scripts/filter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import time

Expand Down

0 comments on commit 52fba10

Please sign in to comment.