This repository has been archived by the owner on Aug 13, 2021. It is now read-only.
forked from jeroennijhof/LoRaWAN
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_downlink.py
executable file
·67 lines (48 loc) · 1.7 KB
/
test_downlink.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
#!/usr/bin/env python3
"""
downlink message testing
NOTE: you need to setup a queued downlink message in the TTN console before
running this test.
Downlink messages are only sent for class A devices after an uplink
message is received by TTN.
"""
import logging
from time import sleep,time
import RPi.GPIO as GPIO
from dragino import Dragino
from dragino.LoRaWAN.MHDR import *
GPIO.setwarnings(False)
logLevel=logging.DEBUG
logging.basicConfig(filename="test_downlink.log", format='%(asctime)s - %(funcName)s - %(lineno)d - %(levelname)s - %(message)s', level=logLevel)
logging.info("Starting session")
callbackReceived=False
def downlinkCallback(payload,mtype):
'''
Called by dragino.on_rx_done() when an UNCONF_DATA_DOWN or CONF_DATA_DOWN downlink message arrives.
Scheduling a CONF_DATA_DOW message requires an uplink response which
impacts on the fair use policy. Not recommended!
payload: bytearray
mtype: one of UNCONF_DATA_DOWN or CONF_DATA_DOWN
'''
global callbackReceived
callbackReceived = True
print("downlink message received")
if mtype==MHDR.UNCONF_DATA_DOWN:
print("Received UNCONF_DATA_DOWN payload:",payload)
else:
print("Received CONF_DATA_DOWN payload:",payload)
D = Dragino("dragino.ini", logging_level=logLevel)
D.setDownlinkCallback(downlinkCallback)
D.join()
while not D.registered():
print("Waiting for JOIN_ACCEPT")
sleep(2)
print("Sending a message to prompt for any scheduled downlinks.")
D.send("hello")
print("Waiting for callback message. Press CTRL-C to quit.")
try:
while not callbackReceived:
sleep(2)
except Exception as e:
print("Exception:",e)
print("test_downlink.py Finished")