jgromes / RadioLib

Universal wireless communication library for embedded devices
https://jgromes.github.io/RadioLib/
MIT License
1.59k stars 396 forks source link

LLCC68 LoRaWAN failed with -1106 and -9 #985

Closed lioff closed 9 months ago

lioff commented 9 months ago

Describe the bug I am using the LoRaWAN example with an LLCC68 on EU868. However, beginOTAA fails during checkADB. It seems to be related to the limited supported SF of LLCC68.

See output:

18:43:14.225 -> [Radio] Initializing ... 
18:43:14.225 -> RadioLib Debug Info
18:43:14.226 -> Version:  6.4.2.0
18:43:14.226 -> Platform: ESP32
18:43:14.226 -> Compiled: Feb 26 2024 18:42:26
18:43:14.226 -> 
18:43:14.226 -> CMDW    80  
18:43:14.226 -> SI  0   
18:43:14.226 -> SO  A2  
18:43:14.226 -> CMDR    C0  
18:43:14.226 -> SI  0   
18:43:14.258 -> SO  22  
18:43:14.258 -> CMDR    1D  3   20  
18:43:14.258 -> SI  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
18:43:14.258 -> SO  A2  4C  4C  43  43  36  38  20  56  32  48  20  32  48  30  32  0   
18:43:14.258 -> Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:
18:43:14.258 -> 0000320 4c 4c 43 43 36 38 20 56 32 48 20 32 48 30 32 00 | LLCC68 V2H 2H02.
18:43:14.258 -> 
18:43:14.258 -> M   SX126x
18:43:14.258 -> CMDW    80  
18:43:14.258 -> SI  0   
18:43:14.258 -> SO  A2  
18:43:14.258 -> CMDR    C0  
18:43:14.258 -> SI  0   
18:43:14.258 -> SO  22  
18:43:14.258 -> CMDW    80  
18:43:14.258 -> SI  0   
18:43:14.258 -> SO  A2  
18:43:14.258 -> CMDR    C0  
18:43:14.258 -> SI  0   
18:43:14.258 -> SO  22  
18:43:14.258 -> CMDW    8F  
18:43:14.258 -> SI  0   0   
18:43:14.258 -> SO  A2  A2  
18:43:14.258 -> CMDR    C0  
18:43:14.258 -> SI  0   
18:43:14.258 -> SO  22  
18:43:14.258 -> CMDW    8A  
18:43:14.258 -> SI  1   
18:43:14.258 -> SO  A2  
18:43:14.258 -> CMDR    C0  
18:43:14.258 -> SI  0   
18:43:14.258 -> SO  22  
18:43:14.258 -> CMDW    93  
18:43:14.258 -> SI  20  
18:43:14.258 -> SO  A2  
18:43:14.289 -> CMDR    C0  
18:43:14.289 -> SI  0   
18:43:14.289 -> SO  22  
18:43:14.289 -> CMDW    88  
18:43:14.289 -> SI  3   16  A   0   0   0   0   
18:43:14.289 -> SO  A2  A2  A2  A2  A2  A2  A2  
18:43:14.289 -> CMDR    C0  
18:43:14.289 -> SI  0   
18:43:14.289 -> SO  22  
18:43:14.289 -> CMDW    2   
18:43:14.289 -> SI  43  FF  
18:43:14.289 -> SO  A2  A2  
18:43:14.289 -> CMDR    C0  
18:43:14.289 -> SI  0   
18:43:14.289 -> SO  22  
18:43:14.289 -> CMDW    8   
18:43:14.289 -> SI  0   0   0   0   0   0   0   0   
18:43:14.289 -> SO  A2  A2  A2  A2  A2  A2  A2  A2  
18:43:14.289 -> CMDR    C0  
18:43:14.289 -> SI  0   
18:43:14.289 -> SO  22  
18:43:14.289 -> CMDW    89  
18:43:14.289 -> SI  7F  
18:43:14.289 -> SO  A2  
18:43:14.289 -> CMDR    C0  
18:43:14.289 -> SI  0   
18:43:14.289 -> SO  22  
18:43:14.289 -> CMDR    11  
18:43:14.289 -> SI  0   0   
18:43:14.289 -> SO  A2  1   
18:43:14.321 -> CMDR    C0  
18:43:14.321 -> SI  0   
18:43:14.321 -> SO  22  
18:43:14.321 -> CMDW    8B  
18:43:14.321 -> SI  9   6   3   0   
18:43:14.321 -> SO  A2  A2  A2  A2  
18:43:14.321 -> CMDR    C0  
18:43:14.321 -> SI  0   
18:43:14.321 -> SO  22  
18:43:14.321 -> CMDR    11  
18:43:14.321 -> SI  0   0   
18:43:14.321 -> SO  A2  1   
18:43:14.321 -> CMDR    C0  
18:43:14.321 -> SI  0   
18:43:14.321 -> SO  22  
18:43:14.321 -> CMDW    D   7   40  
18:43:14.321 -> SI  14  24  
18:43:14.321 -> SO  A2  A2  
18:43:14.321 -> CMDR    11  
18:43:14.321 -> SI  0   0   
18:43:14.321 -> SO  A2  1   
18:43:14.321 -> CMDR    C0  
18:43:14.321 -> SI  0   
18:43:14.321 -> SO  22  
18:43:14.321 -> CMDR    1D  7   36  
18:43:14.321 -> SI  0   0   
18:43:14.321 -> SO  A2  D   
18:43:14.321 -> CMDR    C0  
18:43:14.321 -> SI  0   
18:43:14.321 -> SO  22  
18:43:14.321 -> CMDW    D   7   36  
18:43:14.321 -> SI  D   
18:43:14.321 -> SO  A2  
18:43:14.321 -> CMDW    8C  
18:43:14.321 -> SI  0   8   0   FF  1   0   
18:43:14.321 -> SO  A2  A2  A2  A2  A2  A2  
18:43:14.321 -> CMDR    C0  
18:43:14.321 -> SI  0   
18:43:14.321 -> SO  22  
18:43:14.321 -> CMDW    96  
18:43:14.353 -> SI  1   
18:43:14.353 -> SO  A2  
18:43:14.353 -> CMDR    C0  
18:43:14.353 -> SI  0   
18:43:14.353 -> SO  22  
18:43:14.353 -> CMDW    D   8   E7  
18:43:14.353 -> SI  18  
18:43:14.353 -> SO  A2  
18:43:14.353 -> CMDW    9D  
18:43:14.353 -> SI  1   
18:43:14.353 -> SO  A2  
18:43:14.353 -> CMDR    C0  
18:43:14.353 -> SI  0   
18:43:14.353 -> SO  22  
18:43:14.353 -> CMDR    11  
18:43:14.353 -> SI  0   0   
18:43:14.353 -> SO  A2  1   
18:43:14.353 -> CMDR    C0  
18:43:14.353 -> SI  0   
18:43:14.353 -> SO  22  
18:43:14.353 -> CMDR    1D  7   36  
18:43:14.353 -> SI  0   0   
18:43:14.353 -> SO  A2  D   
18:43:14.353 -> CMDR    C0  
18:43:14.353 -> SI  0   
18:43:14.353 -> SO  22  
18:43:14.353 -> CMDW    D   7   36  
18:43:14.353 -> SI  D   
18:43:14.353 -> SO  A2  
18:43:14.353 -> CMDW    8C  
18:43:14.353 -> SI  0   8   0   FF  1   0   
18:43:14.353 -> SO  A2  A2  A2  A2  A2  A2  
18:43:14.353 -> CMDR    C0  
18:43:14.353 -> SI  0   
18:43:14.353 -> SO  22  
18:43:14.353 -> CMDR    11  
18:43:14.353 -> SI  0   0   
18:43:14.353 -> SO  A2  1   
18:43:14.353 -> CMDR    C0  
18:43:14.353 -> SI  0   
18:43:14.353 -> SO  22  
18:43:14.353 -> CMDR    1D  7   36  
18:43:14.353 -> SI  0   0   
18:43:14.385 -> SO  A2  D   
18:43:14.385 -> CMDR    C0  
18:43:14.385 -> SI  0   
18:43:14.385 -> SO  22  
18:43:14.385 -> CMDW    D   7   36  
18:43:14.385 -> SI  D   
18:43:14.385 -> SO  A2  
18:43:14.385 -> CMDW    8C  
18:43:14.385 -> SI  0   8   0   FF  1   0   
18:43:14.385 -> SO  A2  A2  A2  A2  A2  A2  
18:43:14.385 -> CMDR    C0  
18:43:14.385 -> SI  0   
18:43:14.385 -> SO  22  
18:43:14.385 -> CMDW    98  
18:43:14.385 -> SI  6B  6E  
18:43:14.385 -> SO  A2  A2  
18:43:14.385 -> CMDR    C0  
18:43:14.385 -> SI  0   
18:43:14.385 -> SO  22  
18:43:14.385 -> CMDW    86  
18:43:14.385 -> SI  1B  20  0   0   
18:43:14.385 -> SO  A2  A2  A2  A2  
18:43:14.385 -> CMDR    C0  
18:43:14.385 -> SI  0   
18:43:14.385 -> SO  22  
18:43:14.385 -> CMDW    86  
18:43:14.385 -> SI  1B  20  0   0   
18:43:14.385 -> SO  A2  A2  A2  A2  
18:43:14.385 -> CMDR    C0  
18:43:14.385 -> SI  0   
18:43:14.385 -> SO  22  
18:43:14.385 -> CMDR    11  
18:43:14.385 -> SI  0   0   
18:43:14.385 -> SO  A2  1   
18:43:14.385 -> CMDR    C0  
18:43:14.385 -> SI  0   
18:43:14.385 -> SO  22  
18:43:14.385 -> CMDW    8B  
18:43:14.385 -> SI  9   4   3   0   
18:43:14.385 -> SO  A2  A2  A2  A2  
18:43:14.385 -> CMDR    C0  
18:43:14.385 -> SI  0   
18:43:14.385 -> SO  22  
18:43:14.385 -> CMDR    11  
18:43:14.417 -> SI  0   0   
18:43:14.417 -> SO  A2  1   
18:43:14.417 -> CMDR    C0  
18:43:14.417 -> SI  0   
18:43:14.417 -> SO  22  
18:43:14.417 -> CMDW    8B  
18:43:14.417 -> SI  9   4   3   0   
18:43:14.417 -> SO  A2  A2  A2  A2  
18:43:14.417 -> CMDR    C0  
18:43:14.417 -> SI  0   
18:43:14.417 -> SO  22  
18:43:14.417 -> CMDR    1D  8   E7  
18:43:14.417 -> SI  0   0   
18:43:14.417 -> SO  A2  18  
18:43:14.417 -> CMDR    C0  
18:43:14.417 -> SI  0   
18:43:14.417 -> SO  22  
18:43:14.417 -> CMDW    95  
18:43:14.417 -> SI  4   7   0   1   
18:43:14.417 -> SO  A2  A2  A2  A2  
18:43:14.417 -> CMDR    C0  
18:43:14.417 -> SI  0   
18:43:14.417 -> SO  22  
18:43:14.417 -> CMDW    8E  
18:43:14.417 -> SI  A   4   
18:43:14.417 -> SO  A2  A2  
18:43:14.417 -> CMDR    C0  
18:43:14.417 -> SI  0   
18:43:14.417 -> SO  22  
18:43:14.417 -> CMDW    D   8   E7  
18:43:14.417 -> SI  18  
18:43:14.417 -> SO  A2  
18:43:14.417 -> CMDR    1D  8   D8  
18:43:14.417 -> SI  0   0   
18:43:14.417 -> SO  A2  FE  
18:43:14.417 -> CMDR    C0  
18:43:14.417 -> SI  0   
18:43:14.417 -> SO  22  
18:43:14.417 -> CMDW    D   8   D8  
18:43:14.417 -> SI  FE  
18:43:14.417 -> SO  A2  
18:43:14.417 -> success!
18:43:14.417 -> SI  0   0   
18:43:14.417 -> SO  A2  FE  
18:43:14.417 -> CMDR    C0  
18:43:14.417 -> SI  0   
18:43:14.417 -> SO  22  
18:43:14.417 -> CMDW    D   8   D8  
18:43:14.417 -> SI  FE  
18:43:14.417 -> SO  A2  
18:43:14.417 -> success!
18:43:14.417 -> [LoRaWAN] Attempting over-the-air activation ... Didn't restore session (checksum: 0, mode: 0)
18:43:14.450 -> First 16 bytes of NVM:
18:43:14.450 -> 0000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
18:43:14.450 -> Wiping EEPROM and starting a clean session
18:43:14.739 -> Setting up dynamic channels
18:43:14.739 -> Channel UL/DL 0 frequency = 868.099976 MHz
18:43:14.739 -> Channel UL/DL 1 frequency = 868.299988 MHz
18:43:14.739 -> Channel UL/DL 2 frequency = 868.500000 MHz
18:43:14.739 -> exe MAC CID = 03, len = 4
18:43:14.739 -> ADR REQ: dataRate = 2, txPower = 0, chMask = 0x0000, chMaskCntl = 00, nbTrans = 0
18:43:14.739 -> DR 72: LORA (SF: 10, BW: 125.000000, CR: 5)
18:43:14.739 -> CMDR    11  
18:43:14.739 -> SI  0   0   
18:43:14.739 -> SO  A2  1   
18:43:14.739 -> CMDR    C0  
18:43:14.739 -> SI  0   
18:43:14.739 -> SO  22  
18:43:14.739 -> ADR failed to configure dataRate 2, code -9!
18:43:14.739 -> CMDR    1D  8   E7  
18:43:14.739 -> SI  0   0   
18:43:14.739 -> SO  A2  18  
18:43:14.772 -> CMDR    C0  
18:43:14.772 -> SI  0   
18:43:14.772 -> SO  22  
18:43:14.772 -> CMDW    95  
18:43:14.772 -> SI  4   7   0   1   
18:43:14.772 -> SO  A2  A2  A2  A2  
18:43:14.772 -> CMDR    C0  
18:43:14.772 -> SI  0   
18:43:14.772 -> SO  22  
18:43:14.772 -> CMDW    8E  
18:43:14.772 -> SI  10  4   
18:43:14.772 -> SO  A2  A2  
18:43:14.772 -> CMDR    C0  
18:43:14.772 -> SI  0   
18:43:14.772 -> SO  22  
18:43:14.772 -> CMDW    D   8   E7  
18:43:14.772 -> SI  18  
18:43:14.772 -> SO  A2  
18:43:14.772 -> ADR ANS: status = 0x05
18:43:14.772 -> exe MAC CID = 04, len = 1
18:43:14.772 -> Max duty cycle: 1/2^7
18:43:14.836 -> exe MAC CID = 05, len = 4
18:43:14.836 -> Rx param REQ: rx1DrOffset = 0, rx2DataRate = 0, freq = 869.525024
18:43:14.836 -> CMDW    98  
18:43:14.836 -> SI  D8  DB  
18:43:14.836 -> SO  A2  A2  
18:43:14.836 -> CMDR    C0  
18:43:14.836 -> SI  0   
18:43:14.836 -> SO  22  
18:43:14.836 -> CMDW    86  
18:43:14.836 -> SI  36  58  66  80  
18:43:14.836 -> SO  A2  A2  A2  A2  
18:43:14.836 -> CMDR    C0  
18:43:14.836 -> SI  0   
18:43:14.836 -> SO  22  
18:43:14.836 -> Rx param ANS: status = 0x07
18:43:14.836 -> exe MAC CID = 08, len = 1
18:43:14.836 -> RX timing: delay = 1 sec
18:43:14.836 -> exe MAC CID = 09, len = 1
18:43:14.836 -> TX timing: dlDwell = 0, ulDwell = 0, maxEirp = 16 dBm
18:43:14.867 -> exe MAC CID = 0c, len = 1
18:43:14.867 -> ADR param setup: limitExp = 6, delayExp = 5
18:43:14.867 -> exe MAC CID = 0f, len = 1
18:43:14.867 -> Rejoin setup: maxTime = 15, maxCount = 10
18:43:14.867 -> CMDR    1D  8   E7  
18:43:14.867 -> SI  0   0   
18:43:14.867 -> SO  A2  18  
18:43:14.867 -> CMDR    C0  
18:43:14.867 -> SI  0   
18:43:14.867 -> SO  22  
18:43:14.867 -> CMDW    95  
18:43:14.867 -> SI  4   7   0   1   
18:43:14.867 -> SO  A2  A2  A2  A2  
18:43:14.867 -> CMDR    C0  
18:43:14.867 -> SI  0   
18:43:14.867 -> SO  22  
18:43:14.867 -> CMDW    8E  
18:43:14.867 -> SI  10  4   
18:43:14.867 -> SO  A2  A2  
18:43:14.867 -> CMDR    C0  
18:43:14.867 -> SI  0   
18:43:14.867 -> SO  22  
18:43:14.867 -> CMDW    D   8   E7  
18:43:14.867 -> SI  18  
18:43:14.867 -> SO  A2  
18:43:14.867 -> CMDR    11  
18:43:14.867 -> SI  0   0   
18:43:14.867 -> SO  A2  1   
18:43:14.867 -> CMDR    C0  
18:43:14.867 -> SI  0   
18:43:14.867 -> SO  22  
18:43:14.867 -> CMDR    11  
18:43:14.900 -> SI  0   0   
18:43:14.900 -> SO  A2  1   
18:43:14.900 -> CMDR    C0  
18:43:14.900 -> SI  0   
18:43:14.900 -> SO  22  
18:43:14.900 -> CMDW    D   7   40  
18:43:14.900 -> SI  34  44  
18:43:14.900 -> SO  A2  A2  
18:43:14.900 -> CMDR    11  
18:43:14.900 -> SI  0   0   
18:43:14.900 -> SO  A2  1   
18:43:14.900 -> CMDR    C0  
18:43:14.900 -> SI  0   
18:43:14.900 -> SO  22  
18:43:14.900 -> CMDR    1D  7   36  
18:43:14.900 -> SI  0   0   
18:43:14.900 -> SO  A2  D   
18:43:14.900 -> CMDR    C0  
18:43:14.900 -> SI  0   
18:43:14.900 -> SO  22  
18:43:14.900 -> CMDW    D   7   36  
18:43:14.900 -> SI  D   
18:43:14.900 -> SO  A2  
18:43:14.900 -> CMDW    8C  
18:43:14.900 -> SI  0   8   0   FF  1   0   
18:43:14.900 -> SO  A2  A2  A2  A2  A2  A2  
18:43:14.900 -> CMDR    C0  
18:43:14.900 -> SI  0   
18:43:14.900 -> SO  22  
18:43:14.900 -> There are no channels defined - are you in ABP mode with no defined subband?
18:43:14.900 -> failed, code -1106

