示例#1
0
文件: dan.py 项目: IoTtalk/vpython-da
def pull_odf(df_name):
    if not _df_is_odf[df_name] or not _df_selected[df_name]:
        return

    dataset = csmapi.pull(_mac_addr, df_name)
    if has_new_data(dataset, _df_timestamp[df_name]):
        _df_timestamp[df_name] = dataset[0][0]
        _dan2dai.pull(df_name, dataset[0][1])
示例#2
0
文件: dan.py 项目: IoTtalk/vpython-da
def pull_ctl():
    global _ctl_timestamp

    dataset = csmapi.pull(_mac_addr, '__Ctl_O__')
    if has_new_data(dataset, _ctl_timestamp):
        _ctl_timestamp = dataset[0][0]
        if _handle_control_message(dataset[0][1]):
            _dan2dai.pull('Control', dataset[0][1])

        else:
            logging('Problematic command message: {}', dataset[0][1])
示例#3
0
文件: DAN.py 项目: IoTtalk/CameraPT
def pull(FEATURE_NAME):
    global timestamp

    data = csmapi.pull(MAC,FEATURE_NAME)
    if data != []:
        if timestamp[FEATURE_NAME] == data[0][0]:
            return None
        timestamp[FEATURE_NAME] = data[0][0]
        if data[0][1] != []:
            return data[0][1]
        else: return None
    else:
        return None
示例#4
0
def pull(FEATURE_NAME):
    global timestamp

    if state == 'RESUME': data = csmapi.pull(MAC, FEATURE_NAME)
    else: data = []

    if data != []:
        if timestamp[FEATURE_NAME] == data[0][0]:
            return None
        timestamp[FEATURE_NAME] = data[0][0]
        if data[0][1] != []:
            return data[0][1]
        else:
            return None
    else:
        return None
示例#5
0
def ControlChannel():
    global state, SelectedDF, control_channel_timestamp
    NewSession=requests.Session()
    while True:
        time.sleep(2)
        try:
            CH = csmapi.pull(MAC,'__Ctl_O__', NewSession)
            if CH != []:
                if control_channel_timestamp == CH[0][0]: continue
                control_channel_timestamp = CH[0][0]
                state = CH[0][1][0]
                if state == 'SET_DF_STATUS' :
                    csmapi.push(MAC,'__Ctl_I__',['SET_DF_STATUS_RSP',{'cmd_params':CH[0][1][1]['cmd_params']}], NewSession)
                    DF_STATUS = list(CH[0][1][1]['cmd_params'][0])
                    SelectedDF = []
                    index=0            
                    for STATUS in DF_STATUS:
                        if STATUS == '1':
                            SelectedDF.append(profile['df_list'][index])
                        index=index+1
        except Exception as e:
            print ('Control error', e)
示例#6
0
def get_state():
    CH = csmapi.pull(MAC, '__Ctl_O__')
    if CH != []: return CH[0][1][0]
    else: return None
示例#7
0
import csmapi

csmapi.ENDPOINT = "https://5.iottalk.tw"  #Please fill the used IoTtalk server URL.

registered_address = 'The registered address of your device'  #Please fill the registered address of your device.

if __name__ == "__main__":

    profile = csmapi.pull(registered_address,
                          'profile')  #Pull the profile of RemoteControl
    if profile:
        device_feature_list = profile['df_list']
        print("Device feature list = ", device_feature_list)

    control_channel_output = csmapi.pull(
        registered_address, '__Ctl_O__')  #Pull the Output of Control Channel
    if control_channel_output:
        selected_device_feature_flags = control_channel_output[0][1][1][
            'cmd_params'][0]
        print("Selected device feature flags = ",
              selected_device_feature_flags)
示例#8
0
def SwitchSetCount(mac_addr, count=1, count1=1, count2=1, count3=1, count4=1):
    try:
        registered_address = mac_addr
        profile = csmapi.pull(registered_address,
                              'profile')  #Pull the profile of RemoteControl
        if profile:
            device_feature_list = profile['df_list']
            print("Device feature list = ", device_feature_list)

        control_channel_output = csmapi.pull(
            registered_address,
            '__Ctl_O__')  #Pull the Output of Control Channel
        if control_channel_output:
            selected_device_feature_flags = control_channel_output[0][1][1][
                'cmd_params'][0]
            print("Selected device feature flags = ",
                  selected_device_feature_flags)

            button_string = selected_device_feature_flags[18:27]
            button_num = button_string.count('1')
            print("Button String :", button_string)
            print("Iottalk Button Count :", button_num)

            color_string = selected_device_feature_flags[36:45]
            color_num = color_string.count('1')
            print("Color String :", color_string)
            print("Iottalk Color Count :", color_num)

            key_string = selected_device_feature_flags[9:18]
            key_num = key_string.count('1')
            print("keypad String :", key_string)
            print("Iottalk keypad Count :", key_num)

            knob_string = selected_device_feature_flags[27:36]
            knob_num = knob_string.count('1')
            print("knob String :", knob_string)
            print("Iottalk knob Count :", knob_num)

            switch_string = selected_device_feature_flags[0:9]
            switch_num = switch_string.count('1')
            print("Switch String :", switch_string)
            print("Iottalk Switch Count :", switch_num)

        return make_response(
            render_template('SwitchSet.html',
                            mac_addr=registered_address,
                            count=switch_num,
                            count1=key_num,
                            count2=button_num,
                            count3=knob_num,
                            count4=color_num))

    except Exception as e:
        print('Error:', e)
        return make_response(
            render_template('SwitchSet.html',
                            mac_addr=mac_addr,
                            count=int(count),
                            count1=int(count1),
                            count2=int(count2),
                            count3=int(count3),
                            count4=int(count4)))