-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
43 lines (36 loc) · 1.45 KB
/
test.py
File metadata and controls
43 lines (36 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from pyfirmata import *
import time
import hardware
import json
seri = serial.Serial(baudrate=9600,timeout=None, port = 'COM6') #시리얼 포트 설정
print("Serial name" + seri.name)#시리얼 포트 이름 출력
res = []
def get():
time.sleep(2)
for i in range(0, 8):
seri.write('g'.encode()) #시리얼 포트에 데이터 전송
con = seri.readline() #시리얼 포트에서 데이터 수신
con = con[:len(con)-1].decode().replace('\r', '')
res.append(con)
print(con)
get()
print(res)
def hardware_info():
content = get()
info = {
"id" : "A1B2C3", #FARMSELT Model Name
"soilEc" : float(content[0]), #Soil EC Sensor Value
"soilTemp" : float(content[1]),#Soil Temperature Sensor Value
"soilHum" : float(content[2]), #Soil Humidity Sensor Value
"airTemp" : float(content[3]), #Air Temperature Sensor Value
"airHum" : float(content[4]), #Air Humidity Sensor Value
"solar" : int(content[5]), #Sunlight Sensor Value
"uptime":hardware.uptime_info,#hardware.uptime_info()
"latitude": content[6], #Hardware GPS Sendsor Value
"longitude":content[7], #Hardware GPS Sendsor Value
"speed":hardware.network_speed_test(),#hardware.network_speed_test()
"ping": hardware.ping(),#hardware.ping_test()
"bettery":hardware.hardware_voltage()#hardware.bettery_info()
}
return json.dumps(info)
#print(hardware_info())