This repository has been archived by the owner on Apr 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwake.py
66 lines (51 loc) · 1.91 KB
/
wake.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
# GNU General Public License <https://www.gnu.org/licenses>
# STIA436 Course - Spring 2019
# Professor Colin McCormick & Father Chris Wagner
# Copyright (c) 2019 F. Pascal Girard
#
# Code improvement suggestions:
# 1. how about one post to submit all new data? C'mon Adafruit
#
# Don't forget to enable A0 battery as well as sleep (16 & Reset) - solder!
import config
import machine
import sleep
sleep_interval = config.SLEEP
def main():
import utime # ESP stuff
# Version 905 sensors has BME280, BME680 & PMS-A003 sensors - comment this line for stub.py
from sensors.tphg import tphg
from sensors.tph import tph
from sensors.pm25 import pm25
# from sensors import stub # when no sensors are attached.
import iot # IOT networking
start_time = utime.ticks_ms() # let's track runtime (for measuring current usage)
aq = {}
id = machine.unique_id()
chipId = "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}".format(
id[0], id[1], id[2], id[3], id[4], id[5]
) # make each sensor its own group
# aq.update(analog.measure())
# aq.update(dht11.measure())
# aq.update(enviro.measure())
# aq.update(ppd42.measure())
tph_1 = tph(22, 21)
aq.update(tph_1.measure())
try:
tphg_1 = tphg(22, 21)
aq.update(tphg_1.measure())
except OSError as e:
print("TPHG OS error: {0}".format(e))
#aq.update(stub.measure()) # when you only want the MCU and no sensors.
# for reasons I can't explain, UART takes time to setup - so do this last? WTF.
pm25_1 = pm25(1, 26, 27)
pm25_2 = pm25(2, 0, 2)
aq.update(pm25_1.measure())
aq.update(pm25_2.measure())
iot.init_ap(False)
iot.init_sta(True)
# Now let's post all
iot.io_post(chipId, aq)
# iot.io_post({"runtime": ((utime.ticks_ms() - start_time)/1000)})
print("Runtime is:", (utime.ticks_ms() - start_time) / 1000)
sleep.init(sleep_interval) # see you later!