Hi,
I try to advertise nrf52840 dongle on pc to build a connection with nrf5340 uart service. Although I try to modify the advertising program by advertising.py and heart_rate_collector.py, I still can't succeed in notifying the uart handle. Here is my code, which results in 'cccd not found'.
class HRCollector(BLEDriverObserver, BLEAdapterObserver):
def __init__(self, adapter):
super(HRCollector, self).__init__()
self.adapter = adapter
self.conn_q = Queue()
self.adapter.observer_register(self)
self.adapter.driver.observer_register(self)
self.adapter.default_mtu = 250
from pc_ble_driver_py.ble_driver import BLEUUIDBase
self.nus_base = BLEUUIDBase([
0x6e, 0x40, 0x00, 0x00, 0xb5, 0xa3, 0xf3, 0x93, 0xe0, 0xa9, 0xe5, 0x0e, 0x24, 0xdc, 0xca, 0x9e
])
def open(self):
self.adapter.driver.open()
if config.__conn_ic_id__.upper() == "NRF51":
self.adapter.driver.ble_enable(
BLEEnableParams(
vs_uuid_count=1,
service_changed=0,
periph_conn_count=0,
central_conn_count=1,
central_sec_count=0,
)
)
elif config.__conn_ic_id__.upper() == "NRF52":
gatt_cfg = BLEConfigConnGatt()
gatt_cfg.att_mtu = self.adapter.default_mtu
gatt_cfg.tag = CFG_TAG
self.adapter.driver.ble_cfg_set(BLEConfig.conn_gatt, gatt_cfg)
self.adapter.driver.ble_enable()
self.adapter.driver.ble_vs_uuid_add(self.nus_base)
def connect_and_discover(self):
scan_duration = 20
adv_data = BLEAdvData(complete_local_name="nrf52840")
# adv_data = BLEAdvData(complete_local_name="pc_ble_driver_py")
self.adapter.driver.ble_gap_adv_data_set(adv_data)
self.adapter.driver.ble_gap_adv_start()
scan_duration = 60
try:
new_conn = self.conn_q.get(timeout=scan_duration)
self.adapter.enable_notification(
new_conn, BLEUUID(Uart_Tx_uuid), uart_tx_handle
)
return new_conn
except Empty:
print(f"No heart rate collector advertising with name {TARGET_DEV_NAME} found.")
return None
return None
def main(selected_serial_port):
print("Serial port used: {}".format(selected_serial_port))
driver = BLEDriver(
serial_port=selected_serial_port, auto_flash=False, baud_rate=1000000, log_severity_level="info"
)
observer = TimeoutObserver()
driver.observer_register(observer)
adapter = BLEAdapter(driver)
collector = HRCollector(adapter)
conn = collector.open()
collector.connect_and_discover()
observer.wait_for_timeout()
collector.close()
I find that the db_conns has empty service. Is this way to notify advertising device's handle not correct? Thank you for your help!
