Hello I'm hoping someone can help me with Bluetooth advertising & scanning. This is for a school stem project.
I'm working with a circuit playground Bluefruit development board and using circuit python. Trying to implement a social distancing badge - lights up when another user is too near. General idea is to set up an advertising beacon and then switch to scan.
I've had a go at code but would appreciate someone to review it. I'm not sure if the eddystoneuid works; when I'm scanning will it only scan for my specific uid for example.
Thank you
import time
from adafruit_circuitplayground.bluefruit import cpb
import adafruit_ble
from adafruit_ble_eddystone import uid
emitter = adafruit_ble.BLERadio()
advertisement = uid.EddystoneUID(emitter.address_bytes)
receiver = adafruit_ble.BLERadio()
while cpb.switch:
# only if the switch is to the leftt the code will work
# so there's an option to turn the board off if needed.
emitter.start_advertising(advertisement)
time.sleep(0.5)
emitter.stop_advertising()
# advertises its "address" almost every half second
for advertisement in receiver.start_scan():
# then the same board scans for advertisements after
rssi = advertisement.rssi
if advertisement.rssi > -80:
# if the rssi is stronger than -80 (around 2m, yet to be certain)
cpb.pixels.fill((250, 0, 0))
time.sleep(0.2)
cpb.pixels.fill((250, 0, 0))
time.sleep(0.2)
cpb.pixels.fill((250, 0, 0))
cpb.pixels.fill((0, 0, 0))
# then the neopixels flash bright red three times, then turn off
receiver.stop_scan()
question from:
https://stackoverflow.com/questions/65877086/bluetooth-advertising-and-scan 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…