To Reproduce

/*
  RadioLib LoRaWAN End Device Example

  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.

  NOTE: LoRaWAN v1.1 requires storing parameters persistently!
        RadioLib does this by using EEPROM (persistent storage), 
        by default starting at address 0 and using 448 bytes.
        If you already use EEPROM in your application,
        you will have to either avoid this range, or change it
        by setting a different start address by changing the value of
        RADIOLIB_HAL_PERSISTENT_STORAGE_BASE macro, either
        during build or in src/BuildOpt.h.

  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/
*/

// include the library
#include <SPI.h>
#include <RadioLib.h>

SPIClass customSPI(SPI);
SPISettings spiSettings(2000000, MSBFIRST, SPI_MODE0);

// SX1262 has the following pin order:
// Module(NSS/CS, DIO1, RESET, BUSY)
// SX1262 radio = new Module(8, 14, 12, 13);

LLCC68 radio = new Module(12, 14, 1, 4, customSPI, spiSettings);

// SX1278 has the following pin order:
// Module(NSS/CS, DIO0, RESET, DIO1)
// SX1278 radio = new Module(10, 2, 9, 3);

// create the node instance on the EU-868 band
// using the radio module and the encryption key
// make sure you are using the correct band
// based on your geographical location!
LoRaWANNode node(&radio, &EU868);

