forked from computenodes/dragino
-
Notifications
You must be signed in to change notification settings - Fork 3
/
soakTTN.py
62 lines (48 loc) · 1.36 KB
/
soakTTN.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
#!/usr/bin/env python3
"""
Test for dragino module - sends hello world out over LoRaWAN N times
and adheres to a 1% duty cycle
cache.json will be created if it doesn't exist
"""
import logging
from time import sleep
from dragino import Dragino
msg="A"
LOG="testTTN.log"
# add logfile
logLevel=logging.WARNING
logging.basicConfig(filename=LOG, filemode="w", format='%(asctime)s - %(funcName)s - %(lineno)d - %(levelname)s - %(message)s', level=logLevel)
# disbale verbose rports from ipython system
logging.getLogger('parso.cache').disabled=True
logging.getLogger('parso.cache.pickle').disabled=True
# create a Dragino object and join to TTN
D = Dragino("dragino.toml", logging_level=logLevel)
D.join()
print("Waiting for JOIN ACCEPT")
while not D.registered():
print(".",end="")
sleep(2)
print("\nJoined")
# calculate how many transmissions we can
# make per 24 hours
# FUP limits us to 30s per 24h
D.send(msg)
sleep(10)
airTime=D.lastAirTime()
while airTime==0:
D.send(msg)
sleep(10)
airTime=D.lastAirTime()
numTxPer30s=30/airTime
interval=24*60*60/numTxPer30s - airTime # time between transmissions
print(f"tx time {airTime}s interval {interval}")
count=0
while True:
try:
print("count=",count)
count+=1
D.send(msg)
sleep(interval)
except Exception as e:
print(f"Exception {e}")
break