RadioLib: LoRaWan - CubeCell cannot join most time (error -6)

Using the LoRaWAN_End_Device_Reference.ino the CubeCell 2 can initialize the Device but return error -6 most times. In TTN I see the join process without errors.

Tried to skip the error in sketch, but sending does not work.

Sometimes the process will go as expected, values will be transmitted and I can see it in TTN. If connected with data transfer - I have seen that SF10BW125 was used - this is not normal, other devices (Heltec WirelessStickV3 lite) are using SF7BW125, as expected…

#include <RadioLib.h>

SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);

LoRaWANNode node(&radio, &EU868);

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

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

  uint64_t joinEUI = 0x...;  //CubeCell
  uint64_t devEUI = 0x...;  //CubeCell
  uint8_t nwkKey[] = { ... };
  uint8_t appKey[] = { ... };

  Serial.print(F("[LoRaWAN] Attempting over-the-air activation ... "));
  state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey);

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

  node.setADR(true);
  node.setDutyCycle(true, 1250);
  node.setDwellTime(true, 1000);
}

void loop() {
  int state = RADIOLIB_ERR_NONE;
  uint8_t battLevel = 146;
  node.setDeviceStatus(battLevel);
  uint32_t fcntUp = node.getFcntUp();

  Serial.print(F("[LoRaWAN] Sending uplink packet ... "));
  String strUp = "Hello World! #" + String(fcntUp);
  Serial.print("upstream:");Serial.println(strUp);  

  if(fcntUp % 64 == 0) {
    state = node.uplink(strUp, 10, true);
    node.sendMacCommandReq(RADIOLIB_LORAWAN_MAC_LINK_CHECK);
    node.sendMacCommandReq(RADIOLIB_LORAWAN_MAC_DEVICE_TIME);
  } else {
    state = node.uplink(strUp, 10);
  }
  if(state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
  }

  Serial.print(F("[LoRaWAN] Waiting for downlink ... "));
  String strDown;

  LoRaWANEvent_t event;
  state = node.downlink(strDown, &event);
  if(state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));

    Serial.print(F("[LoRaWAN] Data:\t\t"));
    if(strDown.length() > 0) {
      Serial.println(strDown);
    } else {
      Serial.println(F("<MAC commands only>"));
    }

    Serial.print(F("[LoRaWAN] RSSI:\t\t"));
    Serial.print(radio.getRSSI());
    Serial.println(F(" dBm"));

    Serial.print(F("[LoRaWAN] SNR:\t\t"));
    Serial.print(radio.getSNR());
    Serial.println(F(" dB"));

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

    Serial.println(F("[LoRaWAN] Event information:"));
    Serial.print(F("[LoRaWAN] Direction:\t"));
    if(event.dir == RADIOLIB_LORAWAN_CHANNEL_DIR_UPLINK) {
      Serial.println(F("uplink"));
    } else {
      Serial.println(F("downlink"));
    }
    Serial.print(F("[LoRaWAN] Confirmed:\t"));
    Serial.println(event.confirmed);
    Serial.print(F("[LoRaWAN] Confirming:\t"));
    Serial.println(event.confirming);
    Serial.print(F("[LoRaWAN] Datarate:\t"));
    Serial.print(event.datarate);
    Serial.print(F("[LoRaWAN] Frequency:\t"));
    Serial.print(event.freq, 3);
    Serial.println(F(" MHz"));
    Serial.print(F("[LoRaWAN] Output power:\t"));
    Serial.print(event.power);
    Serial.println(F(" dBm"));
    Serial.print(F("[LoRaWAN] Frame count:\t"));
    Serial.println(event.fcnt);
    Serial.print(F("[LoRaWAN] Port:\t\t"));
    Serial.println(event.port);
    
    Serial.print(radio.getFrequencyError());

    uint8_t margin = 0;
    uint8_t gwCnt = 0;
    if(node.getMacLinkCheckAns(&margin, &gwCnt)) {
      Serial.print(F("[LoRaWAN] LinkCheck margin:\t"));
      Serial.println(margin);
      Serial.print(F("[LoRaWAN] LinkCheck count:\t"));
      Serial.println(gwCnt);
    }

    uint32_t networkTime = 0;
    uint8_t fracSecond = 0;
    if(node.getMacDeviceTimeAns(&networkTime, &fracSecond, true)) {
      Serial.print(F("[LoRaWAN] DeviceTime Unix:\t"));
      Serial.println(networkTime);
      Serial.print(F("[LoRaWAN] LinkCheck second:\t1/"));
      Serial.println(fracSecond);
    }
  
  } else if(state == RADIOLIB_ERR_RX_TIMEOUT) {
    Serial.println(F("timeout!"));
  
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
  }

  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
  Serial.print("delay(ms): ");Serial.println(delayMs);
  delay(delayMs);
}

Attached 2 verbose debug logs - first with returned error -6 for join, second with a normal transfer without error. So maybe you can see the difference and have an idea what happen here in most times.

CubeCell_join_failed.log CubeCell_join_data_ok.log

Screenshots attached from TTN a screen with join (but sketch returned -6) and a screen with datatransfer CubeCell_TTN_failed CubeCell_TTN_ok

Additional info :

  • Heltec CubeCell 2.2 / HTCC-AB01
  • Arduino IDE version 2.2.1
  • Library version 6.4.2

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Comments: 33 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@michapr as promised, timeout detection is switched from micros to millis, which should resolve some of the weirdness of CubeCell. However, fully fixing it’s issues with millis and micros is fairly out-of-scope for this library, so I suggest taking this to the CubeCell maintainers.