-
Notifications
You must be signed in to change notification settings - Fork 8
/
temperature_control.py
96 lines (70 loc) · 2.59 KB
/
temperature_control.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""
This example queries the status of the status device
and set and get the temperature in a given temperature type.
Then it changes the set temperature every minute.
"""
import sys
import time
try:
import requests
except ImportError:
print("ERROR! Please install requests library! Run `pip3 install requests` and retry!", file=sys.stderr)
sys.exit(-1)
HEATER_ADDRESS = "10.0.0.176" # Please specify IP address of your device here
def print_device_status():
response = requests.get(url=f'http://{HEATER_ADDRESS}/status')
if response.status_code != 200:
raise Exception(f"Request error! Body={response.text}")
device_status = response.json()
name = device_status['name']
version = device_status['version']
operation_key = device_status['operation_key']
print(f"STATUS:\n"
f" Name = {name}\n"
f" Version = {version}\n"
f" Operation key = {operation_key} \n")
def set_temperature_value_for_type(temperature_type, temperature):
payload = {'type': temperature_type, 'value': temperature}
response = requests.post(url=f'http://{HEATER_ADDRESS}/set-temperature', json=payload, timeout=5)
if response.status_code != 200:
raise Exception(f"Request error! Body={response.text}")
def get_temperature_value_for_temperature_type(temperature_type):
payload = {'type': temperature_type}
response = requests.get(url=f'http://{HEATER_ADDRESS}/set-temperature', json=payload, timeout=5)
if response.status_code != 200:
raise Exception(f"Request error! Body={response.text}")
temperature = response.json()
set_temperature = temperature['value']
print(f"set_temperature = {set_temperature:.2f}\n")
def main():
print_device_status()
target_temperature_type = 'Normal'
for i in range(3):
print('===========')
target_temperature = 15 + i / 2
print(f'Changing the set temperature to {target_temperature:.1f} C...')
set_temperature_value_for_type(temperature_type=target_temperature_type, temperature=target_temperature)
time.sleep(1)
get_temperature_value_for_temperature_type(target_temperature_type)
time.sleep(1)
if __name__ == '__main__':
main()
print('Done!')
'''
EXAMPLE OUTPUT:
STATUS:
Name = panel heater gen. 3
Version = 0x211019
Operation key =
===========
Changing the set temperature to 15.0 C...
set_temperature = 15.00
===========
Changing the set temperature to 15.5 C...
set_temperature = 15.50
===========
Changing the set temperature to 16.0 C...
set_temperature = 16.00
Done!
Process finished with exit code 0
'''