#include #include "lora_util.h" /* * 32 digit length, character 0-9, a-f, A-F only, representing eight (16) hexadecimal numbers. */ uint8_t encrypt_key[16] = {0xfa, 0x11, 0x12, 0x56, 0x44, 0x18, 0x46, 0x30, 0xa8, 0x13, 0xdb, 0x05, 0xf5, 0x52, 0x39, 0xc4}; void send_cb(void) { Serial.println("Sent Sucessfully"); } void encode_payload(float temperature, float humidity, uint8_t *payload) { // Scale and clamp temperature to the range -40.00 to +125.00 int16_t temp_scaled = (int16_t)((temperature + 40.0) * 100); // Scale and clamp humidity to the range 0.00% to 100.00% uint8_t hum_scaled = (uint8_t)(humidity * 2.55); // 255/100 for 1-byte representation // Populate the payload payload[0] = (temp_scaled >> 8) & 0xFF; // Temperature high byte payload[1] = temp_scaled & 0xFF; // Temperature low byte payload[2] = hum_scaled; // Humidity byte } void init_lora() { api.system.restoreDefault(); api.lora.nwm.set(); api.lora.pfreq.set(LORA_BAND); api.lora.psf.set(LORA_SF); api.lora.pbw.set(LORA_BANDWIDTH); api.lora.pcr.set(LORA_CODING_RATE); api.lora.ppl.set(LORA_PREAMBLE_LENGTH); api.lora.ptp.set(LORA_TX_POWER); #ifdef ENABLE_ENCRYPTION api.lora.encry.set(1); api.lora.enckey.set(encrypt_key, sizeof(encrypt_key)); #endif api.lora.registerPSendCallback(send_cb); }