-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from BeelanMX/DownlinkTimingFix
Downlink timing fix
- Loading branch information
Showing
6 changed files
with
418 additions
and
269 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <lorawan.h> | ||
|
||
//ABP Credentials | ||
const char *devAddr = "00000000"; | ||
const char *nwkSKey = "00000000000000000000000000000000"; | ||
const char *appSKey = "00000000000000000000000000000000"; | ||
|
||
const unsigned long interval = 20000; // 10 s interval to send message | ||
unsigned long previousMillis = 0; // will store last time message sent | ||
unsigned int counter = 0; // message counter | ||
|
||
char myStr[50]; | ||
char outStr[255]; | ||
byte recvStatus = 0; | ||
|
||
const sRFM_pins RFM_pins = { | ||
.CS = 6, | ||
.RST = 7, | ||
.DIO0 = 8, | ||
.DIO1 = 9, | ||
.DIO2 = -1, | ||
.DIO5 = -1, | ||
}; | ||
|
||
|
||
void setup() { | ||
// Setup loraid access | ||
Serial.begin(115200); | ||
delay(5000); | ||
Serial.println("Start.."); | ||
if(!lora.init()){ | ||
Serial.println("RFM95 not detected"); | ||
delay(5000); | ||
return; | ||
} | ||
|
||
// Set LoRaWAN Class change CLASS_A or CLASS_C | ||
lora.setDeviceClass(CLASS_C); | ||
|
||
// Set Data Rate | ||
lora.setDataRate(SF7BW125); | ||
|
||
// set channel to random | ||
lora.setChannel(MULTI); | ||
|
||
// Put ABP Key and DevAddress here | ||
lora.setNwkSKey(nwkSKey); | ||
lora.setAppSKey(appSKey); | ||
lora.setDevAddr(devAddr); | ||
} | ||
|
||
void loop() { | ||
|
||
// Check interval overflow | ||
if(millis() - previousMillis > interval) { | ||
previousMillis = millis(); | ||
|
||
sprintf(myStr, "Counter-%d", counter); | ||
|
||
Serial.print("Sending: "); | ||
Serial.println(myStr); | ||
|
||
lora.sendUplink(myStr, strlen(myStr), 0, 1); | ||
counter++; | ||
} | ||
|
||
recvStatus = lora.readData(outStr); | ||
if(recvStatus) { | ||
Serial.print("====>> "); | ||
Serial.println(outStr); | ||
} | ||
|
||
// Check Lora RX | ||
lora.update(); | ||
} |
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,71 @@ | ||
#include <lorawan.h> | ||
|
||
//ABP Credentials | ||
const char *devAddr = "00000000"; | ||
const char *nwkSKey = "00000000000000000000000000000000"; | ||
const char *appSKey = "00000000000000000000000000000000"; | ||
|
||
char myStr[240]; | ||
char outStr[255]; | ||
byte recvStatus = 0; | ||
|
||
const sRFM_pins RFM_pins = { | ||
.CS = 6, | ||
.RST = 7, | ||
.DIO0 = 8, | ||
.DIO1 = 9, | ||
.DIO2 = -1, | ||
.DIO5 = -1, | ||
}; | ||
|
||
|
||
void setup() { | ||
// Setup loraid access | ||
Serial.begin(115200); | ||
Serial.println("Start.."); | ||
if(!lora.init()){ | ||
Serial.println("RFM95 not detected"); | ||
delay(5000); | ||
return; | ||
} | ||
|
||
// Set LoRaWAN Class change CLASS_A or CLASS_C | ||
lora.setDeviceClass(CLASS_C); | ||
|
||
// Set Data Rate | ||
lora.setDataRate(SF7BW125); | ||
|
||
// set channel to random | ||
lora.setChannel(MULTI); | ||
|
||
// Put ABP Key and DevAddress here | ||
lora.setNwkSKey(nwkSKey); | ||
lora.setAppSKey(appSKey); | ||
lora.setDevAddr(devAddr); | ||
} | ||
|
||
void loop() { | ||
|
||
if(Serial.available()){ | ||
uint8_t i = 0; | ||
while(Serial.available()>0){ | ||
myStr[i++]=Serial.read(); | ||
if(i>240){ | ||
Serial.println("[ERROR] payload maximo alcanzado"); | ||
break; | ||
} | ||
} | ||
Serial.print("Uplink: "); | ||
Serial.println(myStr); | ||
lora.sendUplink(myStr, strlen(myStr), 0, 1); | ||
} | ||
|
||
recvStatus = lora.readData(outStr); | ||
if(recvStatus) { | ||
Serial.print("Downlink: "); | ||
Serial.println(outStr); | ||
} | ||
|
||
// Check Lora RX | ||
lora.update(); | ||
} |
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
Oops, something went wrong.