Problems calling a function from a class
When I try to use the sendData function, I get an error stating that nonObject has write_characteristic_value.
class bellRinger (object): def __init__(self): self.peripheral = None self.characteristic = None def did_discover_peripheral(self, p): if p.name and 'School Bell' in p.name and not self.peripheral: #Change Name Here self.peripheral = p peripheral = p cb.connect_peripheral(p) def did_connect_peripheral(self, p): p.discover_services() def did_fail_to_connect_peripheral(self, p, error): print('Failed to Connect') def did_disconnect_peripheral(self, p, error): self.peripheral = None def did_discover_services(self, p, error): for s in p.services: if s.uuid == 'FFE0': p.discover_characteristics(s) def did_discover_characteristics(self, s, error): for c in s.characteristics: if c.uuid == 'FFE1': self.characteristic = c characteristic = c self.peripheral.set_notify_value(c, True) def did_update_value(self, c, error): print('Got Something',c.value) def sendData(): c = self.characteristic self.peripheral.write_characteristic_value(c, 'ring/', True) mngr = bellRinger() cb.set_central_delegate(mngr) cb.scan_for_peripherals() mngr.sendData()
Strangely enough it does work if called from a button action....
JonB last edited by
not strange at all -- you are calling sendData before the characteristic has been discovered.
You may want to have
while mngr.characteristic is None: time.sleep(1) mngr.sendData()