Heltec-Aaron-Lee / WiFi_Kit_series

Arduino source codes and toolchain for WiFi_Kit_series made by HelTecAutomation.
GNU Lesser General Public License v2.1
756 stars 307 forks source link

Issues with TTN Data Transmission using Wireless Stick Lite V3 (ESP32S3 + SX1262) #178

Open Fabian-LinkAm opened 1 year ago

Fabian-LinkAm commented 1 year ago

Hi there,

I have been testing the LoRaWan example for the Wireless Stick Lite V3 (ESP32S3 + SX1262), specifically focusing on sending messages to The Things Network (TTN). Here are a few observations and issues that I have encountered during this process.

Flashing Issues with esptool: Initially, I had some trouble with flashing the device. I resolved this by updating the esptool compiler from version 3.3 to version 4.6.1.

Setting the Chip License: I had to edit the provided code to set the license of my chip ID for the MCU.

Missing V3 Hardware Model in TTN Repository: I observed that TTN does not list the V3 hardware model in their repository. I'm wondering if this might be causing some of the issues I'm encountering?

Issues with OTAA Method: I have tested the OTAA method but the code flow is unclear to me. After joining, it seems to go into a sleep state and doesn't wake up or send any messages.

Issues with ABP Method: On testing the ABP method, it appears that after joining, it sends a message, schedules the next tx frame, and then goes to sleep. I believe the process then restarts by rebooting.

No Live Data on TTN End Device: Despite trying both methods (OTAA and ABP), I am not seeing any live data on the TTN end device.

I wonder if I'm missing something in this process, or if TTN's lack of a hardware model for V3 boards might be causing this issue.

Here is the code I have used (note: TTN keys and the chip license have been intentionally omitted for security reasons):

#include "LoRaWan_APP.h"

/*license for Heltec ESP32 LoRaWan, quary your ChipID relevant license: http://resource.heltec.cn/search */
uint32_t  license[4] = { };

/* OTAA para*/
uint8_t devEui[] = {  };
uint8_t appEui[] = {  };
uint8_t appKey[] = {  };

/* ABP para*/
uint8_t nwkSKey[] = {  };
uint8_t appSKey[] = {  };
uint32_t devAddr =  ( uint32_t );

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

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

/*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 = 4;

/* Prepares the payload of the frame */
static void prepareTxFrame( uint8_t port )
{
  /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h".
  *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
  *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure.
  *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
  *for example, if use REGION_CN470, 
  *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h".
  */
    appDataSize = 4;
    appData[0] = 0x00;
    appData[1] = 0x01;
    appData[2] = 0x02;
    appData[3] = 0x03;
}

//if true, next uplink will add MOTE_MAC_DEVICE_TIME_REQ 

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println("START MCU_INIT");
  Mcu.setlicense(license);
  Mcu.begin();
  Serial.println("END MCU_INIT");
  deviceState = DEVICE_STATE_INIT;
}

void loop()
{
  Serial.println(deviceState);
  delay(1000);
  switch( deviceState )
  {
    case DEVICE_STATE_INIT:
    {
      Serial.println("START DEVICE_STATE_INIT");
      LoRaWAN.init(loraWanClass,loraWanRegion);
      Serial.println("END DEVICE_STATE_INIT");
      break;
    }
    case DEVICE_STATE_JOIN:
    {
      Serial.println("START DEVICE_STATE_JOIN");
      LoRaWAN.join();
      Serial.println("END DEVICE_STATE_JOIN");
      break;
    }
    case DEVICE_STATE_SEND:
    {
      Serial.println("START DEVICE_STATE_SEND");
      prepareTxFrame( appPort );
      LoRaWAN.send();
      deviceState = DEVICE_STATE_CYCLE;
      Serial.println("END DEVICE_STATE_SEND");
      break;
    }
    case DEVICE_STATE_CYCLE:
    { 
      Serial.println("START 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;
      Serial.println("END DEVICE_STATE_CYCLE");
      break;
    }
    case DEVICE_STATE_SLEEP:
    {
      Serial.println("START DEVICE_STATE_SLEEP");
      LoRaWAN.sleep(loraWanClass);
      Serial.println("END DEVICE_STATE_SLEEP");
      break;
    }
    default:
    {
      Serial.println("INVALID DEVICE_STATE");
      deviceState = DEVICE_STATE_INIT;
      break;
    }
  }
}

Could anyone provide some guidance on what might be going wrong and how to fix it? I appreciate any help you can provide. Thank you!

eliannarg commented 1 year ago

Didn't you solve this problem yet?