I am using the @jpmeijers RN2483 Arduino Library with an Atmel MEGA328P RN2903 board and am doing some testing to see what the largest payload that I can transmit is.
After some testing I came to realise that I am unable to send to more than 24 bytes, or 11 characters in myLoRa.tx(). If I try to transmit anymore, the board keeps printing that it is transmitting, much quicker it normally does (About half a second versus 3 seconds). No transmission is present in either the TTN console for the device or the gateway. This is due to the RN2903 stating that there is an invalid_data_len
.
This means that the initialisation message in the setup() does not work, which has led me to removing it from any code that I have been using. It also means that the amount of data and be transmitted is much lower than what is possible and permitted with LoRaWAN. For example, if I wanted to send a GPS coordinate, I would not have enough space.
This output from the module is documented in the RN2903 LoRa Technology Module Command Reference User’s Guide. There are two mentions of it in here, one for:
Response after entering the command
and another for:
Response after the uplink transmission
The description is the same, however my error is related to the entering of the command as I believe no transmission is occurring:
invalid_data_len
if application payload length is greater than the maximum application payload length corresponding to the current data rate
In the library I am using, I have specified that I am using AU915, which is initialised the same as US915 as both frequencies use band 2 (channels 8 to 15).
I have also tried turning the ADR on in line 290 as I am using ABP, however that did not change what has been happening.
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"));
}