-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsmarthouse_temperature_sensor.py
51 lines (30 loc) · 1.06 KB
/
smarthouse_temperature_sensor.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
import logging
import threading
import time
import math
import requests
from messaging import SensorMeasurement
import common
class Sensor:
def __init__(self, did):
self.did = did
self.measurement = SensorMeasurement('0.0')
def simulator(self):
logging.info(f"Sensor {self.did} starting")
while True:
temp = round(math.sin(time.time() / 10) * common.TEMP_RANGE, 1)
logging.info(f"Sensor {self.did}: {temp}")
self.measurement.set_temperature(str(temp))
time.sleep(common.TEMPERATURE_SENSOR_SIMULATOR_SLEEP_TIME)
def client(self):
logging.info(f"Sensor Client {self.did} starting")
# TODO: START
# send temperature to the cloud service with regular intervals
logging.info(f"Client {self.did} finishing")
# TODO: END
def run(self):
pass
# TODO: START
# create and start thread simulating physical temperature sensor
# create and start thread sending temperature to the cloud service
# TODO: END