Пример #1
0
def adv_stop_cb(data):
    global pdu_count, adv_content
    print("Advertising stopped")
    adv_content = (adv_content + 1) % 3
    if adv_content == 0:
        # advertise UID
        interval = 100
        timeout = 10000
    elif adv_content == 1:
        # advertise URL
        interval = 100
        timeout = 15000
    else:
        # advertise TLM
        interval = 100
        timeout = 150
        pdu_count += 1
        payloads[2] = bb.eddy_encode_tlm(battery_level, temperature, pdu_count,
                                         uptime.get() /
                                         1000)  # TLM Eddystone payload

    payload = payloads[adv_content]
    ble.advertising(interval,
                    timeout=timeout,
                    payload=payload,
                    mode=ble.ADV_UNCN_UND)
    ble.start_advertising()
    print("Advertising restarted with", ble.btos(payload))
Пример #2
0
    # Configure security. BLE security is very flexible.
    # In this case we declare that the device has only an output capability (CAP_DISPLAY_ONLY),
    # that we require a bonding (storage of the keys after pairing)
    # and that we want both secure connection and main in the middle protection.
    # Since we have CAP_DISPLAY_ONLY, we also declare a passkey that will be shown to the user
    # to be entered on the master (i.e. the smartphone) to finalize the bonding.
    ble.security(capabilities=ble.CAP_DISPLAY_ONLY,
                 bonding=ble.AUTH_BOND,
                 scheme=ble.AUTH_SC | ble.AUTH_MITM,
                 key_size=16,
                 passkey=225575)
    # To do so, we need a callback to display the passkey when needed
    ble.add_callback(ble.EVT_SHOW_PASSKEY, show_key_cb)

    # Setup advertising to 50ms
    ble.advertising(50)

    # Start the BLE stack
    ble.start()

    # Now start advertising
    ble.start_advertising()

except Exception as e:
    print(e)

# loop forever
while True:
    print(".")
    if random(0, 100) < 50 and notifications_enabled and connected:
        value = bytearray(cn.get_value())
Пример #3
0
#import the ESP32 BLE driver: a BLE capable VM is also needed!
from espressif.esp32ble import esp32ble as bledrv
# then import the BLE module and beacons
from wireless import ble
from wireless import ble_beacons as bb

streams.serial()
try:
    # initialize BLE driver
    bledrv.init()

    # Set GAP name and no security
    ble.gap("Zerynth",security=(ble.SECURITY_MODE_1,ble.SECURITY_LEVEL_1))
    
    # set advertising options: advertise every second with custom payload in non connectable undirected mode
    ble.advertising(20,payload=bb.ibeacon_encode("fb0b57a2-8228-44cd-913a-94a122ba1206",10,3,-69),mode=ble.ADV_UNCN_UND)

    # Start the BLE stack
    ble.start()

    # Now start advertising
    ble.start_advertising()

except Exception as e:
    print(e)

# loop forever
while True:
    print(".")
    sleep(10000)
Пример #4
0
    ble.start_advertising()
    print("Advertising restarted with", ble.btos(payload))


try:
    # initialize BLE driver
    bledrv.init()

    # Set GAP name and no security
    ble.gap("Zerynth", security=(ble.SECURITY_MODE_1, ble.SECURITY_LEVEL_1))
    ble.add_callback(ble.EVT_ADV_STOPPED, adv_stop_cb)

    # set advertising options: advertise every second with custom payload in non connectable undirected mode
    # after 10 seconds, stop and change payload
    ble.advertising(100,
                    timeout=10000,
                    payload=payloads[adv_content],
                    mode=ble.ADV_UNCN_UND)

    # Start the BLE stack
    ble.start()

    # Now start scanning for 30 seconds
    ble.start_advertising()

except Exception as e:
    print(e)

# loop forever
while True:
    print(".")
    sleep(10000)