def scan_report_cb(data):
    try:
        print("Detected packet from", ble.btos(data[4]), "containing",
              ble.btos(data[3]))
        print("         packet is of type", data[0],
              "while address is of type", data[1])
        print("         remote device has RSSI of", data[2])
        # send to socket
        ss.sendall(ble.btos(data[3]))
        ss.sendall("\n")
    except Exception as e:
        print("send", e)
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))
def scan_report_cb(data):
    print("Detected packet from",ble.btos(data[4]),"containing",ble.btos(data[3]))
    print("         packet is of type",data[0],"while address is of type",data[1])
    print("         remote device has RSSI of",data[2])
def disconnection_cb(address):
    global connected
    print("Disconnected from", ble.btos(address))
    # let's start advertising again
    ble.start_advertising()
    connected = False
def connection_cb(address):
    global connected
    print("Connected to", ble.btos(address))
    connected = True
Exemple #6
0
    # 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)

# Uncomment the following lines to delte bonded devices!
for bond in ble.bonded():
    print("Removing bonded:", ble.btos(bond))
    ble.remove_bonded(bond)

# loop forever
while True:
    print(".")
    if random(0, 100) < 50 and notifications_enabled and connected:
        value = bytearray(cn.get_value())
        value[0] = 0  # simple alert type
        if value[1] < 255:
            value[1] = value[1] + 1  # add a notification
        print("Adding a new notification, total of", value[1])
        # the remaining 14 bytes can be some text
        value[2:10] = "Zerynth!"
        # set the new value. If ble notifications are enabled, the connected device will receive the change
        cn.set_value(value)
Exemple #7
0
def disconnected_cb(address):
    global connected
    print(ble.btos(address))
    ble.start_advertising()
    connected = False
    set_disconnect_led()
Exemple #8
0
def connected_cb(address):
    global connected
    print(ble.btos(address))
    connected = True
    set_connect_led()