Skip to content

Commit

Permalink
remove compatibility with deb12 to unblock ble_scan on deb11
Browse files Browse the repository at this point in the history
  • Loading branch information
Mips2648 committed Jan 15, 2025
1 parent ae151f6 commit 224909f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
1 change: 0 additions & 1 deletion docs/fr_FR/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
- Fix une fuite de mémoire sur le démon
- Corrections mineures
- Adapatations interface "Liste des commandes"
- Compatibilité Debian 12
- Jeedom 4.4 ou plus requis
- Debian 11 ou plus requis

Expand Down
7 changes: 5 additions & 2 deletions plugin_info/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
"pip3": {
"wheel": {},
"requests": {},
"pybluez": {},
"setuptools": {
"version": "58.0.0"
},
"cryptography": {
"version": "38.0.0"
}
},
"pybluez": {}
},
"post-install": {
"script": "plugins/beagle/resources/post_install.sh"
Expand Down
32 changes: 15 additions & 17 deletions resources/beagled/beagled.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
import blescan
import subprocess
import sendadv
import _thread as thread
from threading import Thread

import bluetooth._bluetooth as bluez

from jeedom.jeedom import jeedom_socket, jeedom_utils, jeedom_com, JEEDOM_SOCKET_MESSAGE
import globals


def read_socket(name):
def read_socket():
while 1:
try:
if not JEEDOM_SOCKET_MESSAGE.empty():
Expand Down Expand Up @@ -76,7 +76,7 @@ def read_socket(name):
time.sleep(0.1)


def heartbeat_handler(delay):
def heartbeat_handler():
while 1:
if globals.LEARN_MODE and (globals.LEARN_BEGIN + 60) < int(time.time()):
globals.LEARN_MODE = False
Expand All @@ -88,17 +88,17 @@ def heartbeat_handler(delay):
def listen():
jeedom_socket.open()
try:
thread.start_new_thread(read_socket, ('socket',))
Thread(target=read_socket, daemon=True).start()
logging.debug('Read Socket Thread Launched')
thread.start_new_thread(ble_scan, ('scanner',))
Thread(target=ble_scan, daemon=True).start()
logging.debug('Ble Scanner Thread Launched')
thread.start_new_thread(heartbeat_handler, (19,))
Thread(target=heartbeat_handler, daemon=True).start()
logging.debug('Heartbeat Thread Launched')
except KeyboardInterrupt:
shutdown()


def ble_scan(name):
def ble_scan():
while not globals.READY:
time.sleep(1)
dev_id = globals.IFACE_DEVICE
Expand All @@ -110,7 +110,7 @@ def ble_scan(name):
while True:
blescan.parse_events(sock, 10)
except Exception as e:
print("Error accessing bluetooth device...: %s", e)
logging.error("Error accessing bluetooth device...: %s", e)
sys.exit(1)


Expand All @@ -134,7 +134,7 @@ def shutdown():
pass
logging.debug("Exit 0")
sys.stdout.flush()
os._exit(0)
sys.exit(0)

# ----------------------------------------------------------------------------

Expand All @@ -159,7 +159,6 @@ def shutdown():
parser.add_argument("--jeedomkey", help="Jeedom Key", type=str)
args = parser.parse_args()


if args.device:
_device = args.device
if args.socketport:
Expand All @@ -182,14 +181,13 @@ def shutdown():
jeedom_utils.set_log_level(_log_level)
logging.info('Start beagled')
logging.info('Log level : %s', _log_level)
logging.info('Socket port : %s', _socket_port)
logging.info('Socket host : %s', _sockethost)
logging.debug('Socket port : %s', _socket_port)
logging.debug('Socket host : %s', _sockethost)
logging.info('Device : %s', _device)
logging.info('PID file : %s', _pidfile)
logging.info('Apikey : %s', _apikey)
logging.info('Callback : %s', _callback)
logging.info('Cycle : %s', _cycle)
logging.info('JeedomKey : %s', globals.jeedomkey)
logging.debug('PID file : %s', _pidfile)
logging.debug('Callback : %s', _callback)
logging.debug('Cycle : %s', _cycle)
logging.debug('JeedomKey : %s', globals.jeedomkey)
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)
globals.IFACE_DEVICE = int(_device[-1:])
Expand Down
5 changes: 3 additions & 2 deletions resources/beagled/blescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import sys
import struct
import time
import bluetooth._bluetooth as bluez
import logging
from beagle import Beagle
Expand Down Expand Up @@ -126,7 +127,6 @@ def parse_events(sock, loop_count=100):
bluez.hci_filter_all_events(flt)
bluez.hci_filter_set_ptype(flt, bluez.HCI_EVENT_PKT)
sock.setsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, flt)
myFullList = []
for i in range(0, loop_count):
pkt = sock.recv(255)
ptype, event, plen = struct.unpack("BBB", pkt[:3])
Expand Down Expand Up @@ -161,6 +161,7 @@ def parse_events(sock, loop_count=100):
mac = packed_bdaddr_to_string(pkt[report_pkt_offset + 3:report_pkt_offset + 9])
Beagle(trame, mac).parse()
sock.setsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, old_filter)
time.sleep(0.1)
except Exception as e:
logging.debug("Exception in ble_scan : %s", e)
return myFullList
time.sleep(1)
15 changes: 8 additions & 7 deletions resources/post_install.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
cd "$(dirname "$0")"
SCRIPT_DIR="$(pwd)"

if [ -d "$SCRIPT_DIR/python_venv/bin" ]; then
echo "patch pybluez on debian >= 12"
sudo $SCRIPT_DIR/python_venv/bin/python3 -m pip install --force-reinstall --upgrade git+https://github.com/pybluez/pybluez.git#egg=pybluez
else
echo "patch pybluez on debian 11"
sudo pip3 install git+https://github.com/pybluez/pybluez.git#egg=pybluez
fi
# this version of pybluez (0.30) doesn't work on debian 11 but version 0.23 doesn't work on debian 12 => block on 0.23 for now
# if [ -d "$SCRIPT_DIR/python_venv/bin" ]; then
# echo "patch pybluez on debian >= 12"
# sudo $SCRIPT_DIR/python_venv/bin/python3 -m pip install --force-reinstall --upgrade git+https://github.com/pybluez/pybluez.git#egg=pybluez
# else
# echo "patch pybluez on debian 11"
# sudo pip3 install git+https://github.com/pybluez/pybluez.git#egg=pybluez
# fi

sudo rfkill unblock all >/dev/null 2>&1
sudo hciconfig hci0 up >/dev/null 2>&1
Expand Down

0 comments on commit 224909f

Please sign in to comment.