-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0106-777.py
More file actions
65 lines (48 loc) · 1.57 KB
/
Copy path0106-777.py
File metadata and controls
65 lines (48 loc) · 1.57 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import network
import time
from machine import WDT,Timer,ADC
import urequests as requests
def connect():
# enable station interface and connect to WiFi access point
nic = network.WLAN(network.STA_IF)
nic.active(True)
nic.connect('LG-yako', '0911767035')
max_wait = 10
#處理正在連線
while max_wait > 0:
max_wait -= 1
status = nic.status()
if status < 0 or status >=3:
break
print("等待連線")
time.sleep(1)
#沒有wifi的處理
if nic.status() != 3:
#連線失敗,重新開機
#wdt = WDT(timeout=2000)
#wdt.feed()
raise RuntimeError('連線失敗')
else:
print("成功連線")
print(nic.ifconfig())
def alert():
print('要爆炸了!')
response = requests.get('https://hook.eu2.make.com/3mlrqor5qp4guezer4xnuu25m3yn8ndf')
print(help(response))
response.close()
def callback1(t:Timer):
global start
sensor = ADC(4)
vol = sensor.read_u16() * (3.3/65535)
temperature = 27 - (vol-0.706) / 0.001721
print(f'溫度:{temperature}')
delta = time.ticks_diff(time.ticks_ms(), start)
print(delta)
#溫度超過24度,並且發送alert()的時間已經大於60秒
if temperature >= 24 and delta >= 60 * 1000:
alert()
start = time.ticks_ms()#重新設定計時的時間
connect()
start = time.ticks_ms() - 60 * 1000 #應用程式啟動時,計時時間,先減60秒
time1 = Timer()
time1.init(period=1000,callback=callback1)