// for fixed bands with subband selection
// such as US915 and AU915, you must specify
// the subband that matches the Frequency Plan
// that you selected on your LoRaWAN console
/*
  LoRaWANNode node(&radio, &US915, 2);
*/

void setup() {
  Serial.begin(9600);

  sleep(1);
  Serial.print(F("[Radio] Initializing ... "));

  customSPI.begin(5, 7, 9, 12);

  int state = radio.begin();
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true)
      ;
  }

  // application identifier - pre-LoRaWAN 1.1.0, this was called appEUI
  // when adding new end device in TTN, you will have to enter this number
  // you can pick any number you want, but it has to be unique
  uint64_t joinEUI = 0x0000000000000000;

  // device identifier - this number can be anything
  // when adding new end device in TTN, you can generate this number,
  // or you can set any value you want, provided it is also unique
  uint64_t devEUI = 0x70B3D57ED00655DF;

  // select some encryption keys which will be used to secure the communication
  // there are two of them - network key and application key
  // because LoRaWAN uses AES-128, the key MUST be 16 bytes (or characters) long

  uint8_t nwkKey[] = { 0x4F, 0x36, 0x06, 0xC0, 0xA1, 0x90, 0xE4, 0xD6, 0x65, 0xA2, 0xC8, 0xD7, 0x2E, 0x49, 0xC3, 0x38 };
  uint8_t appKey[] = { 0x3C, 0x6A, 0x3B, 0x85, 0xBA, 0x4A, 0xFE, 0xF2, 0x73, 0xC7, 0x93, 0xEE, 0x34, 0xED, 0x34, 0x42 };

  // prior to LoRaWAN 1.1.0, only a single "nwkKey" is used
  // when connecting to LoRaWAN 1.0 network, "appKey" will be disregarded
  // and can be set to NULL

  // on EEPROM-enabled boards, after the device has been activated,
  // the session can be restored without rejoining after device power cycle
  // this is intrinsically done when calling `beginOTAA()` with the same keys
  // in that case, the function will not need to transmit a JoinRequest

  // now we can start the activation
  // this can take up to 10 seconds, and requires a LoRaWAN gateway in range
  // a specific starting-datarate can be selected in dynamic bands (e.g. EU868):
  /* 
    uint8_t joinDr = 4;
    state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey, joinDr);
  */
  Serial.print(F("[LoRaWAN] Attempting over-the-air activation ... "));
  state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey);

  if (state >= RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
    delay(2000);  // small delay between joining and uplink
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true)
      ;
  }
}

