Hi everyone,
I am working on a project where I’m trying to connect Seeed’s ESP32-S3 + WIO SX1262 sensor node to a paid LoRaWan 1.0.x network. It’s KPN’s (dutch provider) LoRaWan Network in the Netherlands, they claim nationwide coverage. Connecting is only possible with OTAA. Currently the esp32 is connected to WiFi and sends data from a moisture sensor to Arduino Dashboard. The goal is to get the same functionality, but using LoRa technology, as the nodes will be placed in a field eventually without WiFi connection.
They wanted to use KPN’s LoRaWan due to it’s scalability. No P2P connections to a central hub that forwards thbe packets over IP.
Quick unimportant note you can skip:
To be fair, I don’t have much experience with Arduino/Embedded Systems besides one high school project when I was 16. I got this job because I know a bit of C++. Connecting the ESP32 to the Internet was fine, especially with the wiki. But LoRaWan is a whole different storyMaybe partly because getting correct information from ChatGPT when it comes to LoRaWan is near impossible. So i had to do the research myself.
The community posts here helped me a ton and pointed me in the right direction (shout out PJ_Glasso!), like reading the sx1262 datasheet and the fact that LoRa =/ LoRaWan and that I should use RadioLib and some help with the pinouts. But I still have a few questions and I was hoping the community could help me out :))
The problem
I’m consistently failing to join the network. My code uses RadioLib, which returns the error code -1116
during the node.activateOTAA() step. From my research, I believe this means, the esp32s3 is out of range or it didn’t receive a join accept downlink? Now I am in the netherlands, and I live next to a dyke 5 meters below sea level. That could have something to do with it. I don’t know where KPN’s gateways are.
The part that remains confusing for me is what is being handled by RadioLib and what should be handled by me. I’m pretty sure most of the SPI commands and the order in which they should be executed is being handled by RadioLib.
These questions came to mind:
-
** Is this a range issue? *
-
** Do I miss something in my code? Like setting tx power?*
-
** Did I hard-code something that RadioLib already handles?*
-
** Did I make any mistakes in my setup?*
-
Did I format the DevEUI, JoinEUI, AppKey correctly? I assigned these myself, is that correct?
-
*Is it a power issue? I’m powering the ESP32+sx1262 using the usb port on my laptop/pc. Is this okay to do? *
-
Is it even possible to use the sx1262 for LoRaWan in this way? (Having only the esp32+sx1262, no personal gateways)
-
Is it necessary to both send the uplinks and receive downlinks to start a session? Is that possible with my setup? Can I only send uplinks?
My Code:
Here is the code I’m using for testing the LoRaWan connection. Note: I’m using the pre-configured pinout from the RadioLib Library.
#include <Arduino.h>
#include <RadioLib.h>
// RadioBoards has the B2B pinout of esp32+sx1262
#define RADIO_BOARD_AUTO
#include <RadioBoards.h>
Radio radio = new RadioModule();
// LoRaWAN Credentials + HW COnfig
#define LORA_LDO_EN_PIN 38
// Using placeholder keys for this post.
uint64_t joinEUI = 0x0000000000000000;
uint64_t devEUI = 0x0000000000000000;
// appkey is 120000...
uint8_t appKey[] = {0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t *nwkKey = nullptr;
// configured for EU868
LoRaWANNode node(&radio, &EU868);
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println(F("LoRaWAN OTAA Join Test"));
// Power on the LoRa module
pinMode(LORA_LDO_EN_PIN, OUTPUT);
digitalWrite(LORA_LDO_EN_PIN, HIGH);
delay(500);
// Initialize the radio, this works
Serial.print(F("Init radio.begin()... "));
int16_t state = 0;
state = radio.begin();
if (state != RADIOLIB_ERR_NONE) {
Serial.printf("failed, code %d\n", state);
while (true);
}
Serial.println(F("success!"));
// Start the OTAA join process
Serial.print(F("Attempting to join lorawan network... "));
//Neccessary to do setRfSwitchPins?
radio.setRfSwitchPins(38, RADIOLIB_NC);
// This is the problematic part: always gives -1116
state = node.activateOTAA(joinEUI, devEUI, appKey, nwkKey);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("JOIN SUCCESS!"));
} else {
Serial.printf("failed, code %d\n", state);
Serial.println(F("Check keys, range to gateway, and antenna connection."));
while (true);
}
}
void loop() {
Serial.println(F("LoRaWAN Joined successfully. Sending payload..."));
int state = node.sendReceive((uint8_t*)"Hello!", 6);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.printf("failed, code %d\n", state);
}
}
Thank you so much for taking the time to read this. Any advice or pointers would be incredibly helpful!!
Best regards,
Ary-x86