Skip to content

Commit

Permalink
Merge pull request #58 from BeelanMX/DownlinkTimingFix
Browse files Browse the repository at this point in the history
Downlink timing fix
  • Loading branch information
wero1414 committed Jul 9, 2021
2 parents cb26dd8 + 9ab0afd commit aff67a8
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 269 deletions.
75 changes: 75 additions & 0 deletions examples/class-C-ABP/class_c_ABP/class_c_ABP.ino
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();
}
71 changes: 71 additions & 0 deletions examples/class-C-ABP/serialToLoRaWAN/serialToLoRaWAN.ino
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();
}
4 changes: 2 additions & 2 deletions src/arduino-rfm/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#ifdef US_915
//Select the subband youre working on
// make sure your gateway is working in one of these bands
//#define SUBND_0 // 902.3 - 903.7 Mhz
#define SUBND_1 // 903.9 - 905.3 Mhz TTN
#define SUBND_0 // 902.3 - 903.7 Mhz
//#define SUBND_1 // 903.9 - 905.3 Mhz TTN
//#define SUBND_2 // 905.5 - 906.9 Mhz
//#define SUBND_3 // 907.1 - 908.5 Mhz
//#define SUBND_4 // 908.7 - 910.1 Mhz
Expand Down
Loading

0 comments on commit aff67a8

Please sign in to comment.