Exemplo n.º 1
0
    def __init__(self):
        logging.info("Initializing BLE...")
        self.bt = BLE()
        self.bt.irq(handler=self.bt_irq)
        logging.info('Waiting to set BLE active...')
        self.bt.active(True)

        self.addresses = []
        for i in range (_ARRAYSIZE):
            self.addresses.append((-1, -1, b'AAAAAA', DEVICE_NAME_PLACEHOLDER, 0))
        self.device_index = 0
        self.type = 0
        self.address = bytearray(6)
        self.name = 0
        self.last_read = 0
        self.conn_handle = 0
        self.connected = False
        self.read_flag = False
        self.write_flag = False
        self.write_status = -1
        self.notify_flag = False
        self.scan_complete = False
        self.notify_data = bytearray(30)
        self.char_data = bytearray(30)
        self.temperature = 0
        self.humidity = 0
        self.battery_voltage = 0
        self.battery_level = 0
Exemplo n.º 2
0
def sniffer(time):
    # Scan continuosly
    bt = BLE()
    bt.active(True)
    bt.irq(handler=bt_irq)
    print("Scanning for %dms..." % time, end="")
    bt.gap_scan(time, 10, 10)
    print("DONE!")
Exemplo n.º 3
0
    def startBLE(self):
        if self.ble_activated == False:
            from ubluetooth import BLE

            bt = BLE()
            bt.active(True)
            self.ble_activated = True
            self.ble_handle = bt
Exemplo n.º 4
0
def test_switchbot():
    import json

    bt = BLE()
    bt.active(True)
    switchbot = SwitchBot(bt, "C6:23:6C:64:20:C1")
    status = switchbot.getStatus()
    print("status: ", status)
    switchbot.off()
    bt.active(False)


#test_switchbot()
Exemplo n.º 5
0
def demo():
    ble = BLE()
    ble32 = BluetoothApiESP32(ble)

    bat = 54
    kg = 32.1
    hum = 65.4
    temp = 23.4
    temp_gap = [12.3,45.6]

    i = 0

    while True:
        # Write every second, notify every x seconds.
        i += 1
        if i % 3 == 0:
            ble32.set_battery_level(int(bat), notify=False)
            print('bat: ',bat)
        if i % 5 == 0:    
            ble32.set_weight(kg, notify=False)
            print(' kg: ',kg)
        if i % 7 == 0:
            ble32.set_humidity(hum, notify=False)
            print('  hum: ',hum)
        if i % 11 == 0:
            ble32.set_temperature(temp, notify=False)
            print('   temp: ',temp)
        if i % 13 == 0:
            ble32.set_comb_gap_temperature(temp_gap, notify=False)
            print('    temp gap: ',temp)

        # Random walk 
        #bat += int(random.uniform(-1, 1))
        #kg += random.uniform(-0.5, 0.5)
        #hum += random.uniform(-0.5, 0.5)
        #temp += random.uniform(-0.5, 0.5)
        time.sleep_ms(1000)
Exemplo n.º 6
0
    def __init__(self):
        debug("Initialising")
        self.bt = BLE()
        self.bt.irq(handler=self.bt_irq)
        print('waiting to set BLE active')
        self.bt.active(True)

        self.addresses = []
        for i in range(_ARRAYSIZE):
            self.addresses.append((100, b'AAAAAA', 'name'))
        self.conn_handle = 0
        self.connected = False
        self.write_flag = False
        self.read_flag = False
        self.notify = False
        self.index = 0
        self.scan = False
        self.notify_data = bytearray(30)
        self.address = bytearray(6)
        self.char_data = bytearray(30)
        self.temp = 0
        self.humidity = 0
        self.battery = 0
        self.voltage = 0
Exemplo n.º 7
0
    def __init__(self):
        a = 0
        while a <= 10:
            a = a + 1
            print("REINICIO\n")

        self.timer = Timer(0)
        self.timer.init(period=1200000,
                        mode=Timer.PERIODIC,
                        callback=handleInterrupt)  #Reset cada 20 mins
        self.wdt = WDT(
            timeout=100000
        )  #Watchdog configurado para que si no se alimenta en 100 seg realimente
        self.p13 = Pin(13, Pin.IN)  #Pin para interrumpir el main

        self.mac = ubinascii.hexlify(network.WLAN().config('mac'),
                                     ':').decode()
        print("Esto es la mac:", self.mac)

        # Scan for 10s (at 100% duty cycle)
        self.bt = BLE()

        self.lista_id = []
        self.lista_rssi = []
Exemplo n.º 8
0
            ADV_DISSECTOR_MAP[advdtype](advpdu)
        except:
            print("\t%s" % (dumpHex(advpdu), ))

        i += advsize + 1


def bt_irq(event, data):
    if event == IRQ_SCAN_RESULT:
        # A single scan result.
        addr_type, addr, adv_type, rssi, adv_data = data
        if adv_type in ADV_TYPES:
            print(ADV_TYPES[adv_type])
            print("{addr: ", dumpHex(addr), ", addr_type: ", repr(addr_type),
                  ", rssi:", repr(rssi), "}")
            dumpAdvData(adv_data)
            print("\r\n")

    elif event == IRQ_SCAN_COMPLETE:
        # Scan duration finished or manually stopped.
        print('scan complete')


# Scan continuosly
bt = BLE()
bt.active(True)
bt.irq(handler=bt_irq)
print("Start scanning....", end="")
bt.gap_scan(0, 10, 10)
print("DONE!")
Exemplo n.º 9
0
 def __init__(self):
     self.ble_handle = BLE()
     self.ble_activated = False
     self.ble_devices = {}
Exemplo n.º 10
0
def test_mithermometer():
    bt = BLE()
    bt.active(True)
    mithermometer = MiThermometer(bt,"4C:65:A8:DF:E9:37")
    print(mithermometer.get_mitempdata())