Beispiel #1
0
def connect_lk(productKey, deviceName, deviceSecret):
    global device, iot_connected
    key_info = {
        'region': 'cn-shanghai',
        'productKey': productKey,
        'deviceName': deviceName,
        'deviceSecret': deviceSecret,
        'keepaliveSec': 60
    }
    # 将三元组信息设置到iot组件中
    device = Device()

    # 设定连接到物联网平台的回调函数,如果连接物联网平台成功,则调用on_connect函数
    device.on(Device.ON_CONNECT, on_connect)

    # 配置收到云端属性控制指令的回调函数,如果收到物联网平台发送的属性控制消息,则调用on_props函数
    device.on(Device.ON_PROPS, on_props)

    # 启动连接阿里云物联网平台过程
    device.connect(key_info)

    # 等待设备成功连接到物联网平台
    while (True):
        if iot_connected:
            print('物联网平台连接成功')
            break
        else:
            print('sleep for 1 s')
            utime.sleep(1)
    print('sleep for 2s')
    utime.sleep(2)
Beispiel #2
0
def do_connect_lk(productKey, deviceName, deviceSecret,speaker):
    global device, iot_connected, on_request, on_play
    key_info = {
        'region' : 'cn-shanghai' ,      #实例的区域
        'productKey': productKey ,      #物联网平台的PK
        'deviceName': deviceName ,      #物联网平台的DeviceName
        'deviceSecret': deviceSecret ,  #物联网平台的deviceSecret
        'keepaliveSec': 60              
    }
    # 将三元组信息设置到iot组件中
    device = Device()

    # 设定连接到物联网平台的回调函数,如果连接物联网平台成功,则调用on_connect函数
    device.on(Device.ON_CONNECT, on_connect)

   # 设定连接到物联网平台的回调函数,如果连接物联网平台下发控制服务请求指令,则调用on_service函数
    device.on(Device.ON_SERVICE, on_service)

    print ("开始连接物联网平台")

    # 启动连接阿里云物联网平台过程
    device.connect(key_info)
    # 等待设备成功连接到物联网平台
    while True:
        if iot_connected:
            print("物联网平台连接成功")
            speaker.play(tonepathConnected)
            break
        else:
            print("sleep for 1 s")
            time.sleep(1)

   # 触发linkit sdk持续处理server端信息
    while True:
        if  on_request:
            print('get on request cmd')
            speaker.download_resource_file(on_request, resDir) # 语料下载
            on_request = False
        elif on_play:
            speaker.play_voice(on_play,resDir)                 # 语料播报
            on_play = False
        time.sleep(0.01)
    # 断开连接
    device.close()
Beispiel #3
0
def main():
    global disp, dev, g_score
    dev = Device()
    disp = display.TFT()

    connect_wifi(SSID, PWD)

    dev.on(Device.ON_CONNECT, cb_lk_connect)
    dev.on(Device.ON_SERVICE, cb_lk_service)
    dev.connect(key_info)

    while True:
        if g_lk_connect:
            break

    ucamera.init('uart', 33, 32)
    ucamera.setProp(ucamera.SET_FRAME_SIZE, ucamera.SIZE_320X240)

    while True:
        g_lk_service = False
        start = utime.ticks_ms()
        frame = ucamera.capture()
        time_diff = utime.ticks_diff(utime.ticks_ms(), start)
        print('capture time : %d' % time_diff)

        start = utime.ticks_ms()
        disp.image(0, 0, frame, 0)
        time_diff = utime.ticks_diff(utime.ticks_ms(), start)
        print('image time : %d' % time_diff)

        # fileid = dev.uploadFile('face.jpg', None)
        detectPedestrian(frame, 'pede.jpg', productKey, deviceName,
                         deviceSecret)

        if (g_score > 0.6):
            disp.clear()
            disp.font(disp.FONT_DejaVu40)
            # 显示识别结果
            disp.text(40, 80, 'Pedestrian', disp.RED)
            disp.text(40, 120, 'Deteted!!!', disp.RED)
            print('Pedestrian Detected!!!')
            utime.sleep_ms(1000)
            g_score = 0
Beispiel #4
0
def main():
    global g_connect_status, net, device, deviceSecret, deviceName, productKey, productSecret, device_dyn_resigter_succed
    #连接网络
    connect_network()
    #获取设备的IMEI 作为deviceName 进行动态注册
    deviceName = modem.getDevImei()
    #初始化物联网平台Device类,获取device实例
    device = Device()
    if deviceName is not None and len(deviceName) > 0:
        #动态注册一个设备
        dyn_register_device(productKey, productSecret, deviceName)
    else:
        print("can't get IMEI")
    while deviceSecret is None:
        time.sleep(0.2)

    print('dynamic successed:' + deviceSecret)
    key_info = {
        'region': 'cn-shanghai',
        'productKey': productKey,
        'deviceName': deviceName,
        'deviceSecret': deviceSecret,
        'keepaliveSec': 60
    }
    #打印设备信息
    print(key_info)
    #device.ON_CONNECT 是事件,on_connect是事件处理函数/回调函数
    device.on(device.ON_CONNECT, on_connect)
    device.on(device.ON_PROPS, on_props)
    device.on(device.ON_SERVICE, on_service)
    device.on(device.ON_ERROR, on_error)
    device.connect(key_info)

    write.do_write()
    _thread.start_new_thread(rfid_read, ())