From 38b15816b41af5aa4ca89a055f535e2a89208272 Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Fri, 20 Nov 2020 12:13:15 +0530 Subject: [PATCH] ci: Fix blecent example test (cherry picked from commit fc146a98e403b51f8691d6be077624479dc893d4) --- .../bluetooth/nimble/blecent/blecent_test.py | 16 +- tools/ble/lib_ble_client.py | 342 ++++++++++-------- 2 files changed, 209 insertions(+), 149 deletions(-) diff --git a/examples/bluetooth/nimble/blecent/blecent_test.py b/examples/bluetooth/nimble/blecent/blecent_test.py index 9a85afc06a..b409bb981a 100644 --- a/examples/bluetooth/nimble/blecent/blecent_test.py +++ b/examples/bluetooth/nimble/blecent/blecent_test.py @@ -87,21 +87,21 @@ def test_example_app_ble_central(env, extra_data): ble_client_obj.disconnect() # Check dut responses - dut.expect("Connection established", timeout=30) + dut.expect("Connection established", timeout=60) - dut.expect("Service discovery complete; status=0", timeout=30) + dut.expect("Service discovery complete; status=0", timeout=60) print("Service discovery passed\n\tService Discovery Status: 0") - dut.expect("GATT procedure initiated: read;", timeout=30) - dut.expect("Read complete; status=0", timeout=30) + dut.expect("GATT procedure initiated: read;", timeout=60) + dut.expect("Read complete; status=0", timeout=60) print("Read passed\n\tSupportedNewAlertCategoryCharacteristic\n\tRead Status: 0") - dut.expect("GATT procedure initiated: write;", timeout=30) - dut.expect("Write complete; status=0", timeout=30) + dut.expect("GATT procedure initiated: write;", timeout=60) + dut.expect("Write complete; status=0", timeout=60) print("Write passed\n\tAlertNotificationControlPointCharacteristic\n\tWrite Status: 0") - dut.expect("GATT procedure initiated: write;", timeout=30) - dut.expect("Subscribe complete; status=0", timeout=30) + dut.expect("GATT procedure initiated: write;", timeout=60) + dut.expect("Subscribe complete; status=0", timeout=60) print("Subscribe passed\n\tClientCharacteristicConfigurationDescriptor\n\tSubscribe Status: 0") diff --git a/tools/ble/lib_ble_client.py b/tools/ble/lib_ble_client.py index 708bd42ba1..73be5187fb 100644 --- a/tools/ble/lib_ble_client.py +++ b/tools/ble/lib_ble_client.py @@ -42,26 +42,33 @@ srv_added_old_cnt = 0 srv_added_new_cnt = 0 verify_signal_check = 0 blecent_retry_check_cnt = 0 +gatt_app_retry_check_cnt = 0 verify_service_cnt = 0 verify_readchars_cnt = 0 +adv_retry_check_cnt = 0 blecent_adv_uuid = '1811' gatt_app_obj_check = False gatt_app_reg_check = False +adv_checks_done = False +gatt_checks_done = False adv_data_check = False adv_reg_check = False read_req_check = False write_req_check = False subscribe_req_check = False ble_hr_chrc = False - -DISCOVERY_START = False -SIGNAL_CAUGHT = False - -TEST_CHECKS_PASS = False -ADV_STOP = False - -SERVICES_RESOLVED = False -SERVICE_UUID_FOUND = False +discovery_start = False +signal_caught = False +test_checks_pass = False +adv_stop = False +services_resolved = False +service_uuid_found = False +adapter_on = False +device_connected = False +gatt_app_registered = False +adv_registered = False +adv_active_instance = False +chrc_value_cnt = False BLUEZ_SERVICE_NAME = 'org.bluez' DBUS_OM_IFACE = 'org.freedesktop.DBus.ObjectManager' @@ -76,13 +83,6 @@ LE_ADVERTISING_MANAGER_IFACE = 'org.bluez.LEAdvertisingManager1' GATT_SERVICE_IFACE = 'org.bluez.GattService1' GATT_CHRC_IFACE = 'org.bluez.GattCharacteristic1' -ADAPTER_ON = False -DEVICE_CONNECTED = False -GATT_APP_REGISTERED = False -ADV_REGISTERED = False -ADV_ACTIVE_INSTANCE = False - -CHRC_VALUE_CNT = False # Set up the main loop. dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) @@ -95,7 +95,7 @@ def verify_signal_is_caught(): global verify_signal_check verify_signal_check += 1 - if (not SIGNAL_CAUGHT and verify_signal_check == 15) or (SIGNAL_CAUGHT): + if (not signal_caught and verify_signal_check == 15) or (signal_caught): if event_loop.is_running(): event_loop.quit() return False # polling for checks will stop @@ -107,25 +107,25 @@ def set_props_status(props): """ Set Adapter status if it is powered on or off """ - global ADAPTER_ON, SERVICES_RESOLVED, GATT_OBJ_REMOVED, GATT_APP_REGISTERED, \ - ADV_REGISTERED, ADV_ACTIVE_INSTANCE, DEVICE_CONNECTED, CHRC_VALUE, CHRC_VALUE_CNT, \ - SIGNAL_CAUGHT + global adapter_on, services_resolved, GATT_OBJ_REMOVED, gatt_app_registered, \ + adv_registered, adv_active_instance, device_connected, CHRC_VALUE, chrc_value_cnt, \ + signal_caught is_service_uuid = False # Signal caught for change in Adapter Powered property if 'Powered' in props: if props['Powered'] == 1: - SIGNAL_CAUGHT = True - ADAPTER_ON = True + signal_caught = True + adapter_on = True else: - SIGNAL_CAUGHT = True - ADAPTER_ON = False + signal_caught = True + adapter_on = False if 'ServicesResolved' in props: if props['ServicesResolved'] == 1: - SIGNAL_CAUGHT = True - SERVICES_RESOLVED = True + signal_caught = True + services_resolved = True else: - SIGNAL_CAUGHT = True - SERVICES_RESOLVED = False + signal_caught = True + services_resolved = False if 'UUIDs' in props: # Signal caught for add/remove GATT data having service uuid for uuid in props['UUIDs']: @@ -134,31 +134,31 @@ def set_props_status(props): if not is_service_uuid: # Signal caught for removing GATT data having service uuid # and for unregistering GATT application - GATT_APP_REGISTERED = False + gatt_app_registered = False lib_gatt.GATT_APP_OBJ = False if 'ActiveInstances' in props: # Signal caught for Advertising - add/remove Instances property if props['ActiveInstances'] == 1: - ADV_ACTIVE_INSTANCE = True + adv_active_instance = True elif props['ActiveInstances'] == 0: - ADV_ACTIVE_INSTANCE = False - ADV_REGISTERED = False + adv_active_instance = False + adv_registered = False lib_gap.ADV_OBJ = False if 'Connected' in props: # Signal caught for device connect/disconnect if props['Connected'] == 1: - SIGNAL_CAUGHT = True - DEVICE_CONNECTED = True + signal_caught = True + device_connected = True else: - SIGNAL_CAUGHT = True - DEVICE_CONNECTED = False + signal_caught = True + device_connected = False if 'Value' in props: # Signal caught for change in chars value if ble_hr_chrc: - CHRC_VALUE_CNT += 1 + chrc_value_cnt += 1 print(props['Value']) - if CHRC_VALUE_CNT == 10: - SIGNAL_CAUGHT = True + if chrc_value_cnt == 10: + signal_caught = True return False return False @@ -216,9 +216,9 @@ class BLE_Bluez_Client: Discover Bluetooth Adapter Power On Bluetooth Adapter ''' - global verify_signal_check, SIGNAL_CAUGHT, ADAPTER_ON + global verify_signal_check, signal_caught, adapter_on verify_signal_check = 0 - ADAPTER_ON = False + adapter_on = False try: print("discovering adapter...") for path, interfaces in self.ble_objs.items(): @@ -242,7 +242,7 @@ class BLE_Bluez_Client: print("bluetooth adapter discovered") # Check if adapter is already powered on - if ADAPTER_ON: + if adapter_on: print("Adapter already powered on") return True @@ -251,11 +251,11 @@ class BLE_Bluez_Client: self.props_iface_obj.connect_to_signal('PropertiesChanged', props_change_handler) self.props_iface_obj.Set(ADAPTER_IFACE, "Powered", dbus.Boolean(1)) - SIGNAL_CAUGHT = False + signal_caught = False GLib.timeout_add_seconds(5, verify_signal_is_caught) event_loop.run() - if ADAPTER_ON: + if adapter_on: print("bluetooth adapter powered on") return True else: @@ -270,14 +270,14 @@ class BLE_Bluez_Client: Connect to the device discovered Retry 10 times to discover and connect to device ''' - global DISCOVERY_START, SIGNAL_CAUGHT, DEVICE_CONNECTED, verify_signal_check + global discovery_start, signal_caught, device_connected, verify_signal_check device_found = False - DEVICE_CONNECTED = False + device_connected = False try: self.adapter.StartDiscovery() print("\nStarted Discovery") - DISCOVERY_START = True + discovery_start = True for retry_cnt in range(10,0,-1): verify_signal_check = 0 @@ -290,10 +290,10 @@ class BLE_Bluez_Client: if device_found: self.device.Connect(dbus_interface=DEVICE_IFACE) time.sleep(15) - SIGNAL_CAUGHT = False + signal_caught = False GLib.timeout_add_seconds(5, verify_signal_is_caught) event_loop.run() - if DEVICE_CONNECTED: + if device_connected: print("\nConnected to device") return True else: @@ -356,21 +356,21 @@ class BLE_Bluez_Client: ''' Verify service uuid found ''' - global SERVICE_UUID_FOUND + global service_uuid_found srv_uuid_found = [uuid for uuid in self.srv_uuid if service_uuid in uuid] if srv_uuid_found: - SERVICE_UUID_FOUND = True + service_uuid_found = True def get_services(self, service_uuid=None): ''' Retrieve Services found in the device connected ''' - global SIGNAL_CAUGHT, SERVICE_UUID_FOUND, SERVICES_RESOLVED, verify_signal_check + global signal_caught, service_uuid_found, services_resolved, verify_signal_check verify_signal_check = 0 - SERVICE_UUID_FOUND = False - SERVICES_RESOLVED = False - SIGNAL_CAUGHT = False + service_uuid_found = False + services_resolved = False + signal_caught = False try: om_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, "/"), DBUS_OM_IFACE) @@ -382,12 +382,12 @@ class BLE_Bluez_Client: GLib.timeout_add_seconds(5, verify_signal_is_caught) om_iface_obj.connect_to_signal('InterfacesAdded', self.srvc_iface_added_handler) event_loop.run() - if not SERVICES_RESOLVED: + if not services_resolved: raise Exception("Services not found...") if service_uuid: self.verify_service_uuid_found(service_uuid) - if not SERVICE_UUID_FOUND: + if not service_uuid_found: raise Exception("Service with uuid: %s not found..." % service_uuid) # Services found @@ -400,7 +400,7 @@ class BLE_Bluez_Client: ''' Add services found as lib_ble_client obj ''' - global chrc, chrc_discovered, SIGNAL_CAUGHT + global chrc, chrc_discovered, signal_caught chrc_val = None if self.device and path.startswith(self.device.object_path): @@ -413,17 +413,17 @@ class BLE_Bluez_Client: chrc_val = chrc.ReadValue({}, dbus_interface=GATT_CHRC_IFACE) uuid = chrc_props['UUID'] self.chars[path] = chrc_val, chrc_flags, uuid - SIGNAL_CAUGHT = True + signal_caught = True def read_chars(self): ''' Read characteristics found in the device connected ''' - global iface_added, chrc_discovered, SIGNAL_CAUGHT, verify_signal_check + global iface_added, chrc_discovered, signal_caught, verify_signal_check verify_signal_check = 0 chrc_discovered = False iface_added = False - SIGNAL_CAUGHT = False + signal_caught = False try: om_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, "/"), DBUS_OM_IFACE) @@ -479,7 +479,7 @@ class BLE_Bluez_Client: Retrieve updated value Stop Notifications ''' - global ble_hr_chrc, verify_signal_check, SIGNAL_CAUGHT, CHRC_VALUE_CNT + global ble_hr_chrc, verify_signal_check, signal_caught, chrc_value_cnt srv_path = None chrc = None @@ -487,7 +487,7 @@ class BLE_Bluez_Client: chrc_path = None chars_ret = None ble_hr_chrc = True - CHRC_VALUE_CNT = 0 + chrc_value_cnt = 0 try: # Get HR Measurement characteristic @@ -518,7 +518,7 @@ class BLE_Bluez_Client: chrc_props_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, chrc_path), DBUS_PROP_IFACE) chrc_props_iface_obj.connect_to_signal('PropertiesChanged', props_change_handler) - SIGNAL_CAUGHT = False + signal_caught = False verify_signal_check = 0 GLib.timeout_add_seconds(5, verify_signal_is_caught) event_loop.run() @@ -533,16 +533,16 @@ class BLE_Bluez_Client: print(traceback.format_exc()) return False - def create_gatt_app(self): + def create_and_reg_gatt_app(self): ''' Create GATT data Register GATT Application ''' - global gatt_app_obj, gatt_manager_iface_obj, GATT_APP_REGISTERED + global gatt_app_obj, gatt_manager_iface_obj, gatt_app_registered gatt_app_obj = None gatt_manager_iface_obj = None - GATT_APP_REGISTERED = False + gatt_app_registered = False lib_gatt.GATT_APP_OBJ = False try: @@ -561,15 +561,15 @@ class BLE_Bluez_Client: ''' GATT Application Register success handler ''' - global GATT_APP_REGISTERED - GATT_APP_REGISTERED = True + global gatt_app_registered + gatt_app_registered = True def gatt_app_error_handler(self, error): ''' GATT Application Register error handler ''' - global GATT_APP_REGISTERED - GATT_APP_REGISTERED = False + global gatt_app_registered + gatt_app_registered = False def start_advertising(self, adv_host_name, adv_iface_index, adv_type, adv_uuid): ''' @@ -577,28 +577,47 @@ class BLE_Bluez_Client: Register Advertisement Start Advertising ''' - global le_adv_obj, le_adv_manager_iface_obj, ADV_ACTIVE_INSTANCE, ADV_REGISTERED + global le_adv_obj, le_adv_manager_iface_obj, adv_active_instance, adv_registered le_adv_obj = None le_adv_manager_iface_obj = None le_adv_iface_path = None - ADV_ACTIVE_INSTANCE = False - ADV_REGISTERED = False + adv_active_instance = False + adv_registered = False lib_gap.ADV_OBJ = False try: print("Advertising started") - gatt_app_ret = self.create_gatt_app() + gatt_app_ret = self.create_and_reg_gatt_app() - if not gatt_app_ret: - raise Exception + # Check if gatt app create and register command + # is sent successfully + assert gatt_app_ret + + GLib.timeout_add_seconds(2, self.verify_gatt_app_reg) + event_loop.run() + + # Check if Gatt Application is registered + assert gatt_app_registered for path,interface in self.ble_objs.items(): if LE_ADVERTISING_MANAGER_IFACE in interface: le_adv_iface_path = path - if le_adv_iface_path is None: - raise Exception('\n Cannot start advertising. LEAdvertisingManager1 Interface not found') + # Check LEAdvertisingManager1 interface is found + assert le_adv_iface_path, '\n Cannot start advertising. LEAdvertisingManager1 Interface not found' + + # Get device when connected + if not self.device: + om_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, "/"), DBUS_OM_IFACE) + self.ble_objs = om_iface_obj.GetManagedObjects() + + for path, interfaces in self.ble_objs.items(): + if DEVICE_IFACE not in interfaces.keys(): + continue + device_props_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, path), DBUS_PROP_IFACE) + device_props_iface_obj.connect_to_signal('PropertiesChanged', props_change_handler) + self.device = self.bus.get_object(BLUEZ_SERVICE_NAME, path) le_adv_obj = lib_gap.Advertisement(self.bus, adv_iface_index, adv_type, adv_uuid, adv_host_name) le_adv_manager_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, le_adv_iface_path), LE_ADVERTISING_MANAGER_IFACE) @@ -607,13 +626,30 @@ class BLE_Bluez_Client: reply_handler=self.adv_handler, error_handler=self.adv_error_handler) + GLib.timeout_add_seconds(2, self.verify_adv_reg) + event_loop.run() + + # Check if advertising is registered + assert adv_registered + + ret_val = self.verify_blecent_app() + + # Check if blecent has passed + assert ret_val + + except Exception: + print(traceback.format_exc()) + return False + + def verify_blecent_app(self): + ''' + Verify read/write/subscribe operations + ''' + try: GLib.timeout_add_seconds(2, self.verify_blecent) event_loop.run() - if TEST_CHECKS_PASS: - return True - else: - raise Exception + return test_checks_pass except Exception: print(traceback.format_exc()) @@ -623,47 +659,83 @@ class BLE_Bluez_Client: ''' Advertisement Register success handler ''' - global ADV_REGISTERED - ADV_REGISTERED = True + global adv_registered + adv_registered = True def adv_error_handler(self, error): ''' Advertisement Register error handler ''' - global ADV_REGISTERED - ADV_REGISTERED = False + global adv_registered + adv_registered = False + + def verify_gatt_app_reg(self): + """ + Verify GATT Application is registered + """ + global gatt_app_retry_check_cnt, gatt_checks_done + gatt_app_retry_check_cnt = 0 + gatt_checks_done = False + + # Check for success + if lib_gatt.GATT_APP_OBJ: + print("GATT Data created") + if gatt_app_registered: + print("GATT Application registered") + gatt_checks_done = True + if gatt_app_retry_check_cnt == 20: + if not gatt_app_registered: + print("Failure: GATT Application could not be registered") + gatt_checks_done = True + + # End polling if app is registered or cnt has reached 10 + if gatt_checks_done: + if event_loop.is_running(): + event_loop.quit() + return False # polling for checks will stop + + gatt_app_retry_check_cnt += 1 + # Default return True - polling for checks will continue + return True + + def verify_adv_reg(self): + """ + Verify Advertisement is registered + """ + global adv_retry_check_cnt, adv_checks_done + adv_retry_check_cnt = 0 + adv_checks_done = False + + if lib_gap.ADV_OBJ: + print("Advertising data created") + if adv_registered or adv_active_instance: + print("Advertisement registered") + adv_checks_done = True + if adv_retry_check_cnt == 10: + if not adv_registered and not adv_active_instance: + print("Failure: Advertisement could not be registered") + adv_checks_done = True + + # End polling if success or cnt has reached 10 + if adv_checks_done: + if event_loop.is_running(): + event_loop.quit() + return False # polling for checks will stop + + adv_retry_check_cnt += 1 + # Default return True - polling for checks will continue + return True def verify_blecent(self): """ Verify blecent test commands are successful """ - global blecent_retry_check_cnt, gatt_app_obj_check, gatt_app_reg_check,\ - adv_data_check, adv_reg_check, read_req_check, write_req_check,\ - subscribe_req_check, TEST_CHECKS_PASS - - # Get device when connected - if not self.device: - om_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, "/"), DBUS_OM_IFACE) - self.ble_objs = om_iface_obj.GetManagedObjects() - - for path, interfaces in self.ble_objs.items(): - if DEVICE_IFACE not in interfaces.keys(): - continue - device_props_iface_obj = dbus.Interface(self.bus.get_object(BLUEZ_SERVICE_NAME, path), DBUS_PROP_IFACE) - device_props_iface_obj.connect_to_signal('PropertiesChanged', props_change_handler) - self.device = self.bus.get_object(BLUEZ_SERVICE_NAME, path) + global blecent_retry_check_cnt, read_req_check, write_req_check,\ + subscribe_req_check, test_checks_pass # Check for failures after 10 retries if blecent_retry_check_cnt == 10: # check for failures - if not gatt_app_obj_check: - print("Failure: GATT Data could not be created") - if not gatt_app_reg_check: - print("Failure: GATT Application could not be registered") - if not adv_data_check: - print("Failure: Advertising data could not be created") - if not adv_reg_check: - print("Failure: Advertisement could not be registered") if not read_req_check: print("Failure: Read Request not received") if not write_req_check: @@ -672,23 +744,11 @@ class BLE_Bluez_Client: print("Failure: Subscribe Request not received") # Blecent Test failed - TEST_CHECKS_PASS = False + test_checks_pass = False if subscribe_req_check: lib_gatt.alert_status_char_obj.StopNotify() else: # Check for success - if not gatt_app_obj_check and lib_gatt.GATT_APP_OBJ: - print("GATT Data created") - gatt_app_obj_check = True - if not gatt_app_reg_check and GATT_APP_REGISTERED: - print("GATT Application registered") - gatt_app_reg_check = True - if not adv_data_check and lib_gap.ADV_OBJ: - print("Advertising data created") - adv_data_check = True - if not adv_reg_check and ADV_REGISTERED and ADV_ACTIVE_INSTANCE: - print("Advertisement registered") - adv_reg_check = True if not read_req_check and lib_gatt.CHAR_READ: read_req_check = True if not write_req_check and lib_gatt.CHAR_WRITE: @@ -699,10 +759,10 @@ class BLE_Bluez_Client: if read_req_check and write_req_check and subscribe_req_check: # all checks passed # Blecent Test passed - TEST_CHECKS_PASS = True + test_checks_pass = True lib_gatt.alert_status_char_obj.StopNotify() - if (blecent_retry_check_cnt == 10 or TEST_CHECKS_PASS): + if (blecent_retry_check_cnt == 10 or test_checks_pass): if event_loop.is_running(): event_loop.quit() return False # polling for checks will stop @@ -718,7 +778,7 @@ class BLE_Bluez_Client: Verify cleanup is successful """ global blecent_retry_check_cnt, gatt_app_obj_check, gatt_app_reg_check,\ - adv_data_check, adv_reg_check, ADV_STOP + adv_data_check, adv_reg_check, adv_stop if blecent_retry_check_cnt == 0: gatt_app_obj_check = False @@ -739,24 +799,24 @@ class BLE_Bluez_Client: print("Warning: Advertisement could not be unregistered") # Blecent Test failed - ADV_STOP = False + adv_stop = False else: # Check for success if not gatt_app_obj_check and not lib_gatt.GATT_APP_OBJ: print("GATT Data removed") gatt_app_obj_check = True - if not gatt_app_reg_check and not GATT_APP_REGISTERED: + if not gatt_app_reg_check and not gatt_app_registered: print("GATT Application unregistered") gatt_app_reg_check = True - if not adv_data_check and not adv_reg_check and not (ADV_REGISTERED or ADV_ACTIVE_INSTANCE or lib_gap.ADV_OBJ): + if not adv_data_check and not adv_reg_check and not (adv_registered or adv_active_instance or lib_gap.ADV_OBJ): print("Advertising data removed") print("Advertisement unregistered") adv_data_check = True adv_reg_check = True # all checks passed - ADV_STOP = True + adv_stop = True - if (blecent_retry_check_cnt == 10 or ADV_STOP): + if (blecent_retry_check_cnt == 10 or adv_stop): if event_loop.is_running(): event_loop.quit() return False # polling for checks will stop @@ -778,7 +838,7 @@ class BLE_Bluez_Client: Adapter is powered off ''' try: - global blecent_retry_check_cnt, DISCOVERY_START, verify_signal_check, SIGNAL_CAUGHT + global blecent_retry_check_cnt, discovery_start, verify_signal_check, signal_caught blecent_retry_check_cnt = 0 verify_signal_check = 0 @@ -786,14 +846,14 @@ class BLE_Bluez_Client: self.props_iface_obj.connect_to_signal('PropertiesChanged', props_change_handler) - if ADV_REGISTERED: + if adv_registered: # Unregister Advertisement le_adv_manager_iface_obj.UnregisterAdvertisement(le_adv_obj.get_path()) # Remove Advertising data dbus.service.Object.remove_from_connection(le_adv_obj) - if GATT_APP_REGISTERED: + if gatt_app_registered: # Unregister GATT Application gatt_manager_iface_obj.UnregisterApplication(gatt_app_obj.get_path()) @@ -803,10 +863,10 @@ class BLE_Bluez_Client: GLib.timeout_add_seconds(5, self.verify_blecent_disconnect) event_loop.run() - if ADV_STOP: - print("Stop Advertising status: ", ADV_STOP) + if adv_stop: + print("Stop Advertising status: ", adv_stop) else: - print("Warning: Stop Advertising status: ", ADV_STOP) + print("Warning: Stop Advertising status: ", adv_stop) # Disconnect device if self.device: @@ -815,16 +875,16 @@ class BLE_Bluez_Client: if self.adapter: self.adapter.RemoveDevice(self.device) self.device = None - if DISCOVERY_START: + if discovery_start: self.adapter.StopDiscovery() - DISCOVERY_START = False + discovery_start = False time.sleep(15) - SIGNAL_CAUGHT = False + signal_caught = False GLib.timeout_add_seconds(5, verify_signal_is_caught) event_loop.run() - if not DEVICE_CONNECTED: + if not device_connected: print("device disconnected") else: print("Warning: device could not be disconnected")