I am a python beginner, I read a lot of related questions, but they all ask us to look heart_rate_collector.py , but heart_rate_collector.py did't not have any example, i really don't understand how to used it.
I am a python beginner, I read a lot of related questions, but they all ask us to look heart_rate_collector.py , but heart_rate_collector.py did't not have any example, i really don't understand how to used it.
Hi,
The pc-ble-driver-py is a python wrapper for the pc-ble-driver, and the heart_rate_collector.py is the included example that demonstrate how to use it. In other words, heart_rate_collector.py is the example.
I did not understand the question other than that, though. What is it you are wondering about? As you mention on_notification, this is a function that is called whenever a notification is received, and it prints the connection handle, the UUID that got notified and the data that was notified (i.e. the received data).
How do I get notification from (uuid:0xfff6) and read data.
I think "on_notification" can only show the data what i gave it(hightlight).
on_notification(self, ble_adapter, conn_handle, uuid, data)
So my question is how to get the 'data'?
I have use "self.adapter.enable_notification(new_conn, self.nus_tx)"
Have you enabled notifications with enable_notification()? If not, you will not get any notifications, and on_notification() will never be called
I want to record the notify in 0XFFF6 like image below
but now I have enable notification(),still can't received the data.
I see from the log that you find that characteristic during service discovery. Then the next is to enable notifications using enable_notification with that UUID.
def connect_and_discover(self): scan_duration = 5 params = BLEGapScanParams(interval_ms=200, window_ms=150, timeout_s=scan_duration) message = "We are connected!\r\n" self.adapter.driver.ble_gap_scan_start(scan_params=params) try: new_conn = self.conn_q.get(timeout=scan_duration) self.adapter.service_discovery(new_conn) self.adapter.enable_notification(new_conn, self.nus_tx) return new_conn except Empty: print("No device advertising with name {TARGET_DEV_NAME} found.") return None
Yes ,I have enable notifications using enable_notification in the "def connect_and_discover(self):"
Is enable_notification() return anything? or how do I know this function is working?
Yes, it does return a status. You can see that from looking at the implementation. What is self.nus_tx? Is it the right UUID?
Yes, it does return a status. You can see that from looking at the implementation. What is self.nus_tx? Is it the right UUID?
def __init__(self, adapter): super(NusCollector, self).__init__() self.first = 1 self.adapter = adapter self.conn_q = Queue() self.adapter.observer_register(self) self.adapter.driver.observer_register(self) self.adapter.default_mtu = 247 self.nus_base = BLEUUIDBase([ 0x00, 0x00, 0xff, 0xf0, 0x00 ,0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb ]) self.nus_tx = BLEUUID(0xfff6, self.nus_base)
self.nus_tx is the UUID of 0XFFF6 which is the notify one
Is the UUID Base right? In the screenshot it looks like you are using only 16 bit UUIDs, but here you are adding a base (which is probably what you should do as this is a custom service). But in any case, in order to work, this needs to match.
Hello is there anything I can do for it?
I don't immediately see an issue here. I suggest you take a look at this post, which includes a working script that use NUS, and enables notifications (obviously you need to change the UUID and UUID base for your custom service).