Hello, I am very doubtful right now, I am sending data with LoRaWAN, Heltec ESP v3, via TTN Gateway, but it only comes that it join. I want to send data from DHT11 and from a load cell. below is my code and below is the payload decorder. Can someone please help? Thank you
I have also read through the topics and the only thing I have found is that the gateway is far away from me, but this is not the case with me (I think, but I have entered the nearest gateway in my city). if I am wrong pls send a link from the topic and sorry for opening a new one
that’s the only thing i get:
Code:
#include "LoRaWan_APP.h"
uint8_t appEui[] = { something };
uint8_t devEui[] = { something };
uint8_t appKey[] = { something };
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;
uint16_t userChannelsMask[6] = { 0x00FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };
LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;
DeviceClass_t loraWanClass = CLASS_A;
uint32_t appTxDutyCycle = 240000;
bool overTheAirActivation = true;
bool loraWanAdr = true;
bool isTxConfirmed = true;
uint8_t appPort = 2;
uint8_t confirmedNbTrials = 4;
#include "HX711.h"
HX711 scale;
uint8_t dataPin = 26;
uint8_t clockPin = 48;
int int_nestweight = 0;
#define VBAT_PIN 1
#define VBAT_READ_CNTRL_PIN 37
#define ADC_READ_STABILIZE 10
int int_readBatLevel = 0;
float readBatLevel() {
int analogValue = analogRead(VBAT_PIN);
float voltage = 0.004376 * analogValue;
return voltage;
}
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int int_readhumidity = 0;
int int_readtemperature = 0;
static void prepareTxFrame(uint8_t port) {
Serial.begin(115200);
Serial.println("wakeup scale");
scale.begin(dataPin, clockPin);
scale.set_scale(1000.795471);
scale.set_offset(4294624289);
delay(5000);
if (scale.is_ready()) {
Serial.println("scale is ready");
Serial.println(scale.get_units(1));
int_nestweight = (scale.get_units(1) * 10);
int_nestweight = 890;
if (int_nestweight > 9000) {
int_nestweight = 9999;
}
} else {
int_nestweight = 8888;
Serial.println("scale not ready");
}
Serial.println(int_nestweight);
float v = readBatLevel();
int_readBatLevel = abs(v * 100);
Serial.print("Batterielevel ");
Serial.println(int_readBatLevel);
float humidity = dht.readHumidity();
int_readhumidity = abs(humidity * 100);
float temperature = dht.readTemperature();
int_readtemperature = abs(temperature * 100);
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Error reading DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.println(humidity);
Serial.print("Temperature: ");
Serial.println(temperature);
appDataSize = 16;
appData[0] = int_nestweight >> 8;
appData[1] = int_nestweight & 0xFF;
appData[2] = int_readBatLevel >> 8;
appData[3] = int_readBatLevel & 0xFF;
appData[4] = int_readhumidity >> 8;
appData[5] = int_readhumidity & 0xFF;
appData[6] = int_readtemperature >> 8;
appData[7] = int_readtemperature & 0xFF;
}
void setup() {
Serial.begin(115200);
Mcu.begin();
deviceState = DEVICE_STATE_INIT;
scale.begin(dataPin, clockPin);
scale.set_scale(1000.795471);
scale.set_offset(4294624289);
pinMode(VBAT_READ_CNTRL_PIN, OUTPUT);
digitalWrite(VBAT_READ_CNTRL_PIN, LOW);
dht.begin();
}
void loop() {
switch (deviceState) {
case DEVICE_STATE_INIT: {
#if (LORAWAN_DEVEUI_AUTO)
LoRaWAN.generateDeveuiByChipID();
#endif
LoRaWAN.init(loraWanClass, loraWanRegion);
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;
}
}
}
Payload Decorder:
function decodeUplink(input) {
var nestWeight = (input.bytes[0] << 8) | input.bytes[1];
var batteryVoltage = (input.bytes[2] << 8) | input.bytes[3];
var humidity = (input.bytes[4] << 8) | input.bytes[5];
var temperature = (input.bytes[6] << 8) | input.bytes[7];
var errorMessage = 'measurement_error';
if (nestWeight < 1000) {
return {
data: {
nest_weight_in_grams: nestWeight / 10,
battery_status_in_volts: batteryVoltage / 100,
humidity_in_percent: humidity / 100,
temperature_in_degrees_celsius: temperature / 100
}
};
} else {
return {
data: {
error_message: errorMessage
}
};
}
}