Esempio n. 1
0
def Print(arg):
    while True:
        try:

            NUM = DAN.pull('HKA_MSG_NUM')
            print(NUM)
            NUM = str(NUM)
            NUM = NUM.replace("[", "")
            NUM = NUM.replace("]", "")
            NUM = NUM.replace("'", "")

            String = DAN.pull('HKA_MSG_STRING')
            print(String)
            String = str(String)
            String = String.replace("[", "")
            String = String.replace("]", "")
            String = String.replace("'", "")

            for userId in user_id_set:
                if NUM != 'None' and String != 'None':
                    line_bot_api.push_message(
                        userId, TextSendMessage(text=NUM + ' 時間: ' +
                                                String))  # Push API example
            time.sleep(0.5)
        except Exception as e:
            print(e)
            if str(e).find('mac_addr not found:') != -1:
                print('Reg_addr is not found. Try to re-register...')
                DAN.device_registration_with_retry(ServerURL, Reg_addr)
            else:
                print('Connection failed due to unknow reasons.')
                time.sleep(1)
Esempio n. 2
0
def receive_frame_from_iottalk():

    #print('start receive frame from iottalk')
    try:
        data = DAN.pull('ODF_Frame')
        if data != None:
            frame_string = data[0]
            person_information = data[1]
            #print(person_information)

            tmp_array = literal_eval(frame_string)
            tmp_boxes = json.loads(person_information)
            #tmp_nparray = np.array(tmp_array)
            #tmp_buf = tmp_nparray.astype('uint8')
            #frame = cv2.imdecode(tmp_buf, 1)
            #cv2.imshow('Receive',frame)
            #cv2.waitKey(1)

            return (tmp_array, tmp_boxes)

    except Exception as e:
        print(e)
        if str(e).find('mac_addr not found:') != -1:
            print('Reg_addr is not found. Try to re-register...')
            DAN.device_registration_with_retry(ServerURL, Reg_addr)
        else:
            print('Connection failed due to unknow reasons.')
            #time.sleep(1)

    #time.sleep(0.2)
    return None
Esempio n. 3
0
def RunDevice():
    ServerURL = 'https://6.iottalk.tw' #with SSL connection
    Reg_addr = 'qwgigfiwffuyhihihrjdn' #if None, Reg_addr = MAC address

    DAN.profile['dm_name']='W0858605_1'
    DAN.profile['df_list']=['AtPressure','Humidity','Windspeed','presentwind','rain','winddirection', 'Temperature-O',
           'WindDirection-O','WindSpeed-O','presentwind-O','Humidity-O','RainFall-O']
#DAN.profile['d_name']= 'Assign a Device Name' 

    DAN.device_registration_with_retry(ServerURL, Reg_addr)
#weather=weather()
#print(weather)
#DAN.deregister()  #if you want to deregister this device, uncomment this line
#exit()            #if you want to deregister this device, uncomment this line
    only=0
    while True:
        try:
            ww=weather()
            print(ww)
        #IDF_data = random.uniform(1, 10)
        #IDF_data = weather
            DAN.push ('AtPressure', ww[0]) #Push data to an input device feature "Dummy_Sensor" #Temperature
            DAN.push ('Humidity', ww[4]) #humidity
            DAN.push ('Windspeed', ww[2][:3]) #風力
            DAN.push ('presentwind', ww[3][:3]) #陣風
            DAN.push ('rain', ww[5])
            DAN.push ('winddirection', ww[1])
            #DAN.push ('MSG-I',ww[0])

        #==================================

        #ODF_data = DAN.pull('Dummy_control')#Pull data from an output device feature "Dummy_Control"
            '''
            Temperature=DAN.pull('Temperature-O')
            WindDirection=DAN.pull('WindDirection-O')
            WindPower=DAN.pull('WindSpeed-O')
            Gust=DAN.pull('presentwind-O')
            Humidity=DAN.pull('Humidity-O')
            Rainfall=DAN.pull('RainFall-O')
            Line_Temp=DAN.pull('MSG-O')
            '''
            #print(Line_Temp)
            #print(Temperature,WindDirection,WindPower,Gust,Humidity,Rainfall)
        #time.sleep(5)
    
        #if ODF_data != None and only!=  ODF_data[0]:
        #    print (ODF_data[0]) ##一維度
        #    only = ODF_data[0]
        except Exception as e:
            print(e)
            if str(e).find('mac_addr not found:') != -1:
                print('Reg_addr is not found. Try to re-register...')
                DAN.device_registration_with_retry(ServerURL, Reg_addr)
            else:
                print('Connection failed due to unknow reasons.')
                time.sleep(1)    
        time.sleep(5)
