Transmissão Lora

Bom dia!
Estou trabalhando com o codigo abaixo para transmissao de temperatura, porem alguns envios nao estao sendo recebidos pelo Getway.
Poderiam me auxiliar com a tratativa.

#include “LoRaWan_APP.h”

#include “max6675.h”

// Fator de conversão de microsegundos para segundos

#define mS_TO_S_FACTOR 1000

// Fator de conversão de segundos para minutos

#define s_TO_MIN_FACTOR 60

// Tempo que o ESP32 ficará em modo sleep (em minutos)

#define CYCLE_SLEEP 5

// Defina os pinos para os quatro sensores

#define pinCS 8

#define pinCLK 19

#define pinSO1 18 //PINO DIGITAL (SO) para Sensor 1

#define pinSO2 2 //PINO DIGITAL (SO) para Sensor 2

#define pinSO3 1 //PINO DIGITAL (SO) para Sensor 3

#define pinSO4 0 //PINO DIGITAL (SO) para Sensor 4

// Inicialize os sensores

MAX6675 sensorTemp1(pinCLK, pinCS, pinSO1);

MAX6675 sensorTemp2(pinCLK, pinCS, pinSO2);

MAX6675 sensorTemp3(pinCLK, pinCS, pinSO3);

MAX6675 sensorTemp4(pinCLK, pinCS, pinSO4);

/* OTAA(Over the Air Activation) para*/

uint8_t devEui[] = { 0x38, 0x05, 0x18, 0x8F, 0xFF, 0xFF, 0xFF, 0xFF };

uint8_t appEui[] = { 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }; // JoinEUI FF000000000000FF

uint8_t appKey[] = { 0xED, 0xA4, 0x16, 0xFC, 0x3B, 0xEE, 0x03, 0x51, 0x2C, 0x02, 0x3B, 0x8D, 0x67, 0x06, 0x67, 0xD9 }; // AppKey EDA416FC3BEE03512C023B8D670667D9

/* ABP(Activation By Personalization) 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 mascara de canal, default channels 0-7/

uint16_t userChannelsMask[6] = { 0xFFFF, 0xFFFF, 0xFFFF };

/Região LoraWan, US915E6/AU915 permitido no Brasil/

LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;

/LoraWan Class, Class A e Class C são suportados/

DeviceClass_t loraWanClass = CLASS_A;

//O Duty Cicle da aplicação. Valores em [ms].

uint32_t appTxDutyCycle = (mS_TO_S_FACTOR * s_TO_MIN_FACTOR) * CYCLE_SLEEP;

/OTAA or ABP/

bool overTheAirActivation = true;

/ADR ativo(Adaptative Data Ratio)/

bool loraWanAdr = true;

/* Indicates if the node is sending confirmed or unconfirmed messages */

bool isTxConfirmed = true;

uint8_t appPort = 2; // Identificador númerico usado para diferenciar os tipos de dados enviados*/

uint8_t confirmedNbTrials = 10; // Número de Tentativas de transmissão antes de desistir

/* Prepares the payload of the frame */

static void prepareTxFrame(uint8_t port) {

appDataSize = 0; // 4 bytes por sensor, total de 16 bytes

int tempCelsius1 = sensorTemp1.readCelsius();

int tempCelsius2 = sensorTemp2.readCelsius();

int tempCelsius3 = sensorTemp3.readCelsius();

int tempCelsius4 = sensorTemp4.readCelsius();

Serial.print("Sensor 1: ");

Serial.println(tempCelsius1);

Serial.print("Sensor 2: ");

Serial.println(tempCelsius2);

Serial.print("Sensor 3: ");

Serial.println(tempCelsius3);

Serial.print("Sensor 4: ");

Serial.println(tempCelsius4);

// Adicionar os dados ao payload

unsigned char *puc;

puc = (unsigned char *)(&tempCelsius1);

appData[appDataSize++] = puc[0];

appData[appDataSize++] = puc[1];

appData[appDataSize++] = puc[2];

appData[appDataSize++] = puc[3];

puc = (unsigned char *)(&tempCelsius2);

appData[appDataSize++] = puc[0];

appData[appDataSize++] = puc[1];

appData[appDataSize++] = puc[2];

appData[appDataSize++] = puc[3];

puc = (unsigned char *)(&tempCelsius3);

appData[appDataSize++] = puc[0];

appData[appDataSize++] = puc[1];

appData[appDataSize++] = puc[2];

appData[appDataSize++] = puc[3];

puc = (unsigned char *)(&tempCelsius4);

appData[appDataSize++] = puc[0];

appData[appDataSize++] = puc[1];

appData[appDataSize++] = puc[2];

appData[appDataSize++] = puc[3];

}

void setup() {

Serial.begin(115200);

Mcu.begin(HELTEC_BOARD, SLOW_CLK_TPYE);

Serial.println(“Setup pronto!”);

delay(100);

}

void loop() {

switch (deviceState) {

case DEVICE_STATE_INIT:

  {

    #if (LORAWAN_DEVEUI_AUTO)

      LoRaWAN.generateDeveuiByChipID();

    #endif

    LoRaWAN.init(loraWanClass, loraWanRegion);

    //both set join DR and DR when ADR off

    LoRaWAN.setDefaultDR(3);

    Serial.println("Lora iniciado!");

    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:

{

  // Agendar a transmissão do próximo pacote

  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;

 }

}

}

Hi, friend
Firstly, ensure that your gateway is configured correctly and activated. This document may provide you with some assistance,
Read temperature and humidity data and upload the data to the cloud platform. Here is a complete example that may be helpful to you.
Arduino -> Example -> Heltec ESP32 Dev_Board - >LoRaWAN - >LoRaWAN_GXTV3_Uplink

1 Like