Heltec wifi lora32 (v3.1) with SCD40 temperature,Co2 and humidity sensor problem

Hi everyone, I am creating the weather station project based on Heltec Wifi Lora 32(version3.1) with SCD40 temperature,humidity and CO2 sensor. After uploading my code and connecting it to the TTN, it only sends uplink once. After that, it only receives downlink and can not send the uplink again.
Here is code:

#include “LoRaWan_APP.h”

#include <Wire.h>

#include “Adafruit_SCD30.h”

// SCD30 instance

Adafruit_SCD30 scd30;

/* OTAA parameters (your end device credentials) */

uint8_t devEui[] = { *****************};

uint8_t appEui[] = { **************************** };

uint8_t appKey[] = { ************************************* };

/* ABP parameters (not used in OTAA mode, but kept for reference) */

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

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;

/* Application data transmission duty cycle (value in ms) */

uint32_t appTxDutyCycle = 15000;

/* OTAA activation */

bool overTheAirActivation = true;

/* Adaptive data rate (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 */

uint8_t confirmedNbTrials = 4;

/* Prepares the payload of the frame */

static void prepareTxFrame(uint8_t port)

{

if (scd30.dataReady())

{

    if (!scd30.read())

    {

        Serial.println("Failed to read data from SCD30!");

        return;

    }

    // Convert float values to integers for transmission

    uint16_t co2_int = (uint16_t)scd30.CO2;             // CO2 in ppm

    uint16_t temp_int = (uint16_t)(scd30.temperature * 10); // Temp in 0.1°C

    uint16_t hum_int = (uint16_t)(scd30.relative_humidity * 10); // Humidity in 0.1%

    // Prepare LoRaWAN payload

    appDataSize = 6;

    appData[0] = (co2_int >> 8) & 0xFF;

    appData[1] = co2_int & 0xFF;

    appData[2] = (temp_int >> 8) & 0xFF;

    appData[3] = temp_int & 0xFF;

    appData[4] = (hum_int >> 8) & 0xFF;

    appData[5] = hum_int & 0xFF;

    Serial.print("CO2: ");

    Serial.print(scd30.CO2);

    Serial.print(" ppm, Temp: ");

    Serial.print(scd30.temperature);

    Serial.print(" °C, Humidity: ");

    Serial.print(scd30.relative_humidity);

    Serial.println(" %");

}

else

{

    Serial.println("SCD30 data not ready.");

}

}

void setup() {

Serial.begin(115200);

// Initialize I2C for SCD30

Wire.begin(41, 42); // SDA = 41, SCL = 42

// Initialize the SCD30 sensor

if (!scd30.begin())

{

    Serial.println("Failed to initialize SCD30! Check wiring.");

    while (1);

}

Serial.println("SCD30 initialized successfully.");

// LoRaWAN initialization

Mcu.begin(HELTEC_BOARD, SLOW_CLK_TPYE);

}

void loop()

{

switch (deviceState)

{

    case DEVICE_STATE_INIT:

    {

#if (LORAWAN_DEVEUI_AUTO)

        LoRaWAN.generateDeveuiByChipID();

#endif

        LoRaWAN.init(loraWanClass, loraWanRegion);

        LoRaWAN.setDefaultDR(3);

        break;

    }

    case DEVICE_STATE_JOIN:

    {

        LoRaWAN.join();

        break;

    }

    case DEVICE_STATE_SEND:

    {

        prepareTxFrame(appPort);

        LoRaWAN.send();

        deviceState = DEVICE_STATE_CYCLE;

        break;

    }

    case DEVICE_STATE_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;

    }

    default:

    {

        deviceState = DEVICE_STATE_INIT;

        break;

    }

}

}

And this is the output from serial monitor in Arduino IDE: image

Well… your code says “confirmed uplink sending” and “received unconfirmed downlink” multiple times, at least more than once. So that doesn’t look like a problem to me? Or do you have more information than we see here?

And also… why do you send confirmed uplinks? That looks like a massive waste of precious airtime (and battery power). I advise you to turn it off :wink:

Since I am working with sensor, it must show data reagrding the room temperature,humidty and Co2. But it only sends one data, everytime only same values even though I touched and moved the sensor. I tried to test sensor individually, it showed every 60 minutes proper different values like 23.4C, 23.5C, and so on.

here you can see, the data(values) is the same:

Breaks LoRaWAN processing cycle badly, breaches law on all continents and is contrary to the Fair Use Policy for TTN - maybe they just turn you off?

And you’ve only got ten downlinks a day so you may have broken all the gateways in the area.

By being very very insistent, like “that guy” that bangs on the door …

There’s a learn section linked at the top of the TTN site, that will help you fill in the blanks on this stuff and once you’re legal, we can solve any issues - but mostly it appears to work so will probably work very nicely if you aren’t doing confirmed uplinks so hard & fast.

Honestly, I don’t know, maybe. I have red all the limitations and it is:

  • An average of 30 seconds uplink time on air, per 24 hours, per device.
  • At most 10 downlink messages per 24 hours, including the ACKs for confirmed uplinks.

What should I do? I tried to set data transmission time to 60 seconds, used unconfirmed uplink but still the data is the same.

LW is not designed to be a real time telemetry system. Do more research, the absolute maximum of an EMPTY payload at SF7 is 133 seconds for the FUP, in some regions, longer.