Example #1
0
def push_data(df_name):
    if not _devices[df_name].push_data:
        return
    log.debug('%s:%s', df_name, _flags[df_name])
    while _flags[df_name]:
        _data = _devices[df_name].push_data()
        if not isinstance(_data, NoData) and _data is not NoData:
            push(df_name, _data)
        time.sleep(_interval[df_name])
Example #2
0
                tmp = client.get(f_name)
                if tmp is None:
                    continue
                else:
                    client.delete(f_name)

                v = type_(tmp)
                if v is not None:
                    os.system(
                        r'echo "default-on" > /sys/class/leds/ds:green:wlan/trigger'
                    )
                    print('DAN.push({f}, {v!r})'.format(
                        f=f_name,
                        v=v,
                    ))
                    dan.push(f_name, v)
                    os.system(
                        r'echo "none" > /sys/class/leds/ds:green:wlan/trigger')

            if reConnecting:
                LED_flash(1)
                reConnecting = 0

        except Exception as e:
            print(e)
            LED_flash(0)

            if str(e).find('mac_addr not found:') != -1:
                print('Reg_addr is not found. Try to re-register...')
                reConnection = 1
                device_registration_with_retry()
Example #3
0
    dan.log.info('[cmd] %s, %s', signal, df_list)


def on_register():
    dan.log.info('[da] register successfully')


def on_deregister():
    dan.log.info('[da] register fail')


''' IoTtalk registration '''
context = dan.register(
    IoTtalk_URL,
    on_signal=on_signal,
    on_data=on_data,
    idf_list=idf_list,
    odf_list=odf_list,
    accept_protos=['mqtt'],
    name=device_name,
    #id_=device_addr,
    profile={
        'model': device_model,
        'u_name': username
    },
    on_register=on_register,
    on_deregister=on_deregister)

while True:
    dan.push('Dummy_Sensor', [time.time()])
    time.sleep(0.01)
Example #4
0
context = dan.register(
    IoTtalk_URL,
    on_signal=on_signal,
    on_data=on_data,
    idf_list=idf_list,
    odf_list=odf_list,
    accept_protos=['mqtt'],
    name=device_name,
    #id_=device_addr,
    profile={
        'model': device_model,
        'u_name': username
    },
    on_register=on_register,
    on_deregister=on_deregister)

# Locolization Setting
'''geolocator = Nominatim(user_agent="Google Maps")
location = geolocator.geocode("Taichung, Taiwan")'''

ip_request = requests.get('https://get.geojs.io/v1/ip.json')
my_ip = ip_request.json()['ip']

geo_request_url = 'https://get.geojs.io/v1/ip/geo/' + my_ip + '.json'
geo_request = requests.get(geo_request_url)
geo_data = geo_request.json()

while True:
    #dan.push('Dummy_Sensor', [random.randint(0, 100), geo_data['latitude'], geo_data['longitude']])
    dan.push('Dummy_Sensor', [random.randint(0, 100)])
    time.sleep(time_interval)