<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Temperature</title>
</head>
<frameset rows="50, 50" cols="50, 50">
<frame src="http://127.0.0.1:34242" name="frame1" noresize>
<frame src="http://127.0.0.1:34242" name="frame2" noresize>
<frame src="http://127.0.0.1:34242" name="frame3" noresize>
<frame src="http://127.0.0.1:34242" name="frame4" noresize>
</frameset>
</html>
{
"sensors": [
{
"id": "/DS18B20/20323939554B43120010800A",
"max": 125,
"min": -55,
"serial": "20323939554B43120010800A",
"state": 0,
"type": "DS18B20",
"unit": "℃",
"value": 25.5
}
],
"timestamp": 1528660156476
}
{
"sensors": [
{
"alias": "TEST-2080-H",
"id": "/HDC2080/20313337584D430100290008",
"max": 125,
"min": -40,
"serial": "20313337584D430100290008",
"state": 0,
"type": "HDC2080",
"unit": "℃",
"value": 28.13
},
{
"alias": "TEST-2080-H",
"id": "/HDC2080_RH/20313337584D430100290008",
"max": 100,
"min": 0,
"serial": "20313337584D430100290008",
"state": 2,
"type": "HDC2080_RH",
"unit": "%",
"value": 26.86
}
],
"timestamp": 1539980752561,
"version": "1.0.1"
}
Запрос:
~G
Ответ:
~G25.0
где 25.0 - текущая температуры термодатчика
Запрос:
~W1000
Ответ:
~F1000
~G24.0
~G24.0
...
echo "~W1000" > /dev/ttyACM0
cat USBPORT | sed 's/~G//' | socat - udp-sendto:127.0.0.1:5000
cat USBPORT | sed 's/~G//' | { read temp; if [[ $(echo $temp'>30' | bc -l) -ne 0 ]]; then echo 'Overtemp'; else echo 'Normal'; fi; }
Запрос:
~W0
Ответ:
~F0
#!/usr/bin/python3
'''
Example:
python3 ./odtemp-test.py
'''
from time import sleep
import serial
def run():
port = '/dev/ttyACM0'
ser = serial.Serial(port)
while True:
ser.write(b'~G')
ser_data = ser.readline()
if ser_data:
data = ser_data.decode("utf-8")
print('Read from serial (repl to ~G): {0}'.format(data.strip()))
if data.startswith('~G'):
print('Temperature is {0}'.format(float(data[2:])))
else:
print('sensor error')
sleep(1)
if __name__ == "__main__":
run()