Hello greetings, I need help… I’m doing tests with a LoRaWan gateway with the CubeCell HTCC-AB01 boards, with the LoRaWan_APP and Cayenne library, connected a DHT22 temperature and humidity sensor, I have doubts about the method of sending the payload of the library cayenneLpp.h that I am using is not the right one, I have made several attempts and the sensor readings are always wrong… with values like:
{relative_humidity_2: 127.5, temperature_1: -0.1}
I share the code, I do not understand how such a well-known DHT22 sensor does not work well with the Lorawan_APP.h library
#include “LoRaWan_APP.h”
#include “Arduino.h”
#include <CayenneLPP.h>
#include “DHT.h”
#define DHTPIN GPIO2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
/* OTAA para*/
uint8_t devEui[] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x05, 0x25, 0x5A };
uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t appKey[] = { 0x46, 0x0E, 0xD4, 0x21, 0x0C, 0x65, 0x93, 0xF6, 0x92, 0x04, 0xFD, 0x06, 0x23, 0x85, 0x6C, 0xED };
uint16_t userChannelsMask[6] = { 0xFF00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };
LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;
DeviceClass_t loraWanClass = LORAWAN_CLASS;
uint32_t appTxDutyCycle = 15000;
bool overTheAirActivation = LORAWAN_NETMODE;
bool loraWanAdr = LORAWAN_ADR;
bool keepNet = LORAWAN_NET_RESERVE;
bool isTxConfirmed = LORAWAN_UPLINKMODE;
uint8_t appPort = 2;
uint8_t confirmedNbTrials = 4;
static void prepareTxFrame( uint8_t port )
{
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
CayenneLPP lpp(LORAWAN_APP_DATA_MAX_SIZE);
lpp.addTemperature(1, temperature);
lpp.addRelativeHumidity(2, humidity);
appDataSize = lpp.getSize();
memcpy(appData, lpp.getBuffer(), appDataSize);
}
void setup() {
Serial.begin(115200);
#if(AT_SUPPORT)
enableAt();
#endif
deviceState = DEVICE_STATE_INIT;
LoRaWAN.ifskipjoin();
dht.begin();
}
void loop()
{
delay(2000);
switch ( deviceState )
{
case DEVICE_STATE_INIT:
{
#if(AT_SUPPORT)
getDevParam();
#endif
printDevParam();
LoRaWAN.init(loraWanClass, loraWanRegion);
deviceState = DEVICE_STATE_JOIN;
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:
{
// Schedule next packet transmission
txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND );
LoRaWAN.cycle(txDutyCycleTime);
deviceState = DEVICE_STATE_SLEEP;
break;
}
case DEVICE_STATE_SLEEP:
{
LoRaWAN.sleep();
break;
}
default:
{
deviceState = DEVICE_STATE_INIT;
break;
}
}
}