示例#1
0
def main():
    global datasetid, config, raspi_sid
    f = open('/home/pi/iot.config/raspberry_pi_def.csv', 'r')
    reader = csv.DictReader(f)
    for line in reader:
        config = line
    time.sleep(float(config['init_time']))
    logging.debug("IoT kit Start")

    mode = int(config['mode'])
    if mode == 0:
        logging.debug("`mode` in iot.config is OFF")
        return

    datasetid = config['kvs_datasetid']
    kvs.kvs_server = config['kvs_server']
    raspi_sid = getSerial()

    if config['kvs'] == 'ON':
        Conect = False
        while Conect == False:
            try:
                sendIp()
                Conect = True
            except urllib2.URLError as e:
                time.sleep(1)
                outLog(e)
            except Exception as e:
                outLog(e)
    if config['csv'] == 'ON':
        file_name = '/home/pi/RaspberryPi_list/' + raspi_sid + '_RaspberryPi_list.csv'
        file = open(file_name, 'a')
        ip = commands.getoutput('hostname -I')
        data = ip, time.strftime("%Y/%m/%d %H:%M:%S"), raspi_sid
        writer = csv.writer(file, lineterminator='\n')
        writer.writerow(data)
        file.flush()
        os.fdatasync(file.fileno())
        file.close()

        if config['dropbox'] == 'ON':
            db.send_file(file_name, "Raspberrypi_list", ip="")

    subprocess.Popen(["sudo", "python", "/home/pi/iot_kit/command.py"])

    try:
        if config["twelite"] == "ON":
            subprocess.Popen(["sudo", "python", "/home/pi/iot_kit/twelite.py"])
    except:
        pass

    if config['dropbox'] == 'ON':
        try:
            subprocess.call(["sudo", "rm", "./DB.log"])
        except:
            pass
        subprocess.Popen(
            ["sudo", "python", "/home/pi/iot_kit/db_download.py", raspi_sid])

    if mode == 1:
        logging.debug("Dual Mode")
        if config['screanID'][0:1] == "A":
            thread_1 = threading.Thread(target=screan.GUI, args=(raspi_sid, ))
        elif config['screanID'][0:1] == "B":
            thread_1 = threading.Thread(target=screan.MultiGUI_order,
                                        args=(raspi_sid, ))
        else:
            thread_1 = threading.Thread(target=screan.MultiGUI_ope,
                                        args=(raspi_sid, ))
        thread_2 = threading.Thread(target=create_sensor)
        thread_1.start()
        thread_2.start()
    elif mode == 2:
        logging.debug("GUI Mode")
        if config['screanID'][0:1] == "A":
            screan.GUI(raspi_sid)
        elif config['screanID'][0:1] == "B":
            screan.MultiGUI_order(raspi_sid)
        else:
            screan.MultiGUI_ope(raspi_sid)
    elif mode == 3:
        logging.debug("Sensor Mode")
        create_sensor()
示例#2
0
#cording:utf-8
import time, csv, sys
import db

f = open('/home/pi/iot.config/raspberry_pi_def.csv', 'r')
reader = csv.DictReader(f)
for line in reader:
        config = line

dl = 'ShareMaster'
up = 'sensor_data'

raspi_sid = sys.argv[1]
while True:
	try:
		if config["mode"] != "3": 
			db.get_file(dl, ip="")

		file = raspi_sid+'_'+time.strftime("%Y%m%d")+'.csv'
		db.send_file("/home/pi/data/"+file, up, ip="")
	except Exception as e:
		print(e)
	
	time.sleep(int(config['db_interval']))
#cording:utf-8
import sys, os
import db

ip_dir = ['iot.config', 'command', 'receive_data']
dl_list = ['iot.config', 'iot_kit', 'ShareMaster', 'command']
up_list = {
    'sensor_data': 'data',
    'receive_data': 'senddata',
    'Raspberrypi_list': 'RaspberryPi_list'
}

dir = sys.argv
cont_dir = len(dir) - 1
for i in range(cont_dir):
    if dir[i + 1] in dl_list:
        if dir[i + 1] in ip_dir:
            db.get_file(dir[i + 1])
        else:
            db.get_file(dir[i + 1], ip="")
    elif dir[i + 1] in up_list:
        file_list = os.listdir("/home/pi/" + up_list[dir[i + 1]])
        for file in file_list:
            if dir[i + 1] in ip_dir:
                db.send_file("/home/pi/" + up_list[dir[i + 1]] + "/" + file,
                             dir[i + 1])
            else:
                db.send_file("/home/pi/" + up_list[dir[i + 1]] + "/" + file,
                             dir[i + 1],
                             ip="")
示例#4
0
while True:
    time.sleep(5)
    try:
        if config['dropbox'] == 'ON':
            count += 5
            if count >= int(config['db_interval']):
                count = 0
                db.get_file("command")
                DB = True

        file = open("/home/pi/command/command.txt", "r")
        command_list = file.readlines()
        file.close()

        if "DONE" in command_list[-1]:
            continue

        f = open("/home/pi/command/command.txt", "a")
        f.write("\nDONE " + time.strftime("%Y/%m/%d %H:%M:%S"))
        f.close()

        if DB == True:
            db.send_file("/home/pi/command/command.txt", "command")
            DB = False

        for command in command_list:
            os.system(command)

    except:
        pass
示例#5
0
import csv, os
import db

f = open('/home/pi/iot.config/raspberry_pi_def.csv', 'r')
reader = csv.DictReader(f)
for line in reader:
    config = line

if config['dropbox'] == 'ON':
    ip_list = ['iot.config', 'command', 'receive_data']
    dl_list = ['iot.config', 'ShareMaster', 'iot_kit']
    up_list = {'sensor_data': 'data', 'receive_data': 'senddata'}
    try:
        for dl in dl_list:
            if dl in ip_list:
                db.get_file(dl)
            else:
                db.get_file(dl, ip="")

        for dir in up_list:
            file_list = os.listdir("/home/pi/" + up_list[dir])
            for file in file_list:
                if dir in ip_list:
                    db.send_file("/home/pi/" + up_list[dir] + "/" + file, dir)
                else:
                    db.send_file("/home/pi/" + up_list[dir] + "/" + file,
                                 dir,
                                 ip="")
    except:
        print("error")