-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (48 loc) · 1.29 KB
/
main.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
import sys
import time
from python.fileHandling import RestartService
from python.physical import Button, Leds
from python.web import AccessPoint, WebService
from python.web.mqtt import MqttHandler
def wait():
time.sleep(0.5)
def startConnection() -> bool:
successful = True
try:
mqtt.startConnection()
except:
successful = False
return successful
def handleNormalOperation():
while True:
if button.isPressed():
leds.setGreenOff()
leds.setRedOff()
if not mqtt.isConnected():
leds.setRedOn()
mqtt.publishTemperatureAndPosition()
else:
break
wait()
def handleConfigurationMode():
leds.setGreenOn()
leds.setRedOff()
mqtt.stopConnection()
ap.switchToAccessPoint()
server.start()
while True:
if button.isPressed():
leds.setRedOn()
restartService.restart()
wait()
if __name__ == '__main__':
server = WebService
button = Button.getInstance()
leds = Leds.getInstance()
mqtt = MqttHandler.getInstance()
ap = AccessPoint.getInstance()
restartService = RestartService.getInstance()
status = startConnection()
if status:
handleNormalOperation()
handleConfigurationMode()