Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Bluetooth services is not started

    Scheduled Pinned Locked Moved Pymakr
    bluetoothserviceslopynot started
    15 Posts 4 Posters 3.0k Views 4 Watching
    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.
    • L Offline
      livius @Nagarjuna Reddy
      last edited by

      @nagarjuna-reddy
      you removed it before loop but better here if you remove it from loop
      only connect before (you have only one disconnect)

      think about people first, then computers

      Nagarjuna ReddyN 1 Reply Last reply Reply Quote 0
      • S Offline
        st3ty
        last edited by

        I have the exact same problem.

        I am trying to connect two Wipys via bluetooth.
        I get the connection on both sides.
        But the programm frezzes with the line services = connection.services()

        Is this a bug or is it a problem with my code?

        from network import Bluetooth
        import binascii
        
        bluetooth = Bluetooth()
        
        bluetooth.start_scan(-1)
        
        adv = None
        
        while True:
        
        
            adv = bluetooth.get_adv()
        
            if adv and bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'WiPy':
        
                if bluetooth.isscanning():
                    bluetooth.stop_scan()
        
                try:
        
                    connection = bluetooth.connect(adv.mac)
        
                    while not connection.isconnected():
                        pass
        
                    if connection.isconnected():
        
                        print("Connected to device with addr = {}".format( binascii.hexlify( adv.mac ) ) )
                        print("and name = ", bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL))
                        break
        
                except:
                    # start scanning again
                    bluetooth.start_scan(-1)
                    continue
        
        print('test1')
        services = connection.services()
        print('test2')
        
        Nagarjuna ReddyN 1 Reply Last reply Reply Quote 0
        • Nagarjuna ReddyN Offline
          Nagarjuna Reddy @livius
          last edited by

          @livius
          i cannot understand livius so edit my code and send to me please........

          Ch.nagarjuna reddy

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @Nagarjuna Reddy
            last edited by

            i only mean that you must connect only once and for one connect you need one disconnect
            below "fixed" code in this matter
            i have also added small sleep time - look if it help somehow with your problem (i do not tested this self)

            def ble_reciever(self):
            		bluetooth = Bluetooth()
            		print("Scanning 4509 client")
            		bluetooth.start_scan(-1)
            
            		while True:
            			adv = bluetooth.get_adv()
            			#if adv:
            				#print("Found adv in 4509 client")
            				# try to get the complete name
            				#print(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL))
            
            				# try to get the manufacturer data (Apple's iBeacon data is sent here)
            				#print(binascii.hexlify(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_MANUFACTURER_DATA)))
            
            
            			if adv and bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'LoPy':
            				print("connecting rr Lopy in 4509 client")					
            				conn = bluetooth.connect(adv.mac)					
            				print("connected Lopy in 4509 client")  	
            				
            				services = conn.services()				 
            				for service in services:
            					time.sleep(0.050)
            					print("start reading..")
            					if type(service.uuid()) == bytes:
            						print('Reading chars from service = {}'.format(service.uuid()))
            					else:
            						print('Reading chars from service = %x' % service.uuid())
            					chars = service.characteristics()
            					for char in chars:
            						if (char.properties() & Bluetooth.PROP_READ):
            							print('char {} value = {}'.format(char.uuid(), char.read()))
            							
            				conn.disconnect()
            				print("Disconnected 4509 client")
            				break
            			else:
            				time.sleep(0.050)
            
            	def ble_transmitter(self):
            
            		print('Advertising Bluetooth...')
            		bluetooth = Bluetooth()
            		bluetooth.set_advertisement(name='LoPy', service_uuid=b'1234567890abcdef')
            
            		def conn_cb (bt_o):
            			events = bt_o.events()
            			if  events & Bluetooth.CLIENT_CONNECTED:
            				print("Client connected")
            			elif events & Bluetooth.CLIENT_DISCONNECTED:
            				print("Client disconnected")
            
            		bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb)
            		bluetooth.advertise(True)
            
            		#Create service and characteristic
            		srv1 = bluetooth.service(uuid='0000000000000000', isprimary=True)
            		chr1 = srv1.characteristic(uuid='0000000000000002', properties=Bluetooth.PROP_INDICATE | Bluetooth.PROP_BROADCAST | Bluetooth.PROP_READ | Bluetooth.PROP_NOTIFY, value='InitialValue')
            
            		#Create callback for read events on the characteristic
            		def char1_cb(chr):
            			events = chr.events()
            			if events & Bluetooth.CHAR_READ_EVENT :
            				print('Bluetooth.CHAR_READ_EVENT')
            
            		chr1.callback(trigger=Bluetooth.CHAR_READ_EVENT, handler=char1_cb)
            
            		#Update the characteristic value very few seconds
            		#i=0
            		while True:
            			val = 'Value{}'.format(i)
            			print('Setting value: {}'.format(val))
            			chr1.value(val) #Set the characteristic value - should trigger notification is a client has registered for notifications
            			time.sleep(3)
            			i+=1
            

            think about people first, then computers

            Nagarjuna ReddyN 2 Replies Last reply Reply Quote 0
            • Nagarjuna ReddyN Offline
              Nagarjuna Reddy @livius
              last edited by

              @livius said in Bluetooth services is not started:

              Bluetooth.CHAR_READ_EVENT
              0_1511346140454_Capture.JPG

              transmitter run in one LoPy and reciever LoPy is connected but not get any values from transmitter side i want to
              bolded text

              i=0
              while True:
              val = 'Value{}'.format(i)
              print('Setting value: {}'.format(val))
              chr1.value(val) #Set the characteristic value - should trigger notification is a client has registered for notifications
              time.sleep(3)
              i+=1
              this is a transmitter side loop this loop values is getting to once connected reciever is recieved that for loop values but in their not iam getting so please solve my problem

              Ch.nagarjuna reddy

              Nagarjuna ReddyN 1 Reply Last reply Reply Quote 0
              • Nagarjuna ReddyN Offline
                Nagarjuna Reddy @Nagarjuna Reddy
                last edited by

                @nagarjuna-reddy
                livius you already edit my code but same problem i am getting what iam expected output is sending before message so please check and replay it arguently.

                Ch.nagarjuna reddy

                1 Reply Last reply Reply Quote 0
                • Nagarjuna ReddyN Offline
                  Nagarjuna Reddy @livius
                  last edited by

                  @livius

                  ivius
                  you already edit my code but same problem i am getting what iam expected output is sending before message so please check and replay it urgently.

                  Ch.nagarjuna reddy

                  1 Reply Last reply Reply Quote 0
                  • Nagarjuna ReddyN Offline
                    Nagarjuna Reddy @st3ty
                    last edited by

                    @st3ty

                    hi i am also have a same problem if you success to execute please send your code to me.
                    Thank you

                    Ch.nagarjuna reddy

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      jmahesh @Nagarjuna Reddy
                      last edited by jmahesh

                      @nagarjuna-reddy said in Bluetooth services is not started:

                      conn.disconnect()

                      Hi,
                      put a sleep time before service loop, that will make the services to read. I tried and it is working.

                      time.sleep(1.0);
                      print('sleep resumed', conn.services())
                      services = conn.services()
                      print(services)
                      for service in conn.services():

                      S 1 Reply Last reply Reply Quote 0
                      • S Offline
                        st3ty @jmahesh
                        last edited by

                        @jmahesh

                        Hi,

                        I tried it too and it's working.

                        Thank You!

                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • 1 / 1
                        • First post
                          Last post

                        Pycom on Twitter

                        Pycom