// counter to keep track of transmitted packets
int count = 0;

void loop() {
  // send uplink to port 10
  Serial.print(F("[LoRaWAN] Sending uplink packet ... "));
  String strUp = "Hello!" + String(count++);
  String strDown;
  int state = node.sendReceive(strUp, 10, strDown);
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("received a downlink!"));

    // print data of the packet (if there are any)
    Serial.print(F("[LoRaWAN] Data:\t\t"));
    if (strDown.length() > 0) {
      Serial.println(strDown);
    } else {
      Serial.println(F("<MAC commands only>"));
    }

    // print RSSI (Received Signal Strength Indicator)
    Serial.print(F("[LoRaWAN] RSSI:\t\t"));
    Serial.print(radio.getRSSI());
    Serial.println(F(" dBm"));

    // print SNR (Signal-to-Noise Ratio)
    Serial.print(F("[LoRaWAN] SNR:\t\t"));
    Serial.print(radio.getSNR());
    Serial.println(F(" dB"));

    // print frequency error
    Serial.print(F("[LoRaWAN] Frequency error:\t"));
    Serial.print(radio.getFrequencyError());
    Serial.println(F(" Hz"));

  } else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
    Serial.println(F("no downlink!"));

  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
  }

  // on EEPROM enabled boards, you can save the current session
  // by calling "saveSession" which allows retrieving the session after reboot or deepsleep
  node.saveSession();

  // wait before sending another packet
  uint32_t minimumDelay = 60000;                   // try to send once every minute
  uint32_t interval = node.timeUntilUplink();      // calculate minimum duty cycle delay (per law!)
  uint32_t delayMs = max(interval, minimumDelay);  // cannot send faster than duty cycle allows

  delay(delayMs);
}

