Inconsistent connectivity

I’m using a wireless stick lite, with the OTAA example, attempting to connect to TTN with a TTN gateway. (This one: https://www.amazon.com/gp/product/B08L6BWNJR?pf_rd_r=KZBAJHNHP3FVV4XGASCY&pf_rd_p=5ae2c7f8-e0c6-4f35-9071-dc3240e894a8&pd_rd_r=37e9ef09-8f56-4b67-a828-e0d7ea4da96b&pd_rd_w=b3Ozp&pd_rd_wg=cwLmU&ref_=pd_gw_unk)

So far, I have been able to get it to work every once in a great while, incredibly frustrating. Tried both OTAA and ABP, both have extremely inconsistent results. Should see a message every 15 seconds, but 10 minutes can pass before I see a new message.

Below is the sketch I’m using, and the TTN settings as well. Note that I’ve also turned frame counting off.

Arduino sketch:

/*
   HelTec Automation(TM) LoRaWAN 1.0.2 OTAA example use OTAA, CLASS A

   Function summary:

   - use internal RTC(150KHz);

   - Include stop mode and deep sleep mode;

   - 15S data send cycle;

   - Informations output via serial(115200);

   - Only ESP32 + LoRa series boards can use this library, need a license
     to make the code run(check you license here: http://www.heltec.cn/search/);

   You can change some definition in "Commissioning.h" and "LoRaMac-definitions.h"

   HelTec AutoMation, Chengdu, China.
   成都惠利特自动化科技有限公司
   https://heltec.org
   support@heltec.cn

  this project also release in GitHub:
  https://github.com/HelTecAutomation/ESP32_LoRaWAN
*/

#include <ESP32_LoRaWAN.h>
#include "Arduino.h"

/*license for Heltec ESP32 LoRaWan, quary your ChipID relevant license: http://resource.heltec.cn/search */
//chipID = B04583910250
uint32_t  license[4] = {0x06309046, 0x8D56EEF8, 0xEA59B397, 0x891F4E72};

/* OTAA para*/
uint8_t DevEui[] = { 0x00, 0x5B, 0xF6, 0x89, 0xFB, 0xD8, 0x95, 0xC9 };
uint8_t AppEui[] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x03, 0xE4, 0x02 };
uint8_t AppKey[] = { 0x1A, 0xDB, 0x92, 0x28, 0x74, 0xCB, 0x8C, 0xB8, 0x95, 0x85, 0xD7, 0xAA, 0x32, 0x86, 0x4E, 0x06 };

/* ABP para*/
uint8_t NwkSKey[] = { 0x86, 0x1E, 0x83, 0xAD, 0xB9, 0x6C, 0x3D, 0x80, 0x11, 0xF8, 0x7C, 0x17, 0x69, 0x62, 0xBA, 0x34 };
uint8_t AppSKey[] = { 0xBD, 0x17, 0x6B, 0xAE, 0xB0, 0x88, 0x1D, 0xB0, 0xB8, 0x65, 0x20, 0x62, 0x73, 0x27, 0x23, 0xA7 };
uint32_t DevAddr =  ( uint32_t )0x26021B8F;

/*LoraWan channelsmask, default channels 0-7*/
uint16_t userChannelsMask[6] = { 0x00FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };

/*LoraWan Class, Class A and Class C are supported*/
DeviceClass_t  loraWanClass = CLASS_A;

/*the application data transmission duty cycle.  value in [ms].*/
uint32_t appTxDutyCycle = 15000;

/*OTAA or ABP*/
bool overTheAirActivation = true;

/*ADR enable*/
bool loraWanAdr = true;

/* Indicates if the node is sending confirmed or unconfirmed messages */
bool isTxConfirmed = true;

/* Application port */
uint8_t appPort = 2;

/*!
  Number of trials to transmit the frame, if the LoRaMAC layer did not
  receive an acknowledgment. The MAC performs a datarate adaptation,
  according to the LoRaWAN Specification V1.0.2, chapter 18.4, according
  to the following table:

  Transmission nb | Data Rate
  ----------------|-----------
  1 (first)       | DR
  2               | DR
  3               | max(DR-1,0)
  4               | max(DR-1,0)
  5               | max(DR-2,0)
  6               | max(DR-2,0)
  7               | max(DR-3,0)
  8               | max(DR-3,0)

  Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
  the datarate, in case the LoRaMAC layer did not receive an acknowledgment
*/
uint8_t confirmedNbTrials = 8;

/*LoraWan debug level, select in arduino IDE tools.
  None : print basic info.
  Freq : print Tx and Rx freq, DR info.
  Freq && DIO : print Tx and Rx freq, DR, DIO0 interrupt and DIO1 interrupt info.
  Freq && DIO && PW: print Tx and Rx freq, DR, DIO0 interrupt, DIO1 interrupt and MCU deepsleep info.
*/
uint8_t debugLevel = LoRaWAN_DEBUG_LEVEL;

