Creating an Eddystone beacon?
-
@b-veen You have successfully implemented an iBeacon. I'm doing the same thing but struggling with the bluetooth.set_advertisement method. Can you help? What should I put in the manufacterer_data and what in the service_data? Should I put the complete 31 bytes in the manufacturer_data and in what order...
-
I tried with data = bytes([0xAA, 0xFE, 0x00,
0x29,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
0x00,0x00]) , but it doesn't work! -
@surly I can help you with Eddystone-URL, if that's interesting, but this seems to be Eddystone-UID.
-
@papasmurph yes, sorry! I mean the Eddystone-URL is ok, but what I really need is the Eddystone-UID ( also the IBeacon version would be usefull ) !
-
@surly Here's a complete example of iBeacon and Eddystone-URL. I don't have an example of UID or TLD, as I didn't need those.
In my iBeacon example, the UUID is encoded in the packet. That's the only UUID I needed (my own), but would be easy to create dynamically from a string.
from network import Bluetooth import pycom import time # https://docs.pycom.io/pycom_esp32/library/network.Bluetooth.html # https://support.kontakt.io/hc/en-gb/articles/201492492-iBeacon-advertising-packet-structure # https://github.com/google/eddystone/blob/master/protocol-specification.md # https://github.com/google/eddystone/tree/master/eddystone-url/ # https://forum.pycom.io/topic/1120/creating-an-eddystone-beacon # https://www.mkompf.com/tech/eddystoneurl.html MODE_IBEACON = 1 MODE_EDDYSTONEURL = 2 mode = MODE_IBEACON def twocompl(x): if x < 0: x += 256 return x timeSleep = 1 bluetooth = Bluetooth() bluetooth.init() power1m = -59 if mode == MODE_IBEACON: major = 22240 minor = 234 data = [ 0x4c, 0x00, 0x02, 0x15, # Manufacturer data 0xA6, 0xE3, 0xE0, 0x06, 0xBB, 0xC4, 0x4D, 0xD1, 0x9C, 0xA3, 0x3E, 0x86, 0xC4, 0x95, 0x7D, 0xF0, # UUID (CliqTags) (major >> 8) & 0xFF, major & 0xFF, # Major ID (minor >> 8) & 0xFF, minor & 0xFF, # Minor ID twocompl(power1m) # Power ] bluetooth.set_advertisement(name = None, manufacturer_data = bytes(data)) elif mode == MODE_EDDYSTONEURL: url = 'https://www.abiro.com' uuid = [0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xaa, 0xfe, 0x00, 0x00] url = url.replace('http://www.', chr(0)) url = url.replace('https://www.', chr(1)) url = url.replace('http://', chr(2)) url = url.replace('https://', chr(3)) url = url.replace('.com/', chr(0)) url = url.replace('.org/', chr(1)) url = url.replace('.edu/', chr(2)) url = url.replace('.net/', chr(3)) url = url.replace('.info/', chr(4)) url = url.replace('.biz/', chr(5)) url = url.replace('.gov/', chr(6)) url = url.replace('.com', chr(7)) url = url.replace('.org', chr(8)) url = url.replace('.edu', chr(9)) url = url.replace('.net', chr(10)) url = url.replace('.info', chr(11)) url = url.replace('.biz', chr(12)) url = url.replace('.gov', chr(13)) data = [ 0xAA, 0xFE, # Eddystone ID 0x10, # Eddystone-URL twocompl(power1m), # Power ] for c in url: data.append(ord(c)) bluetooth.set_advertisement(service_uuid = bytes(uuid), service_data = bytes(data)) bluetooth.advertise(True) while True: time.sleep(timeSleep) -
@papasmurph Great! it works! Thank you very much
-
@papasmurph Thanks for doing the work to make the Eddystone beacon. I have your version up and running on WiPy 3.0. The eddystone beacon can send broadcasts the basic url but not a url with a path attached.
For example, if the url is https://pycom.io, the physical web app on my iphone gets the url and shows a notification. If the url is https://pycom.io/news, the phone app does not see any beacon.
Is this is a limitation of the bluetooth library? If so, is there a fix?
-
@zaphodbb Have you tested with those specific URLs, or with different URLs?
There's a limit on the (compressed) URL length in the Eddystone format which you may hit if your URL is long. The two URLs you gave should fit, but https://forum.pycom.io/topic/1120/creating-an-eddystone-beacon/14 won't, for instance.
If you have longer URLs, you'll need to use an URL-shortener.
-
@jcaron I used the two urls in my original post. I used the code from @papasmurph and added a print statement to look at the data bytes sent to the Bluetooth function. In both cases the data stream is properly formed.
When transmitting “https://pycom.io” it gets picked up by the physical web app on my phone. When I add the path “/news” and restart the code, the data stream is still properly formed but the app does not see an Eddystone beacon. Removing the path gets the beacon to be seen again.
My conclusion is that there is something happening when a path is added to the url. This is important as any shortened url (ie goo.gl/ads23g) won’t be seen.
-
@zaphodbb I think the issue is that the code uses a long (128 bit) UUID instead of the short 16-bit UUID, so there's a very short limitation on the max URL size.
Try replacing the value of
uuidwith[0xaa, 0xfe]or0xfeaa, it should give you 14 more bytes for your URL (haven't tried it).
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