omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Problems calling a function from a class

    Pythonista
    2
    4
    2330
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • robertiii
      robertiii last edited by

      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()
      
      1 Reply Last reply Reply Quote 0
      • robertiii
        robertiii last edited by

        Strangely enough it does work if called from a button action....

        1 Reply Last reply Reply Quote 0
        • JonB
          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()
          
          1 Reply Last reply Reply Quote 0
          • robertiii
            robertiii last edited by

            Thank you!!!!!!!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors