I am using the @jpmeijers RN2483 Arduino Library and am trying the get OTAA to work successfully with a custom Atmel MEGA328P RN2903 board. I have had this device work successfully with ABP resulting in a join and over 5000 transmissions, which means that there is nothing wrong with range, antennas, my packets, etc.
I am using a slightly adjusted code based heavily ArduinoUnoNano-basic.ino which allows the board to operate successfully in Australia.
My code is as follows:
#include <rn2xx3.h>
#include <AltSoftSerial.h>
AltSoftSerial mySerial;
// create an instance of the rn2xx3 library,
// giving the software serial as port to use
rn2xx3 myLora(mySerial);
// the setup routine runs once when you press reset:
void setup()
{
// open serial communications and wait for port to open:
Serial.begin(57600); //serial port to computer
mySerial.begin(9600); //serial port to radio
Serial.println("It's start'n up mate!");
initialize_radio();
myLora.sendRawCommand(F("sys set pindig GPIO0 1"));
led_on();
// setting the frequency plan to AU915
myLora.setFrequencyPlan(TTN_US);
led_off();
delay(2000);
}
void initialize_radio()
{
//reset rn2483
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
delay(500);
digitalWrite(12, HIGH);
delay(100); //wait for the RN2xx3's startup message
mySerial.flush();
// autobaud the rn2483 module to 9600. The default would otherwise be 57600.
myLora.autobaud();
// check communication with radio
String hweui = myLora.hweui();
while(hweui.length() != 16)
{
Serial.println("Communication with RN2xx3 unsuccessful. Start that baby right up again.");
Serial.println(hweui);
delay(10000);
hweui = myLora.hweui();
}
// Setting the frequency plan to AU915
myLora.setFrequencyPlan(TTN_US);
// print out the HWEUI so that we can register it via ttnctl
Serial.println("When using OTAA, register this DevEUI: ");
Serial.println(myLora.hweui());
Serial.println("RN2xx3 firmware version:");
Serial.println(myLora.sysver());
// configure your keys and join the network
Serial.println("Trying to join TTN");
bool join_result = false;
/*
* ABP: initABP(String addr, String AppSKey, String NwkSKey);
* Paste the example code from the TTN console here:
*/
// const char *devAddr = "KEY";
// const char *nwkSKey = "KEY";
// const char *appSKey = "KEY";
//
// join_result = myLora.initABP(devAddr, appSKey, nwkSKey);
/*
* OTAA: initOTAA(String AppEUI, String AppKey);
* If you are using OTAA, paste the example code from the TTN console here:
*/
const char *appEui = "KEY";
const char *appKey = "KEY";
join_result = myLora.initOTAA(appEui, appKey);
while(!join_result)
{
Serial.println("Unable to join. Are your keys correct and are you in the middle of the outback?");
delay(30000); //delay a minute before retry
join_result = myLora.init();
}
Serial.println("Successfully joined TTN. You beauty!");
// Setting the frequency plan to TTN_AU. Not needed for OTAA.
myLora.setFrequencyPlan(TTN_US);
}
// the loop routine runs over and over again forever:
void loop()
{
led_on();
Serial.println("TXing");
myLora.tx("Testing");
led_off();
delay(200);
}
void led_on()
{
myLora.sendRawCommand(F("sys set pindig GPIO10 1"));
}
void led_off()
{
myLora.sendRawCommand(F("sys set pindig GPIO10 0"));
}
The credentials I have entered in the TTN console are identical to those in the code and I have also checked to make sure that the Hardware EUI/Device EUI printed in the serial monitor when starting up the board is the same.
When I do an OTAA join, I can see a join request in my gateway’s console but nothing appears in the application or device console. In the device console I have also tested this with and without Frame Counter Checks and the same thing occurs. Below is an output from the console of my gateway:
The two payloads are identical for both transmissions. Putting this output in the LoRaWAN 1.0.x packet decoder shows the following:
Assuming hex-encoded packet
00F45201D07ED5B370CCFA23000BA304000F71A146E9E0
Message Type = Join Request
PHYPayload = 00F45201D07ED5B370CCFA23000BA304000F71A146E9E0
( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
MHDR = 00
MACPayload = F45201D07ED5B370CCFA23000BA304000F71
MIC = A146E9E0
( MACPayload = AppEUI[8] | DevEUI[8] | DevNonce[2] )
AppEUI = 70B3D57ED00152F4
DevEUI = 0004A30B0023FACC
DevNonce = 710F
I have also done some troubleshooting within the library and in rn2xx3.cpp and on line 206 when receivedData is read, the output is denied
if I do Serial.println(receivedData);
.
I did some research and people have faced this issue before, but not using this library or a similar setup.
If anyone had a suggestion or a way to solve this, I would appreciate it.