LoRaWAN: can't get uplink frames in Chirpstack

Dear All,

I have a problem with receiving data from sensor in Chirpstack (using Wireless stick V3 and Ebyte Gateway).

I do not see the uplink frames in Chirpstack LoRaWAN frames (I have last version Chirpstack 4). As it is new version, I can’t find Live Lorawan frames. I work first time with Wireless Stick V3 (wanted to send data from Humidity sensor to the EBYTE gateway). I have already added the Ebyte gateway to Chirpstack.

There is my code in Arduino IDE:

`#include “LoRaWan_APP.h”

#define SENSOR_PIN 1 // Define the pin where the capacitive soil moisture sensor is connected (analog pin)

// LoRaWAN parameters
uint8_t devEui[] = { 0x5B, 0x48, 0xED, 0x53, 0xA5, 0x5B, 0xE2, 0x6F };
uint8_t appEui[] = { 0x2F, 0x01, 0xFE, 0x2C, 0xD7, 0x0D, 0x17, 0x46 };
uint8_t appKey[] = { 0x16, 0x07, 0x16, 0x42, 0xFF, 0xB8, 0x6A, 0x3D, 0x3D, 0x7C, 0xA0, 0x0B, 0x1D, 0xA6, 0x6D, 0xF4 };

/* ABP para*/
uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 };
uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 };
uint32_t devAddr = ( uint32_t )0x007e6ae1;

// LoRaWAN channel mask - Customize based on your region if needed
uint16_t userChannelsMask[6] = { 0x00FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }; // This enables channels 0-7

// Number of trials for confirmed messages
uint8_t confirmedNbTrials = 4; // Set to how many times the device should retry sending a confirmed message

LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;
DeviceClass_t loraWanClass = CLASS_A;
bool overTheAirActivation = true;
bool loraWanAdr = true;
bool isTxConfirmed = true;
uint8_t appPort = 2;
uint32_t appTxDutyCycle = 15000;

// Prepare and send uplink payload

void setup(void) {
Serial.begin(9600);
Mcu.begin(HELTEC_BOARD, SLOW_CLK_TPYE); // Initialize Heltec LoRaWAN

LoRaWAN.init(loraWanClass, loraWanRegion);
LoRaWAN.setDefaultDR(3);
}

void prepareTxFrame(uint8_t port) {
int sensorValue = analogRead(SENSOR_PIN); // Read sensor value

// Convert sensor value to the format you want to send (e.g., percentage)
float moisturePercentage = map(sensorValue, 0, 4095, 0, 100);
int moistureInt = (int)(moisturePercentage); // Convert to integer
Serial.print("Soil Moisture Raw Value: ");
Serial.println(sensorValue);

Serial.print(“Soil Moisture Percentage: “);
Serial.print(moisturePercentage);
Serial.println(” %”);

// Load the data into the payload
appData[0] = (moistureInt >> 8) & 0xFF; // High byte
appData[1] = moistureInt & 0xFF; // Low byte

// Set payload size (2 bytes in this case)
appDataSize = 2;

}

void loop(void) {
// Device state logic
switch (deviceState) {
case DEVICE_STATE_JOIN:
LoRaWAN.join(); // Join the network
break;
case DEVICE_STATE_SEND:
prepareTxFrame(appPort); // Prepare the sensor data
LoRaWAN.send(); // Send the data to the network
deviceState = DEVICE_STATE_CYCLE;
break;
case DEVICE_STATE_CYCLE:
// Wait for the next transmission cycle
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);
break;
}

delay(2000); // Delay between transmissions

}`

You might want to check out RadioLib instead of Heltec’s library. Their library does weird stuff.

Regardless of which stack you use, a 2 second delay between transmissions on a protocol that typically takes 5 to 10 seconds to do a complete cycle is likely going to mess up the state of the device.