简体   繁体   中英

How to repeat reading the value from the BLE device only when the value updated (python on MacOS)?

As title, now I can get values from the BLE device, as the following codes shown:

class RobotDelegate(object):
...

def peripheral_didDiscoverCharacteristicsForService_error_(self, peripheral, service, error):
for characteristic in self.service.characteristics():
   if characteristic.UUID() == blebee_characteristic:
        self.characteristic = characteristic
        print ("self.characteristic.value = ", self.characteristic.value())
...

delegate = RobotDelegate()
manager = CBCentralManager.alloc()
manager.initWithDelegate_queue_options_(delegate, None, None)

AppHelper.runConsoleEventLoop()

And I can read the value from my BLE device only one time... Actually, the BLE device can continuously update the value when someone touch, so I like to know how should I do to achieve this? Thanks.

I would recommend to use the Observer Pattern. An Example can be found here . In your case a BLE device would be a 'Subject' and notifies each time, when the value changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM