Commit b5602872 authored by joliu's avatar joliu

分布式物联网控制器终端

parent d3d66520
from controler import execute
import sys
if len(sys.argv) != 3:
print("Usage: port database_name")
exit(0)
cmd = "controller&show&%s" % sys.argv[2]
execute(int(sys.argv[1]), cmd)
import subprocess
import pymysql
def Print(msg):
print(msg)
def Input():
print("\033[1;35mopencps $ \033[0m", end='')
return input()
command_list = subprocess.getoutput('cd bin && ls *.py').split('\n')
command_list = subprocess.getoutput('cd opencps && ls *.py').split('\n')
commands = [x.split('.')[0] for x in command_list if x != 'controler.py']
while True:
......@@ -24,11 +25,16 @@ while True:
Print('Illegal Command!')
continue
else:
'''
c_list = cmd.split(' ')
run_commands = "python3 "
c_list[0] = 'bin/' + c_list[0] + '.py'
c_list[0] = 'opencps/' + c_list[0] + '.py'
c_list = ['python'] + c_list
subprocess.call((c_list))
'''
c_list = cmd.split(' ')
run_commands = "cd opencps&&python3 " + c_list[0] + '.py '
for i in range(1, len(c_list)):
run_commands = run_commands + c_list[i] + ' '
print(subprocess.getoutput(run_commands))
......@@ -8,7 +8,15 @@ def execute(port, message):
s.connect(("192.168.12.19", port))
s.sendall(message.encode())
response = s.recv(1024).decode()
print(response)
return json.loads(response)
def Print(data):
print(format(data, "<20"), end='')
def PrintTitle(title):
for t in title:
Print(t)
print('')
import pymysql
def showDevice():
output = ''
try:
sql = 'select * from deviceinfo'
conn = pymysql.connect(host='127.0.0.1', port=12306, user='root', passwd='Vudo3423', db='HiDockerwifi', charset='utf8')
cur = conn.cursor()
cur.execute(sql)
output = cur.fetchall()
#print(output)
except pymysql.Error as err_msg:
print(err_msg)
except Exception as err_msg:
print(err_msg)
finally:
cur.close()
conn.close()
return output
if __name__ == "__main__":
device_data = showDevice()
print(format("deviceID", "<20"), format("IP", "<20"), format("status", "<20"), format("network status"))
for device in device_data:
if device[3] == 1:
status = 'on-line'
else:
status = 'off-line'
#print("%s\t\t%s\t%s\t%s" % (device[1], device[2], status, device[4]))
print(format(device[1], "<20"), format(device[2], "<20"), format(status, "<20"), format(device[4]))
from controler import execute
import sys
import pymysql
import json
def findDevicePort(deviceID):
output = ''
try:
sql = 'select port from portdb where equip="%s"' % deviceID
conn = pymysql.connect(host='127.0.0.1', port=12306, user='root', passwd='Vudo3423', db='HiDockerwifi', charset='utf8')
cur = conn.cursor()
cur.execute(sql)
output = cur.fetchone()
#print(output)
except pymysql.Error as err_msg:
print(err_msg)
except Exception as err_msg:
print(err_msg)
finally:
cur.close()
conn.close()
return output
def Print(data):
print(format(data, "<20"), end='')
def PrintTitle(title):
for t in title:
Print(t)
print('')
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: nodeID database_name")
exit(0)
port = findDevicePort(sys.argv[1])[0]
cmd = "controller&show&%s" % sys.argv[2]
(status, output) = execute(port, cmd)
if status == 0:
print("can't find this database, please check your input")
if sys.argv[2] == 'datacach':
output = json.loads(output)
title_list = ['DeviceID', 'Data', 'Updata Time', 'Status']
PrintTitle(title_list)
if output == []:
output = None
else:
for items in output:
items.remove(items[0])
for item in items:
Print(item)
print('')
elif sys.argv[2] == 'decide':
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment