-
Notifications
You must be signed in to change notification settings - Fork 475
Description
Hello,
I'm been trying to get my TTGO LoRa32 connected to an AU915 V3 instance of The Things Network following this guide:
https://planb.nicecupoftea.org/2024/04/29/a-lora-lora-laughs/
I can confirm the gateway is configured for V3.
I can't seem to get the LoRa32 to acknowledge/receive the downlink.
I'm getting the error (-1116), which I understand means "No JoinAccept was received - check your keys, or otherwise likely a range issue!". This means the serial never says it is "Ready!". I have never had the LoRa32 connect.
LoRa32 located inside, about 300 metres from a Tektelic gateway mounted on the roof of an approximately 2-story building with a mast. Almost direct line of sight from out of the window.
Given my RSSI in the -90s (see metadata later on), I don't think I'm "overwhelming" the device, but I'll leave that to the experts to make the call.
You may see I have included a line into try and force SF12. I haven't got around to verifying if it is working correctly as it appears transmissions are still occurring at SF10. Even before this line was added, the same issue was occurring.
Source: https://jgromes.github.io/RadioLib/group__status__codes.html
Here is my code:
LoRaWAN_Starter.ino
/*
RadioLib LoRaWAN Starter Example
! Please refer to the included notes to get started !
This example joins a LoRaWAN network and will send
uplink packets. Before you start, you will have to
register your device at https://www.thethingsnetwork.org/
After your device is registered, you can run this example.
The device will join the network and start uploading data.
Running this examples REQUIRES you to check "Resets DevNonces"
on your LoRaWAN dashboard. Refer to the network's
documentation on how to do this.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
For LoRaWAN details, see the wiki page
https://github.com/jgromes/RadioLib/wiki/LoRaWAN
*/
#include "config.h"
void setup() {
Serial.begin(115200);
while(!Serial);
delay(5000); // Give time to switch to the serial monitor
Serial.println(F("\nSetup ... "));
Serial.println(F("Initialise the radio"));
int16_t state = radio.begin();
debug(state != RADIOLIB_ERR_NONE, F("Initialise radio failed"), state, true);
// Set spreading factor to SF12
radio.setSpreadingFactor(12);
// Setup the OTAA session information
state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey);
debug(state != RADIOLIB_ERR_NONE, F("Initialise node failed"), state, true);
Serial.println(F("Join ('login') the LoRaWAN Network"));
state = node.activateOTAA();
debug(state != RADIOLIB_LORAWAN_NEW_SESSION, F("Join failed"), state, true);
Serial.println(F("Ready!\n"));
}
void loop() {
Serial.println(F("Sending uplink"));
// This is the place to gather the sensor inputs
// Instead of reading any real sensor, we just generate some random numbers as example
uint8_t value1 = radio.random(100);
uint16_t value2 = radio.random(2000);
// Build payload byte array
uint8_t uplinkPayload[3];
uplinkPayload[0] = value1;
uplinkPayload[1] = highByte(value2); // See notes for high/lowByte functions
uplinkPayload[2] = lowByte(value2);
// Perform an uplink
int16_t state = node.sendReceive(uplinkPayload, sizeof(uplinkPayload));
debug(state < RADIOLIB_ERR_NONE, F("Error in sendReceive"), state, false);
// Check if a downlink was received
// (state 0 = no downlink, state 1/2 = downlink in window Rx1/Rx2)
if(state > 0) {
Serial.println(F("Received a downlink"));
} else {
Serial.println(F("No downlink received"));
}
Serial.print(F("Next uplink in "));
Serial.print(uplinkIntervalSeconds);
Serial.println(F(" seconds\n"));
// Wait until next uplink - observing legal & TTN FUP constraints
delay(uplinkIntervalSeconds * 1000UL); // delay needs milli-seconds
}
config.h
#ifndef _RADIOLIB_EX_LORAWAN_CONFIG_H
#define _RADIOLIB_EX_LORAWAN_CONFIG_H
#define ARDUINO_TTGO_LORA32_V1
#include <RadioLib.h>
// first you have to set your radio model and pin configuration
// this is provided just as a default example
SX1276 radio = new Module(18, 26, 14, 33);
// if you have RadioBoards (https://github.com/radiolib-org/RadioBoards)
// and are using one of the supported boards, you can do the following:
/*
#define RADIO_BOARD_AUTO
#include <RadioBoards.h>
Radio radio = new RadioModule();
*/
// how often to send an uplink - consider legal & FUP constraints - see notes
const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
// joinEUI - previous versions of LoRaWAN called this AppEUI
// for development purposes you can use all zeros - see wiki for details
#define RADIOLIB_LORAWAN_JOIN_EUI 0x0000000000000000
// the Device EUI & two keys can be generated on the TTN console
#ifndef RADIOLIB_LORAWAN_DEV_EUI // Replace with your Device EUI
#define RADIOLIB_LORAWAN_DEV_EUI 0x70B3D57ED006F85A
#endif
#ifndef RADIOLIB_LORAWAN_APP_KEY // Replace with your App Key
#define RADIOLIB_LORAWAN_APP_KEY 0x11, 0x25, 0x4E, 0x23, 0x83, 0xD5, 0x85, 0x39, 0x87, 0xC4, 0xDA, 0x5B, 0x68, 0xA6, 0x67, 0xA8
#endif
#ifndef RADIOLIB_LORAWAN_NWK_KEY // Put your Nwk Key here
#define RADIOLIB_LORAWAN_NWK_KEY 0xDC, 0xEC, 0x04, 0x77, 0xB0, 0x90, 0x2C, 0x60, 0xF2, 0xA3, 0x40, 0x66, 0x44, 0x4A, 0x91, 0xFB
#endif
// for the curious, the #ifndef blocks allow for automated testing &/or you can
// put your EUI & keys in to your platformio.ini - see wiki for more tips
// regional choices: EU868, US915, AU915, AS923, AS923_2, AS923_3, AS923_4, IN865, KR920, CN500
const LoRaWANBand_t Region = AU915;
const uint8_t subBand = 2; // For US915, change this to 2, otherwise leave on 0
// ============================================================================
// Below is to support the sketch - only make changes if the notes say so ...
// copy over the EUI's & keys in to the something that will not compile if incorrectly formatted
uint64_t joinEUI = RADIOLIB_LORAWAN_JOIN_EUI;
uint64_t devEUI = RADIOLIB_LORAWAN_DEV_EUI;
uint8_t appKey[] = { RADIOLIB_LORAWAN_APP_KEY };
uint8_t nwkKey[] = { RADIOLIB_LORAWAN_NWK_KEY };
// create the LoRaWAN node
LoRaWANNode node(&radio, &Region, subBand);
// result code to text - these are error codes that can be raised when using LoRaWAN
// however, RadioLib has many more - see https://jgromes.github.io/RadioLib/group__status__codes.html for a complete list
String stateDecode(const int16_t result) {
switch (result) {
case RADIOLIB_ERR_NONE:
return "ERR_NONE";
case RADIOLIB_ERR_CHIP_NOT_FOUND:
return "ERR_CHIP_NOT_FOUND";
case RADIOLIB_ERR_PACKET_TOO_LONG:
return "ERR_PACKET_TOO_LONG";
case RADIOLIB_ERR_RX_TIMEOUT:
return "ERR_RX_TIMEOUT";
case RADIOLIB_ERR_CRC_MISMATCH:
return "ERR_CRC_MISMATCH";
case RADIOLIB_ERR_INVALID_BANDWIDTH:
return "ERR_INVALID_BANDWIDTH";
case RADIOLIB_ERR_INVALID_SPREADING_FACTOR:
return "ERR_INVALID_SPREADING_FACTOR";
case RADIOLIB_ERR_INVALID_CODING_RATE:
return "ERR_INVALID_CODING_RATE";
case RADIOLIB_ERR_INVALID_FREQUENCY:
return "ERR_INVALID_FREQUENCY";
case RADIOLIB_ERR_INVALID_OUTPUT_POWER:
return "ERR_INVALID_OUTPUT_POWER";
case RADIOLIB_ERR_NETWORK_NOT_JOINED:
return "RADIOLIB_ERR_NETWORK_NOT_JOINED";
case RADIOLIB_ERR_DOWNLINK_MALFORMED:
return "RADIOLIB_ERR_DOWNLINK_MALFORMED";
case RADIOLIB_ERR_INVALID_REVISION:
return "RADIOLIB_ERR_INVALID_REVISION";
case RADIOLIB_ERR_INVALID_PORT:
return "RADIOLIB_ERR_INVALID_PORT";
case RADIOLIB_ERR_NO_RX_WINDOW:
return "RADIOLIB_ERR_NO_RX_WINDOW";
case RADIOLIB_ERR_INVALID_CID:
return "RADIOLIB_ERR_INVALID_CID";
case RADIOLIB_ERR_UPLINK_UNAVAILABLE:
return "RADIOLIB_ERR_UPLINK_UNAVAILABLE";
case RADIOLIB_ERR_COMMAND_QUEUE_FULL:
return "RADIOLIB_ERR_COMMAND_QUEUE_FULL";
case RADIOLIB_ERR_COMMAND_QUEUE_ITEM_NOT_FOUND:
return "RADIOLIB_ERR_COMMAND_QUEUE_ITEM_NOT_FOUND";
case RADIOLIB_ERR_JOIN_NONCE_INVALID:
return "RADIOLIB_ERR_JOIN_NONCE_INVALID";
case RADIOLIB_ERR_N_FCNT_DOWN_INVALID:
return "RADIOLIB_ERR_N_FCNT_DOWN_INVALID";
case RADIOLIB_ERR_A_FCNT_DOWN_INVALID:
return "RADIOLIB_ERR_A_FCNT_DOWN_INVALID";
case RADIOLIB_ERR_DWELL_TIME_EXCEEDED:
return "RADIOLIB_ERR_DWELL_TIME_EXCEEDED";
case RADIOLIB_ERR_CHECKSUM_MISMATCH:
return "RADIOLIB_ERR_CHECKSUM_MISMATCH";
case RADIOLIB_ERR_NO_JOIN_ACCEPT:
return "RADIOLIB_ERR_NO_JOIN_ACCEPT";
case RADIOLIB_LORAWAN_SESSION_RESTORED:
return "RADIOLIB_LORAWAN_SESSION_RESTORED";
case RADIOLIB_LORAWAN_NEW_SESSION:
return "RADIOLIB_LORAWAN_NEW_SESSION";
case RADIOLIB_ERR_NONCES_DISCARDED:
return "RADIOLIB_ERR_NONCES_DISCARDED";
case RADIOLIB_ERR_SESSION_DISCARDED:
return "RADIOLIB_ERR_SESSION_DISCARDED";
}
return "See https://jgromes.github.io/RadioLib/group__status__codes.html";
}
// helper function to display any issues
void debug(bool failed, const __FlashStringHelper* message, int state, bool halt) {
if(failed) {
Serial.print(message);
Serial.print(" - ");
Serial.print(stateDecode(state));
Serial.print(" (");
Serial.print(state);
Serial.println(")");
while(halt) { delay(1); }
}
}
// helper function to display a byte array
void arrayDump(uint8_t *buffer, uint16_t len) {
for(uint16_t c = 0; c < len; c++) {
char b = buffer[c];
if(b < 0x10) { Serial.print('0'); }
Serial.print(b, HEX);
}
Serial.println();
}
#endif
I consistently get the following output on my serial:
21:09:09.481 -> Setup ...
21:09:09.482 -> Initialise the radio
21:09:09.482 -> Join ('login') the LoRaWAN Network
21:09:19.514 -> Join failed - RADIOLIB_ERR_NO_JOIN_ACCEPT (-1116)
The output in serial monitor are as follows:
21:10:07.349 -> Setup ...
21:10:07.349 -> Initialise the radio
21:10:07.349 -> Join ('login') the LoRaWAN Network
21:10:17.404 -> Join failed - RADIOLIB_ERR_NO_JOIN_ACCEPT (-1116)
The Things Network console shows the following. I'm particularly confused by "Receive join-accept message", because it appears like the LoRa32 can receive a message from the gateway":
Here are the settings for the device in The Things Network console:
Details from "Receive join-request":
{
"name": "ns.up.join.receive",
"time": "2025-03-30T10:40:07.903606591Z",
"identifiers": [
{
"device_ids": {
"device_id": "test-device",
"application_ids": {
"application_id": "ttgo-lora32-sx1276-electronicallye"
},
"dev_eui": "70B3D57ED006F85A",
"join_eui": "0000000000000000"
}
}
],
"data": {
"@type": "type.googleapis.com/ttn.lorawan.v3.UplinkMessage",
"raw_payload": "AAAAAAAAAAAAWvgG0H7Vs3AAAPbhU5E=",
"payload": {
"m_hdr": {},
"mic": "9uFTkQ==",
"join_request_payload": {
"join_eui": "0000000000000000",
"dev_eui": "70B3D57ED006F85A",
"dev_nonce": "0000"
}
},
"settings": {
"data_rate": {
"lora": {
"bandwidth": 125000,
"spreading_factor": 10,
"coding_rate": "4/5"
}
},
"frequency": "917800000",
"timestamp": 3141377716,
"time": "2025-03-30T10:40:07.755Z"
},
"rx_metadata": [
{
"gateway_ids": {
"gateway_id": "eui-647fdafffe00b437",
"eui": "647FDAFFFE00B437"
},
"time": "2025-03-30T10:40:07.755Z",
"timestamp": 3141377716,
"rssi": -95,
"channel_rssi": -95,
"snr": 8.8,
"location": {
"latitude": -34.770833066481295,
"longitude": 138.719783330873,
"source": "SOURCE_REGISTRY"
},
"uplink_token": "CiIKIAoUZXVpLTY0N2ZkYWZmZmUwMGI0MzcSCGR/2v/+ALQ3ELS99tkLGgwIh7+kvwYQ+MivrAMgoN7PxbbACSoMCIe/pL8GEMDFgegC",
"channel_index": 15,
"gps_time": "2025-03-30T10:40:07.755Z",
"received_at": "2025-03-30T10:40:07.842044590Z"
}
],
"received_at": "2025-03-30T10:40:07.899964099Z",
"correlation_ids": [
"gs:uplink:01JQKA6APVM4FEYZT20D6SA64A"
],
"device_channel_index": 13,
"consumed_airtime": "0.370688s"
},
"correlation_ids": [
"gs:uplink:01JQKA6APVM4FEYZT20D6SA64A"
],
"origin": "ip-10-102-7-79.ap-southeast-2.compute.internal",
"context": {
"tenant-id": "CgN0dG4="
},
"visibility": {
"rights": [
"RIGHT_APPLICATION_TRAFFIC_READ"
]
},
"unique_id": "01JQKA6APZ61B8E7FA6CBXWKBG"
}
Following the information in README.md in the LoRaWAN_Starter example folder, I tried 1.0.4 and set the NwkKey to NULL. I get a "MIC mismatch" error and the same -1116 error in serial. This happens on 1.0.2 as well.


Additional Info:
- MCU: TTGO LoRa32 SX1276 V1
- Link to Arduino core: esp32 by Espressif Systems https://github.com/espressif/arduino-esp32 (Board: TTGO LoRa32-OLED)
- Wireless module type: SX1267
- Arduino IDE version: 2.3.4
- Library version: 7.1.2
Any help would be much appreciated. This has got me beat!
Also, I acknowledge I have shared my IDs, but just doing some testing, so will be deleting the application later.