Esempio n. 4
0
def Push_Activate():
    try:
        IDF_data = 1
        DAN.push('SState_I4', IDF_data)
    except Exception as e:
        print(e)
        if str(e).find('mac_addr not found:') != -1:
            print('Reg_addr is not found. Try to re-register...')
            DAN.device_registration_with_retry(ServerURL, Reg_addr)
        else:
            print('Connection failed due to unknow reasons.')
            time.sleep(1)
    #start few second
    time.sleep(120)
    IDF_data = 0
    DAN.push('SState_I4', IDF_data)
Esempio n. 5
0
def main():
    print(type(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S %p')))
    DAN.profile['dm_name'] = 'SwitchAIO'
    DAN.profile['d_name'] = 'TEST_SwitchAIO'
    DAN.profile['df_list'] = idf_list + odf_list

    open_config(config_name)
    #DAN.profile['d_name']= 'Assign a Device Name'

    DAN.device_registration_with_retry(IOT_ServerURL, Reg_addr)

    t_auto_pull = threading.Thread(target=Auto_pull)
    t_auto_pull.start()

    t_time_control = threading.Thread(target=auto_push_switch)
    t_time_control.start()

    atexit.register(on_exit)

    app.run(host=WEB_HOST, port=WEB_PORT, threaded=True, debug=False)
Esempio n. 6
0
def Iottalk_message():
    while True:
        try:
            value1 = DAN.pull('position')
            if value1 != None:
                nearby = GameInfo.updatePos(value1[0], float(value1[1]),
                                            float(value1[2]))
                if nearby:
                    line_bot_api.push_message(
                        nearby, TextSendMessage(
                            text='Treasure is nearby!!'))  # Push API example

        except Exception as e:
            print(e)
            if str(e).find('mac_addr not found:') != -1:
                print('Reg_addr is not found. Try to re-register...')
                DAN.device_registration_with_retry(ServerURL, Reg_addr)
            else:
                print('Connection failed due to unknow reasons.')
                time.sleep(1)
        time.sleep(0.2)
def send_frame_to_iottalk(buf, boxes):

    #print(type(buf))
    #array = buf.tolist()
    #print(len(buf))
    frame_string = str(buf)
    person_information = json.dumps(boxes)
    #print(person_information)
    #print(data)
    #print(len(data))

    try:
        # @0: string
        # @1: json
        DAN.push('IDF_Frame', frame_string, person_information)
        print('push')
    except Exception as e:
        print(e)
        if str(e).find('mac_addr not found:') != -1:
            print('Reg_addr is not found. Try to re-register...')
            DAN.device_registration_with_retry(ServerURL, Reg_addr)
        else:
            print('Connection failed due to unknow reasons.')
Esempio n. 8
0
def Print(arg):
    while True:
        try:
            Line_Temp = DAN.pull('MSG-O')
            print(Line_Temp)
            Line_Temp = str(Line_Temp)
            Line_Temp = Line_Temp.replace("[", "")
            Line_Temp = Line_Temp.replace("]", "")
            Line_Temp = Line_Temp.replace("'", "")
            for userId in user_id_set:
                if Line_Temp != 'None':
                    line_bot_api.push_message(
                        userId,
                        TextSendMessage(text=Line_Temp))  # Push API example
            time.sleep(10)
        except Exception as e:
            print(e)
            if str(e).find('mac_addr not found:') != -1:
                print('Reg_addr is not found. Try to re-register...')
                DAN.device_registration_with_retry(ServerURL, Reg_addr)
            else:
                print('Connection failed due to unknow reasons.')
                time.sleep(1)
Esempio n. 9
0
# ServerURL = 'http://Your_server_IP_or_DomainName:9999' #with no secure connection
# ServerURL = 'http://192.168.20.101:9999' #with no secure connection
#  注意你用的 IoTtalk 伺服器網址或 IP 
ServerURL = 'https://6.iottalk.tw' #with SSL secure connection
# ServerURL = 'https://Your_DomainName' #with SSL connection  (IP can not be used with https)
Reg_addr = None #if None, Reg_addr = MAC address

mac_addr = 'C86208BD2493'  # put here for easy to modify;;  the mac_addr in DAN.py is NOT used
# Copy DAI.py to DAI2.py and then modify the above mac_addr, then you can have two dummy devices
Reg_addr = mac_addr   # Otherwise, the mac addr generated in DAN.py will always be the same !

DAN.profile['dm_name']='RAY_DUMMY'   # you can change this but should also add the DM in server
DAN.profile['df_list']=['Dummy_Sensor', 'Dummy_Control']
DAN.profile['d_name']='0716230R'
DAN.device_registration_with_retry(ServerURL, Reg_addr)

# global gotInput, theInput
gotInput=False
theInput="haha"
allDead=False

###################################
#doRead read input from user
###################################

def doRead( ):
    global gotInput, theInput, allDead
    while True:
        if gotInput:
           time.sleep(0.1)
Esempio n. 10
0
for t in odf_list:
    if t[0] not in DAN.profile['df_list']:
        DAN.profile['df_list'].append(t[0])

print('Detected features:')
for f_name in DAN.profile['df_list']:
    print('    {}'.format(f_name))
'''def LED_flash(LED_state):
    if LED_state:
        client.put('Reg_done', '1')
        os.system(r'echo "timer" > /sys/class/leds/ds:green:usb/trigger')      #For ArduinoYun Only. LED Blink.
    else:
        client.put('Reg_done', '0')
        os.system(r'echo "none" > /sys/class/leds/ds:green:usb/trigger')
'''
DAN.device_registration_with_retry(custom.ServerIP)
'''LED_flash(1)'''

incomming = {}
for f_name in [t[0] for t in odf_list]:
    incomming[f_name] = 0

reConnecting = 0
while True:
    try:
        cache = {}
        check_list = [t[0] for t in odf_list]
        for f_name, index, pin_name in odf_list:
            if f_name not in cache.keys():
                os.system(
                    r'echo "default-on" > /sys/class/leds/ds:green:wlan/trigger'
Esempio n. 11
0
        DAN.profile['df_list'].append(t[0])

print('Detected features:')
for f_name in DAN.profile['df_list']:
    print('    {}'.format(f_name))


def LED_flash(LED_state):
    if LED_state:
        client.put('Reg_done', '1')
        os.system(r'echo "timer" > /sys/class/leds/arduino:white:usb/trigger')      #For ArduinoYun Only. LED Blink.
    else:
        client.put('Reg_done', '0')
        os.system(r'echo "none" > /sys/class/leds/arduino:white:usb/trigger')

DAN.device_registration_with_retry(custom.ServerIP)
LED_flash(1)

incomming = {}
for f_name in [t[0] for t in odf_list]:
    incomming[f_name] = 0

reConnecting = 0
while True:
    try:
        cache = {}
	check_list=[t[0] for t in odf_list]
	for f_name, index, pin_name in odf_list:

            if f_name not in cache.keys():
                os.system(r'echo "default-on" > /sys/class/leds/arduino:blue:wlan/trigger')
Esempio n. 12
0
custom.profile_init()
odf_list = custom.odf()
idf_list = custom.idf()

DAN.profile['df_list'] = [t[0] for t in idf_list]

for t in odf_list:
    if t[0] not in DAN.profile['df_list']:
        DAN.profile['df_list'].append(t[0])

print('Detected features:')
for f_name in DAN.profile['df_list']:
    print('    {}'.format(f_name))

DAN.device_registration_with_retry()

BridgeClient().put('Reg_done', '1')

incomming = {}
for f_name in [t[0] for t in odf_list]:
    incomming[f_name] = 0

while True:
    try:
        cache = {}
        check_list = [t[0] for t in odf_list]
        for f_name, index, pin_name in odf_list:

            if f_name not in cache.keys():
                PIN = DAN.pull(f_name)
Esempio n. 13
0
def run():
    global current_x, current_y, current_z, x, y, z
    while True:
        start = time.time()
        x, y, z = get_gyro()
        x -= benchmark_x
        y -= benchmark_y
        z -= benchmark_z
        calibrate = int(GPIO.input(Calibrate) == GPIO.LOW)
        add_speed = int(GPIO.input(Speed_Up) == GPIO.LOW)
        minus_speed = int(GPIO.input(Speed_Down) == GPIO.LOW)
        if x <= 3 and x >= -3:
            x = 0
        if y <= 3 and y >= -3:
            y = 0
        if z <= 3 and z >= -3:
            z = 0
        current_x += (x * 0.1)
        current_y += (y * 0.1)
        current_z += (z * 0.1)
        sign_x = int(current_x > 0)
        sign_y = int(current_y > 0)
        sign_z = int(current_z > 0)
        if current_x < 0:
            x = -1 * current_x
        else:
            x = current_x
        if current_y < 0:
            y = -1 * current_y
        else:
            y = current_y
        if current_z < 0:
            z = -1 * current_z
        else:
            z = current_z
        # msg = format(int(gear), '01b') + format(int(calibrate), '01b') + format(int(terminate), '01b') + format(int(add_speed), '01b') + format(int(minus_speed), '01b') + format(int(current_flap), '03b') + format(int(sign_x), '01b') + format(int(x), '013b') + format(int(sign_y), '01b') + format(int(y), '013b') + format(int(sign_z), '01b') + format(int(z), '013b')

        try:
            DAN.push('add_speed', add_speed)
            DAN.push('calibrate', calibrate)
            DAN.push('current_flap', current_flap)
            DAN.push('gear', gear)
            DAN.push('minus_speed', minus_speed)
            DAN.push('sign_x', sign_x)
            DAN.push('sign_y', sign_y)
            DAN.push('sign_z', sign_z)
            DAN.push('terminate', terminate)
            DAN.push('x', x)
            DAN.push('y', y)
            DAN.push('z', z)

        except Exception as e:
            print(e)
            if str(e).find('mac_addr not found:') != -1:
                print('Reg_addr is not found. Try to re-register...')
                DAN.device_registration_with_retry(ServerURL, Reg_addr)
            else:
                print('Connection failed due to unknow reasons.')

        if terminate == 1:
            GPIO.cleanup()
            sys.exit(1)
        time_past = time.time() - start
        time_to_sleep = 0.1 - time_past
        if time_to_sleep > 0:
            time.sleep(time_to_sleep)
Esempio n. 14
0
def on_exit():
    # DAN.deregister()
    return


@app.route('/')
def main_page():
    return render_template('index.html')


@app.route('/<df>', methods=['POST'])
def get_push(df):
    data = request.json
    print(data)
    DAN.push(df, data)
    return '', 200


if '__main__' == __name__:
    DAN.profile = env_config.ctlboard_profile
    DAN.device_registration_with_retry(env_config.server_ip,
                                       env_config.mac_addr)

    atexit.register(on_exit)

    app.run(host=env_config.host,
            port=env_config.port,
            threaded=True,
            debug=True)
import IDA
import subprocess
import msvcrt  #Windows only
import threading
import os
import pyautogui as pygui
import sys
import random

DAN.profile['dm_name'] = 'KAI_OUT'
DAN.profile['d_name'] = 'kai'
DAN.profile['df_list'] = [
    'KAI_OUT0', 'KAI_OUT1', 'KAI_OUT2', 'KAI_OUT3', 'KAI_OUT4', 'KAI_OUT5',
    'KAI_OUT6', 'KAI_OUT7', 'KAI_OUT8', 'KAI_OUT_MODE', 'KAI_OUT_IDF'
]
DAN.device_registration_with_retry('140.113.199.249')

# ifSound
sound = 0

# play Mode
mode = 0


# OPEN EXE
def openPicman():
    process = subprocess.Popen('./game/picman.exe')
    time.sleep(1)
    #library:pyautogui
    IDA.press('tab')
    IDA.press('enter')