Ejemplo n.º 1
0
def blueGo(u0):
    #   p = Peripheral()
    #   p.advertise(device_name=name)

    def event_handler(id, handle, data):
        print("BLE event:", id, "handle:", handle)
        print(data)
        if id == constants.EVT_GAP_CONNECTED:
            Dragos.colorwheel()
        elif id == constants.EVT_GAP_DISCONNECTED:
            print("Disconnect")
            # disconnect
            #LED(2).off()

    #u0 = UUID("6e400001-b5a3-f393-e0a9-e50e24dcca9e")
    #u0 = UUID(encodeName(badge))
    u1 = UUID("6e400002-b5a3-f393-e0a9-e50e24dcca9e")
    u2 = UUID("6e400003-b5a3-f393-e0a9-e50e24dcca9e")
    s = Service(u0)
    c0 = Characteristic(u1,
                        props=Characteristic.PROP_WRITE
                        | Characteristic.PROP_WRITE_WO_RESP)
    c1 = Characteristic(u2,
                        props=Characteristic.PROP_NOTIFY,
                        attrs=Characteristic.ATTR_CCCD)
    s.addCharacteristic(c0)
    s.addCharacteristic(c1)
    p = Peripheral()
    p.addService(s)
    p.setConnectionHandler(event_handler)
    p.advertise(device_name="Dragos", services=[s])
Ejemplo n.º 2
0
def event_handler(id, handle, data):
    global periph
    global service
    if id == constants.EVT_GAP_CONNECTED:
        pass
    elif id == constants.EVT_GAP_DISCONNECTED:
        # restart advertisment
        periph.advertise(device_name="Nano Blinky", services=[service])
    elif id == constants.EVT_GATTS_WRITE:
        LED(1).on() if int(data[0]) else LED(1).off()


# start off with LED(1) off
LED(1).off()

notif_enabled = False
uuid_service = UUID("0x1523")
uuid_led = UUID("0x1525")

service = Service(uuid_service)
char_led = Characteristic(uuid_led, props=Characteristic.PROP_WRITE)
service.addCharacteristic(char_led)

periph = Peripheral()
periph.addService(service)
periph.setConnectionHandler(event_handler)
periph.advertise(device_name="Nano Blinky", services=[service])

while (True):
    time.sleep_ms(500)
Ejemplo n.º 3
0
        # measure chip temperature
        temp = Temp.read()
        temp = temp * 100
        char_temp.write(bytearray([temp & 0xFF, temp >> 8]))


# start off with LED(1) off
LED(1).off()

# use RTC1 as RTC0 is used by bluetooth stack
# set up RTC callback every 5 second
rtc = RTC(1, period=5, mode=RTC.PERIODIC, callback=send_temp)

notif_enabled = False

uuid_env_sense = UUID("0x181A")  # Environmental Sensing service
uuid_temp = UUID("0x2A6E")  # Temperature characteristic

serv_env_sense = Service(uuid_env_sense)

temp_props = Characteristic.PROP_NOTIFY | Characteristic.PROP_READ
temp_attrs = Characteristic.ATTR_CCCD
char_temp = Characteristic(uuid_temp, props=temp_props, attrs=temp_attrs)

serv_env_sense.addCharacteristic(char_temp)

periph = Peripheral()
periph.addService(serv_env_sense)
periph.setConnectionHandler(event_handler)
periph.advertise(device_name="micr_temp", services=[serv_env_sense])
Ejemplo n.º 4
0
Dragos.ledtest()

micropython.alloc_emergency_exception_buf(100)
"""
name = open('name.py','r')
title = open('title.py','r')
company = open('company.py','r')
"""

badge = Dragos.dragos(name.get(), title.get(), company.get())
#badge = Dragos.dragos(name.read(), title.read(), company.read())

Dragos.dragos.nametag(badge)

#Start BLE service
DragosBle.blueGo(UUID(DragosBle.encodeName(badge)))

once = True
# Main UI Loop
while True:
    if Dragos.a.value() == 0:
        sleep_ms(400)
        if Dragos.a.value() == 0 and Dragos.b.value() == 0:
            Dragos.usbMode()
            Dragos.dragos.showString(badge, "USB mode enabled")
            break
        Dragos.dragos.showTemp(badge)
    if Dragos.b.value() == 0:
        sleep_ms(400)
        if Dragos.a.value() == 0 and Dragos.b.value() == 0:
            Dragos.usbMode()