-
Notifications
You must be signed in to change notification settings - Fork 67
/
LoRaWAN_Confirmed.ino
100 lines (89 loc) · 2.74 KB
/
LoRaWAN_Confirmed.ino
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Send a confirmed packet every 10 seconds and print out the ACK/NACK status.
*
* Per default LoRaWAN uses Unconfirmed packets, which of course are subject
* to packet loss. However one can request a confirmation from the gateway.
* The downside is that network bandwidth is used up for the confirmation,
* as well as additional transmissions in case there was no confirmation
* received.
*
*
* In setup() below please replace the argument to LoRaWAN.begin()
* with your appropriate region specific band:
*
* AS923
* AU915
* EU868
* IN865
* KR920
* US915
*
* AU915/US915 networks have 64+8 channels. Typical gateways support only
* 8 (9) channels. Hence it's a good idea to pick the proper channel
* subset via select via LoRaWAN.setSubBand(),
*
* EU868/IN865 have duty cycle restrictions. For debugging it makes sense
* to disable those via setDutyCycle(false);
*
* For an external antenna one should set the proper antenna gain
* (default is 2.0) via setAntennaGain().
*
* Please edit the keys below as they are just debugging samples.
*
*
* This example code is in the public domain.
*/
#include "LoRaWAN.h"
const char *appEui = "0101010101010101";
const char *appKey = "2B7E151628AED2A6ABF7158809CF4F3C";
const char *devEui = "0101010101010101";
void setup( void )
{
Serial.begin(9600);
while (!Serial) { }
LoRaWAN.begin(US915);
// LoRaWAN.setSubBand(2);
// LoRaWAN.setDutyCycle(false);
// LoRaWAN.setAntennaGain(2.0);
LoRaWAN.joinOTAA(appEui, appKey, devEui);
Serial.println("JOIN( )");
}
void loop( void )
{
if (LoRaWAN.joined() && !LoRaWAN.busy())
{
Serial.print("TRANSMIT( ");
Serial.print("TimeOnAir: ");
Serial.print(LoRaWAN.getTimeOnAir());
Serial.print(", NextTxTime: ");
Serial.print(LoRaWAN.getNextTxTime());
Serial.print(", MaxPayloadSize: ");
Serial.print(LoRaWAN.getMaxPayloadSize());
Serial.print(", DR: ");
Serial.print(LoRaWAN.getDataRate());
Serial.print(", TxPower: ");
Serial.print(LoRaWAN.getTxPower(), 1);
Serial.print("dbm, UpLinkCounter: ");
Serial.print(LoRaWAN.getUpLinkCounter());
Serial.print(", DownLinkCounter: ");
Serial.print(LoRaWAN.getDownLinkCounter());
Serial.println(" )");
LoRaWAN.beginPacket();
LoRaWAN.write(0xef);
LoRaWAN.write(0xbe);
LoRaWAN.write(0xad);
LoRaWAN.write(0xde);
LoRaWAN.endPacket(true);
while (LoRaWAN.busy())
{
}
if (LoRaWAN.confirmed())
{
Serial.println("ACK");
}
else
{
Serial.println("NACK");
}
}
delay(10000);
}