Esempio n. 1
0
def initConnection(address):
    pycom.rgbled(0xffff00)
    pycom.heartbeat(False)
    bluetooth = Bluetooth()
    bluetooth.start_scan(-1)
    bluetooth.init()
    while True:
        print("starting bluetooth")
        global connection
        devices = bluetooth.get_advertisements()
        try:
            if devices is not None and len(devices) > 0:
                for device in devices:
                    uuid = ubinascii.hexlify(device.mac)
                    if (str(uuid) == address):
                        print("foud the arduino")

                        connection = bluetooth.connect(device.mac)
                        print(device)

                        bluetooth.stop_scan()
                        global char
                        char = getBleChar()
                        pycom.rgbled(0x00ff00)
                        return device
        except:
            print("arduino refused connection trying again")
            pycom.heartbeat(True)
            closeConnection()
            continue
        time.sleep(0.05)
    pycom.rgbled(0xff0000)
    return None
def main():
    first = True
    while True:
        if first == True:
            om2m.createApplication('http://smart-iot.lan.uow.edu.au:8181/~/in-cse', 'admin:admin', 'LOPY5')
            om2m.createContainer('http://smart-iot.lan.uow.edu.au:8181/~/in-cse/in-name/LOPY5', 'admin:admin', 'WiFi_Connectivity')
            om2m.subscribeResource('http://smart-iot.lan.uow.edu.au:8181/~/in-cse/in-name/LOPY5/WiFi_Connectivity', 'admin:admin', 'lopy5_wifi_sub', 'http://smart-iot.lan.uow.edu.au:8081/monitorLopy5Wifi')
            

        wlan = WLAN()
        wlan.init(mode=WLAN.STA)
        wfResults = wlan.scan()

        wifiCon = getWifiConnectivity(wfResults)
        print('WiFi Connectivity:')
        print(wifiCon)
        print(len(wifiCon['names']))
        wifiData = {
            'Networks': wifiCon['names'],
            'MAC Addresses': wifiCon['macs'],
            'Signal Strengths': wifiCon['strengths']
        }
        om2m.createContentInstance('http://smart-iot.lan.uow.edu.au:8181/~/in-cse/in-name/LOPY5/WiFi_Connectivity', 'admin:admin', json.dumps(wifiData) )

        if first == True:
            om2m.createContainer('http://smart-iot.lan.uow.edu.au:8181/~/in-cse/in-name/LOPY5', 'admin:admin', 'BT_Connectivity')
            om2m.subscribeResource('http://smart-iot.lan.uow.edu.au:8181/~/in-cse/in-name/LOPY5/BT_Connectivity', 'admin:admin', 'lopy5_bt_sub', 'http://smart-iot.lan.uow.edu.au:8081/monitorLopy5BT')
            first = False

        bluetooth = Bluetooth()
        bluetooth.start_scan(3)
        while bluetooth.isscanning():
            time.sleep(1)
        btResults = bluetooth.get_advertisements()
        btCon = getBTConnectivity(btResults)
        print('BT Connectivity:')
        print(btCon)
        btData = {
            'MAC Addresses': btCon['macs'],
            'Signal Strengths': btCon['strengths']
        }
        om2m.createContentInstance('http://smart-iot.lan.uow.edu.au:8181/~/in-cse/in-name/LOPY5/BT_Connectivity', 'admin:admin', json.dumps(btData) )
        time.sleep(30)
Esempio n. 3
0
py = Pysense()
mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
si = SI7006A20(py)
lt = LTR329ALS01(py)
li = LIS2HH12(py)

bt = Bluetooth()
bt.set_advertisement(name="pycom")
bt.advertise(True)

while True:
    wdt.feed()
    bt.start_scan(10)
    while bt.isscanning():
        time.sleep_ms(100)
    advs = bt.get_advertisements()
    devices = set()
    devicetypes = dict()
    for adv in advs:
        if adv.mac in devices:
            continue
        devices.add(adv.mac)
        print("MAC: "+str(ubinascii.hexlify(adv.mac)))
        print("RSSI: "+str(adv.rssi))
        print("NameShort: "+str(bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_SHORT)))
        print("NameComplete: "+str(bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL)))
        mfg_data = bt.resolve_adv_data(adv.data, Bluetooth.ADV_MANUFACTURER_DATA)
        if mfg_data:
            # try to get the manufacturer data (Apple's iBeacon data is sent here)
            print("ManufacturerData: "+str(ubinascii.hexlify(mfg_data)))
        print("connecting to "+str(ubinascii.hexlify(adv.mac)))
Esempio n. 4
0
# org.bluetooth.service.weight_scale - WS_WS_INT = 0x181D
# org.bluetooth.characteristic.weight_measurement_WS_CHAR = (UUID(0x2A9D), FLAG_READ | FLAG_NOTIFY,)
# org.bluetooth.service.environmental_sensing - ES _ES_INT = 0x181A

from network import Bluetooth
import time
import struct

print('Create BT')
bluetooth = Bluetooth()
print('Scanning...')
bluetooth.start_scan(2)  # start scanning with no timeout
time.sleep(2.1)

if not bluetooth.isscanning():
    for adv in bluetooth.get_advertisements():
        name = bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL)
        if name == 'HEN':
            mac = adv.mac

            try:
                print('Connecting to HEN')
                conn = bluetooth.connect(adv.mac)
                time.sleep(0.05)
                services = conn.services()
                for service in services:
                    time.sleep(0.050)
                    #print('Service: ',service.uuid())
                    #print('Chars: ',service.characteristics())
                    uuid = service.uuid()
                    if type(uuid) == bytes:
Esempio n. 5
0
# new mac adresses:
#C7:C3:83:EE:AA:A4
#FB:6F:11:25:79:9B
#F7:F0:BB:A6:ED:F7
#C3:C7:E7:73:7C:3F

# b'f3bc0b6feb4c' # raw: b'\xf3\xbc\x0bo\xebL'
# b'edbed48d0b87' # raw: b'\xed\xbe\xd4\x8d\x0b\x87
# b'c7c383eeaaa4' # raw?
# b'cd87e6a38dc2' # raw?

#pycom.rgbled(0x007f00) # green
while True:
    pycom.rgbled(0x007f00)
    advList = bluetooth.get_advertisements()
    for adv in advList:
        macRaw = adv[0] # binary mac address
        macReal = binascii.hexlify(macRaw) # convert to hexadecimal
        if macReal == b'fb6f1125799b': # old: b'f3bc0b6feb4c':
            print('beacon A rssi: ', adv[3]) # adv[3] is rssi
            sendToSocket(beaconID = 1, rssi = adv[3])
        elif macReal == b'f7f0bba6edf7': # old: b'edbed48d0b87':
            print('beacon B rssi: ', adv[3])
            sendToSocket(beaconID = 2, rssi = adv[3])
        elif macReal == b'c7c383eeaaa4': # <-- old
            print('beacon C rssi: ', adv[3])
            sendToSocket(beaconID = 3, rssi = adv[3])
        elif macReal == b'c3c7e7737c3f': # old: b'cd87e6a38dc2':
            print('beacon D rssi: ', adv[3])
            sendToSocket(beaconID = 4, rssi = adv[3]) # adv[3]