diff --git a/Bluetooth_LE_beacon/dbus/uxplay-beacon.1 b/Bluetooth_LE_beacon/dbus/uxplay-beacon.1 index 2655abf..34a514a 100644 --- a/Bluetooth_LE_beacon/dbus/uxplay-beacon.1 +++ b/Bluetooth_LE_beacon/dbus/uxplay-beacon.1 @@ -9,7 +9,7 @@ UxPlay 1.72: Standalone Python Script for Bluetooth LE Service Discovery (DBus). .SH OPTIONS .TP .B -\fB\--file\fR fn Specify alternate configuration file +\fB\--file\fR fn Specify configuration file (default: ~/.uxplay.beacon) .TP \fB\--path\fR fn Specify non-default Bluetooth LE data file used by uxplay .TP @@ -24,11 +24,9 @@ UxPlay 1.72: Standalone Python Script for Bluetooth LE Service Discovery (DBus). \fB \-h, --help\fR Show help text. .SH FILES -Options in beacon configuration file ~/.uxplay.beacon +Options in configuration file are applied first (command-line options may modify them). .TP -are applied first (command-line options may modify them). Format: -.TP -one option per line, with initial "--"; lines beginning with "#" ignored. +Format: one option per line, with initial "--"; lines beginning with "#" ignored. .SH AUTHORS .TP diff --git a/Bluetooth_LE_beacon/dbus/uxplay-beacon.py b/Bluetooth_LE_beacon/dbus/uxplay-beacon.py index 865c1ee..7f38db2 100644 --- a/Bluetooth_LE_beacon/dbus/uxplay-beacon.py +++ b/Bluetooth_LE_beacon/dbus/uxplay-beacon.py @@ -19,7 +19,8 @@ import dbus.service ad_manager = None airplay_advertisement = None -server_address = None +advertised_port = None +advertised_address = None BLUEZ_SERVICE_NAME = 'org.bluez' LE_ADVERTISING_MANAGER_IFACE = 'org.bluez.LEAdvertisingManager1' @@ -125,15 +126,17 @@ class AirPlayAdvertisement(AirPlay_Service_Discovery_Advertisement): def register_ad_cb(): - global server_address - print(f'AirPlay Service_Discovery Advertisement ({server_address}) registered') + print(f'AirPlay Service_Discovery Advertisement ({advertised_address}:{advertised_port}) registered') def register_ad_error_cb(error): print(f'Failed to register advertisement: {error}') global ad_manager + global advertised_port + global advertised_address ad_manager = None - + advertised_port = None + advertised_address = None def find_adapter(bus): remote_om = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, '/'), @@ -150,8 +153,9 @@ def find_adapter(bus): def setup_beacon(ipv4_str, port, advmin, advmax, index): global ad_manager global airplay_advertisement - global server_address - server_address = f"{ipv4_str}:{port}" + global advertised_address + advertised_port = port + advertised_address = ipv4_str dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) bus = dbus.SystemBus() adapter = find_adapter(bus) @@ -168,7 +172,6 @@ def setup_beacon(ipv4_str, port, advmin, advmax, index): airplay_advertisement = AirPlayAdvertisement(bus, index, ipv4_str, port, advmin, advmax) def beacon_on(): - global ad_manager global airplay_advertisement ad_manager.RegisterAdvertisement(airplay_advertisement.get_path(), {}, reply_handler=register_ad_cb, @@ -182,14 +185,25 @@ def beacon_on(): def beacon_off(): global ad_manager global airplay_advertisement + global advertised_port + global advertised_address ad_manager.UnregisterAdvertisement(airplay_advertisement) print(f'AirPlay Service-Discovery beacon advertisement unregistered') ad_manager = None dbus.service.Object.remove_from_connection(airplay_advertisement) airplay_advertisement = None - + advertised_Port = None + advertised_address = None + + #==generic code (non-dbus) below here ============= +def check_port(port): + if advertised_port is None or port == advertised_port: + return True + else: + return False + import argparse import os import sys @@ -238,7 +252,6 @@ def check_process_name(pid, pname): return False def check_pending(): - global beacon_is_running global beacon_is_pending_on global beacon_is_pending_off if beacon_is_running: @@ -254,38 +267,50 @@ def check_pending(): def check_file_exists(file_path): global port - global beacon_is_running global beacon_is_pending_on global beacon_is_pending_off - - if os.path.exists(file_path): - with open(file_path, 'rb') as file: - data = file.read(2) - port = struct.unpack('