File tree 1 file changed +5
-13
lines changed
1 file changed +5
-13
lines changed Original file line number Diff line number Diff line change 9
9
import json
10
10
import alarm
11
11
import board
12
- import busio
13
12
import socketpool
14
13
import wifi
15
14
import adafruit_minimqtt .adafruit_minimqtt as MQTT
16
15
import adafruit_shtc3
17
16
18
- sht = adafruit_shtc3 .SHTC3 (busio .I2C (board .SCL , board .SDA ))
19
17
PUBLISH_DELAY = 60
20
18
MQTT_TOPIC = "state/temp-sensor"
21
- USE_DEEP_SLEEP = False
19
+ USE_DEEP_SLEEP = True
20
+
21
+ # Connect to the Sensor
22
+ sht = adafruit_shtc3 .SHTC3 (board .I2C ())
22
23
23
24
# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
24
25
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
30
31
print ("WiFi secrets are kept in secrets.py, please add them there!" )
31
32
raise
32
33
33
- print ("Connecting to %s" % secrets ["ssid" ])
34
34
wifi .radio .connect (secrets ["ssid" ], secrets ["password" ])
35
35
print ("Connected to %s!" % secrets ["ssid" ])
36
36
37
-
38
- ### Secrets File Setup ###
39
- try :
40
- from secrets import secrets
41
- except ImportError :
42
- print ("Connection secrets are kept in secrets.py, please add them there!" )
43
- raise
44
-
45
37
# Create a socket pool
46
38
pool = socketpool .SocketPool (wifi .radio )
47
39
68
60
69
61
print ("Publishing to %s" % MQTT_TOPIC )
70
62
mqtt_client .publish (MQTT_TOPIC , json .dumps (output ))
71
- last_update = time .monotonic ()
72
63
73
64
if USE_DEEP_SLEEP :
74
65
mqtt_client .disconnect ()
75
66
pause = alarm .time .TimeAlarm (monotonic_time = time .monotonic () + PUBLISH_DELAY )
76
67
alarm .exit_and_deep_sleep_until_alarms (pause )
77
68
else :
69
+ last_update = time .monotonic ()
78
70
while time .monotonic () < last_update + PUBLISH_DELAY :
79
71
mqtt_client .loop ()
You can’t perform that action at this time.
0 commit comments