-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpms5003_test.py
76 lines (61 loc) · 1.85 KB
/
pms5003_test.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
67
68
69
70
71
72
73
74
75
76
import machine
# import pms5003
import uasyncio as asyncio
from . import pms5003
loop = asyncio.get_event_loop()
_DEFAULT_MS = 20
pm = None
lock = asyncio.Lock()
async def printit():
pm.print()
import time
async def idle():
while True:
await asyncio.sleep(2)
time.sleep_ms(5)
async def testing():
await asyncio.sleep(120)
while pm._sleeping_state is False:
await asyncio.sleep_ms(100)
print("")
print("")
print("----------------------------------------------------------")
print("")
print("Setting to active mode while sleeping")
print("")
print("----------------------------------------------------------")
print("")
print("")
asyncio.create_task(pm.setActiveMode())
await asyncio.sleep(120)
print("")
print("")
print("----------------------------------------------------------")
print("")
print("Setting to passive mode whithout sleeping with 20s interval")
print("")
print("----------------------------------------------------------")
print("")
print("")
pm.setEcoMode(False)
asyncio.create_task(pm.setPassiveMode(20))
await asyncio.sleep(120)
print("")
print("")
print("----------------------------------------------------------")
print("")
print("Activating EcoMode, interval will be adapted to 60s")
print("")
print("----------------------------------------------------------")
print("")
print("")
pm.setEcoMode(True)
def start():
uart = machine.UART(1, tx=25, rx=26, baudrate=9600)
global pm
pm = pms5003.PMS5003(uart, lock, active_mode=False, interval_passive_mode=60)
pms5003.set_debug(True)
pm.registerCallback(printit)
asyncio.create_task(testing())
asyncio.get_event_loop().run_forever()
start()