/*LoraWan region, select in arduino IDE tools*/
LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;

static void prepareTxFrame( uint8_t port )
{
  appDataSize = 4;//AppDataSize max value is 64
  appData[0] = 0x01;
  appData[1] = 0x02;
  appData[2] = 0x03;
  appData[3] = 0x04;
}

// Add your initialization code here
void setup()
{
  Serial.begin(115200);
  //while (!Serial);
  SPI.begin(SCK, MISO, MOSI, SS);
  pinMode(25, OUTPUT);
  digitalWrite(25, HIGH);
  delay(500);
  digitalWrite(25, LOW);
  delay(500);
  Mcu.init(SS, RST_LoRa, DIO0, DIO1, license);
  deviceState = DEVICE_STATE_INIT;
}

// The loop function is called in an endless loop
void loop()
{
  switch ( deviceState )
  {
    case DEVICE_STATE_INIT:
      {
        LoRaWAN.init(loraWanClass, loraWanRegion);
        break;
      }
    case DEVICE_STATE_JOIN:
      {
        LoRaWAN.join();
        break;
      }
    case DEVICE_STATE_SEND:
      {
        prepareTxFrame( appPort );
        LoRaWAN.send(loraWanClass);
        deviceState = DEVICE_STATE_CYCLE;
        digitalWrite(25, HIGH);
        delay(500);
        digitalWrite(25, LOW);
        delay(500);
        break;
      }
    case DEVICE_STATE_CYCLE:
      {
        // Schedule next packet transmission
        txDutyCycleTime = appTxDutyCycle + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
        LoRaWAN.cycle(txDutyCycleTime);
        deviceState = DEVICE_STATE_SLEEP;
        break;
      }
    case DEVICE_STATE_SLEEP:
      {
        LoRaWAN.sleep(loraWanClass, debugLevel);
        break;
      }
    default:
      {
        deviceState = DEVICE_STATE_INIT;
        break;
      }
  }
}

Join event from gateway:

{
  "gw_id": "eui-58a0cbfffe8030d9",
  "payload": "AALkA9B+1bNwyZXY+4n2WwBvMXTT410=",
  "dev_eui": "005BF689FBD895C9",
  "lora": {
    "spreading_factor": 8,
    "bandwidth": 500,
    "air_time": 28288000
  },
  "coding_rate": "4/5",
  "timestamp": "2021-02-26T18:04:54.136Z",
  "rssi": -44,
  "snr": 10.25,
  "app_eui": "70B3D57ED003E402",
  "frequency": 904600000
}

Accompanying serial port message (note, TTN sees join request, but device says join failed? Can only seem to get data through sometimes on ABP mode…):

TX on freq 903000000 Hz at DR 4
DIO0:TX Done
RX on freq 923300000 Hz at DR 13
DIO1:RX Timeout
RX on freq 923300000 Hz at DR 8
DIO1:RX Timeout
TX on freq 903300000 Hz at DR 0
DIO0:TX Done
RX on freq 926300000 Hz at DR 10
DIO1:RX Timeout
RX on freq 923300000 Hz at DR 8
DIO1:RX Timeout
join failed, rejoin at 30000 ms later

TTN settings and logs:

Yet another odd thing I noticed, while in ABP mode the few messages that get through all have extremely low RSSI, ~-109dB, which is strange since the devices are within a few feet of each other and are line of sight…

Any and all input would be appreciated, I’m tearing my hair out over here.

Hi cmodTera,

If your device is very close to the TTN gateway the signal could be too strong and cause reception problems. Try to have the device in a separate room from the gateway or at least 20 metres away.

Hi ahgreenhalgh, thanks for the help.

I don’t think this is an overpowering issue, I’ve since tried the LMIC library with TX power set to max and every packet made it through with no issues. I believe this to be an issue with this library, rather than the radio/hardware environment. Perhaps it’s a bug with the ADR code?

hi,

Greeting from heltec!

I think I might know what your problem is. I noticed that you added your code here:

We currently only recommend that you add your code to this function(Or before the setup function initializes lora):
%E5%9B%BE%E7%89%87

Thanks for looking into this Jason, unfortunately removing the added LED code did not solve the problem, still weird behaviors happening with the out of the box example code. Packets are getting dropped and not making their way to the gateway, and join requests fail unnecessarily even when the gateway can see the join request. Using the same microcontroller, I don’t have any issues when using the LMIC library.

hi,
ABP mode requires stricter frame-counter. ABP mode requires that the frame-counter of the node and the frame-counter of the server must be the same.
%E5%9B%BE%E7%89%87
maybe you can disable frame-counter validation.

Unfortunately, I have already disabled frame counter checks. The messages didn’t show up at all otherwise.