-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve handling of needsHardReset flag and add method to check valid…
… module connected to serial port (#282) * Removed reset of needsHardReset flag in reset() function. Added checkValidModuleConnected() to check for correct wiring and supported module. Added getVersion to obtain response of sys get ver. Updated documentation. Added CheckModule example to showcase usage of checkValidModuleConnected(). * Updated naming scheme to match TTN camelCase convention
- Loading branch information
1 parent
c5d62cf
commit 4eb8762
Showing
4 changed files
with
170 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters