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

    Get Client Mac Address in GATTSService/Characteristic

    Scheduled Pinned Locked Moved LoPy
    blelopylopy ble
    4 Posts 2 Posters 1.3k Views 2 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.
    • N Offline
      neilh93
      last edited by

      I'm connecting to my LoPy using my Android phone and the app "BLE Scanner".

      I would like to be able to print the MAC address of my Android phone once i try to read on a characteristic but i'm unsure how this is done using GATTSService/Characteristic.

      from network import Bluetooth
      
      bluetooth = Bluetooth()
      bluetooth.set_advertisement(name='LoPy', service_uuid=b'1234567890123456')
      
      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)
      
      srv1 = bluetooth.service(uuid=b'1234567890123456', isprimary=True)
      
      chr1 = srv1.characteristic(uuid=b'ab34567890123456', value=5)
      
      char1_read_counter = 0
      def char1_cb_handler(chr):
      	global char1_read_counter
      	char1_read_counter += 1
      
      	events = chr.events()
      	if  events & Bluetooth.CHAR_WRITE_EVENT:
      		print("Write request with value = {}".format(chr.value()))
      	else:
      		if char1_read_counter < 3:
      			print(bluetooth.client(mac_adder)) #print phone MAC address??
      		else:
      			return 'ABC DEF'
      
      char1_cb = chr1.callback(trigger=Bluetooth.CHAR_WRITE_EVENT | Bluetooth.CHAR_READ_EVENT, handler=char1_cb_handler)
      
      srv2 = bluetooth.service(uuid=1234, isprimary=True)
      
      chr2 = srv2.characteristic(uuid=4567, value=0x1234)
      char2_read_counter = 0xF0
      def char2_cb_handler(chr):
      	global char2_read_counter
      	char2_read_counter += 1
      	if char2_read_counter > 0xF1:
      		return char2_read_counter
      
      char2_cb = chr2.callback(trigger=Bluetooth.CHAR_READ_EVENT, handler=char2_cb_handler)
      
      1 Reply Last reply Reply Quote 0
      • ledbelly2142L Offline
        ledbelly2142
        last edited by

        I am having some issues with Bluetooth and the GATTSService/Characteristic, can't write multiple values.

        Are you able to write multiple values?

        Friends don't let friends run with scissors

        N 1 Reply Last reply Reply Quote 0
        • N Offline
          neilh93 @ledbelly2142
          last edited by

          @ledbelly2142 I can write multiple times from the app on my phone to the Characteristic if that's what you mean?

          are you writing values from a mobile app? or do you want multiple values per characteristic? because as far as i am aware each characteristic has a single value and you can create multiple characteristics.

          1 Reply Last reply Reply Quote 0
          • ledbelly2142L Offline
            ledbelly2142
            last edited by

            We created a service with multiple characteristics but could only see the first characteristic using BLE scanner.

            Friends don't let friends run with scissors

            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