Expected behavior Example should connect to TTN and send Hello World message.

Additional info:

jgromes commented 9 months ago

This has been discussed (at length) here: https://github.com/jgromes/RadioLib/discussions/946

It's been fixed in upstream, just not released yet. Are you using the last release? And if so, can you try with the current master?

lioff commented 9 months ago

@jgromes: I used the latest release (6.4.2). Now I pulled the current master and get the same error:

18:52:13.358 -> [Radio] Initializing ... 
18:52:13.359 -> RadioLib Debug Info
18:52:13.359 -> Version:  6.4.2.0
18:52:13.359 -> Platform: ESP32
18:52:13.359 -> Compiled: Feb 27 2024 18:50:41
18:52:13.359 -> 
18:52:13.359 -> Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:
18:52:13.359 -> 0000320 4c 4c 43 43 36 38 20 56 32 48 20 32 48 30 32 00 | LLCC68 V2H 2H02.
18:52:13.359 -> 
18:52:13.359 -> M   SX126x
18:52:13.359 -> success!
18:52:13.359 -> [LoRaWAN] Attempting over-the-air activation ... Didn't restore session (checksum: 0, mode: 0)
18:52:13.359 -> First 16 bytes of NVM:
18:52:13.391 -> 0000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
18:52:13.391 -> Wiping EEPROM and starting a clean session
18:52:13.681 -> Setting up dynamic channels
18:52:13.681 -> Channel UL/DL 0 frequency = 868.099976 MHz
18:52:13.681 -> Channel UL/DL 1 frequency = 868.299988 MHz
18:52:13.681 -> Channel UL/DL 2 frequency = 868.500000 MHz
18:52:13.681 -> exe MAC CID = 03, len = 4
18:52:13.681 -> ADR REQ: dataRate = 2, txPower = 0, chMask = 0x0000, chMaskCntl = 00, nbTrans = 0
18:52:13.681 -> DR 72: LORA (SF: 10, BW: 125.000000, CR: 5)
18:52:13.681 -> ADR failed to configure dataRate 2, code -9!
18:52:13.681 -> ADR ANS: status = 0x05
18:52:13.681 -> exe MAC CID = 04, len = 1
18:52:13.681 -> Max duty cycle: 1/2^7
18:52:13.681 -> exe MAC CID = 05, len = 4
18:52:13.681 -> Rx param REQ: rx1DrOffset = 0, rx2DataRate = 0, freq = 869.525024
18:52:13.712 -> Rx param ANS: status = 0x07
18:52:13.712 -> exe MAC CID = 08, len = 1
18:52:13.712 -> RX timing: delay = 1 sec
18:52:13.744 -> exe MAC CID = 09, len = 1
18:52:13.744 -> TX timing: dlDwell = 0, ulDwell = 0, maxEirp = 16 dBm
18:52:13.744 -> exe MAC CID = 0c, len = 1
18:52:13.744 -> ADR param setup: limitExp = 6, delayExp = 5
18:52:13.777 -> exe MAC CID = 0f, len = 1
18:52:13.777 -> Rejoin setup: maxTime = 15, maxCount = 10
18:52:13.777 -> There are no channels defined - are you in ABP mode with no defined subband?

