-
Notifications
You must be signed in to change notification settings - Fork 96
/
CheckModule.ino
73 lines (60 loc) · 1.99 KB
/
CheckModule.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
#include <TheThingsNetwork.h>
// Set your DevAddr, NwkSKey, AppSKey and the frequency plan
const char *devAddr = "00000000";
const char *nwkSKey = "00000000000000000000000000000000";
const char *appSKey = "00000000000000000000000000000000";
#define loraSerial Serial1
#define debugSerial Serial
// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
#define freqPlan REPLACE_ME
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
void setup()
{
loraSerial.begin(57600);
debugSerial.begin(9600);
// Wait a maximum of 10s for Serial Monitor
while (!debugSerial && millis() < 10000)
;
// RN2XX3 reset pin connected to Arduino pin 12
pinMode(12, OUTPUT);
digitalWrite(12, HIGH);
// hard reset module and wait for startup
debugSerial.println("-- CHECK COMM");
ttn.resetHard(12);
delay(100);
// check if a valid module responded
// (if no module is connected or wiring is bad, checkValidModuleConnected() will
// take about ~30s to return (another ~30s if autobaud_first is true))
if(!ttn.checkValidModuleConnected(true))
{
if(ttn.needsHardReset)
{
debugSerial.println("Module unresponsive, please power cycle or hard reset board!");
}
else
{
debugSerial.println("Module unsupported!"); // module must be RN2483, RN2483A, RN2903, RN2903AS
}
while(true) // stop code execution
{
;
}
}
// do an ABP join
debugSerial.println("-- PERSONALIZE");
// false is added as fourth argument to the personalize() call so that it
// does not perform a soft reset, because the module was already hard reset before via pin 12.
ttn.personalize(devAddr, nwkSKey, appSKey, false);
debugSerial.println("-- STATUS");
ttn.showStatus();
}
void loop()
{
debugSerial.println("-- LOOP");
// Prepare payload of 1 byte to indicate LED status
byte payload[1];
payload[0] = (digitalRead(LED_BUILTIN) == HIGH) ? 1 : 0;
// Send it off
ttn.sendBytes(payload, sizeof(payload));
delay(10000);
}