Based on the discussion you mentioned I tried again with joinDr of 3:

state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey, 3);

Now it seems to attempt a join request with SF 9, reaches a timeout, and then fails in a second attempt with SF 12. I am not sure if this is expected behavior (as the SF 9 request timed out).

18:53:46.769 -> [Radio] Initializing ... 
18:53:46.769 -> RadioLib Debug Info
18:53:46.801 -> Version:  6.4.2.0
18:53:46.801 -> Platform: ESP32
18:53:46.801 -> Compiled: Feb 27 2024 18:50:41
18:53:46.801 -> 
18:53:46.801 -> Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:
18:53:46.801 -> 0000320 4c 4c 43 43 36 38 20 56 32 48 20 32 48 30 32 00 | LLCC68 V2H 2H02.
18:53:46.801 -> 
18:53:46.801 -> M   SX126x
18:53:46.801 -> success!
18:53:46.801 -> [LoRaWAN] Attempting over-the-air activation ... Didn't restore session (checksum: 0, mode: 0)
18:53:46.801 -> First 16 bytes of NVM:
18:53:46.801 -> 0000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
18:53:46.801 -> Wiping EEPROM and starting a clean session
18:53:47.154 -> Setting up dynamic channels
18:53:47.154 -> Channel UL/DL 0 frequency = 868.099976 MHz
18:53:47.154 -> Channel UL/DL 1 frequency = 868.299988 MHz
18:53:47.154 -> Channel UL/DL 2 frequency = 868.500000 MHz
18:53:47.154 -> exe MAC CID = 03, len = 4
18:53:47.154 -> ADR REQ: dataRate = 3, txPower = 0, chMask = 0x0000, chMaskCntl = 00, nbTrans = 0
18:53:47.154 -> DR 56: LORA (SF: 9, BW: 125.000000, CR: 5)
18:53:47.154 -> ADR ANS: status = 0x07
18:53:47.154 -> exe MAC CID = 04, len = 1
18:53:47.154 -> Max duty cycle: 1/2^7
18:53:47.185 -> exe MAC CID = 05, len = 4
18:53:47.185 -> Rx param REQ: rx1DrOffset = 0, rx2DataRate = 0, freq = 869.525024
18:53:47.185 -> Rx param ANS: status = 0x07
18:53:47.185 -> exe MAC CID = 08, len = 1
18:53:47.185 -> RX timing: delay = 1 sec
18:53:47.185 -> exe MAC CID = 09, len = 1
18:53:47.185 -> TX timing: dlDwell = 0, ulDwell = 0, maxEirp = 16 dBm
18:53:47.185 -> exe MAC CID = 0c, len = 1
18:53:47.185 -> ADR param setup: limitExp = 6, delayExp = 5
18:53:47.185 -> exe MAC CID = 0f, len = 1
18:53:47.185 -> Rejoin setup: maxTime = 15, maxCount = 10
18:53:47.282 -> 
18:53:47.282 -> Channel frequency UL = 868.500000 MHz

Any idea what the problem could be?

lioff commented 9 months ago

I see now that TTN actually receives (at least some) of the join requests. The first one appeared ok (even though I did not notice any change in the RadioLib debug output). Since then, however, I get the error "DevNonce is too small" in TTN console. I tried to reset DevNonce in TTN, but no change.

image

jgromes commented 9 months ago

It looks like the original problem was resolved (TTN now obviously receives your join requests), so I will convert this to a discussion.

Based on the discussion you mentioned I tried again with joinDr of 3:

Setting appropriate DR is required, since LLCC68 only supports a subset of spreading factors.

I see now that TTN actually receives (at least some) of the join requests. The first one appeared ok (even though I did not notice any change in the RadioLib debug output).

So ... can you post the output? Was there a timeout, or did you receive the join accept message? Either way it might be worth it to wipe the persistent memory, and (temporarily) allow reusing dev nonces in TTN.