Skip to content

Instantly share code, notes, and snippets.

@beegee-tokyo
Created November 8, 2022 05:25
Show Gist options
  • Save beegee-tokyo/33a3e882dc327c86806441585a60eb1a to your computer and use it in GitHub Desktop.
Save beegee-tokyo/33a3e882dc327c86806441585a60eb1a to your computer and use it in GitHub Desktop.
Send data in CayenneLPP format
#include <CayenneLPP.h>
/** Buffer for Cayenne LPP formatter */
CayenneLPP g_solution_data(255);
/** LoRaWAN application data buffer. */
static uint8_t m_lora_app_data_buffer[256];
/** Lora application data structure. */
static lmh_app_data_t m_lora_app_data = {m_lora_app_data_buffer, 0, 0, 0, 0};
void send_data(void)
{
float Temperature_f = 0.0;
float Humidity = 0.0;
float RainRate = 0.0;
float Rain = 0.0;
float WinDir = 0.0;
float UVIndex = 0.0;
float SolarRad = 0.0;
// Reset the packet
g_solution_data.reset();
// Add the data packets
g_solution_data.addAnalogInput(0x01, Temperature_f);
g_solution_data.addAnalogInput(0x02, Humidity);
g_solution_data.addAnalogInput(0x03, RainRate);
g_solution_data.addAnalogInput(0x04, Rain);
g_solution_data.addAnalogInput(0x05, WinDir);
g_solution_data.addAnalogInput(0x06, UVIndex);
g_solution_data.addAnalogInput(0x07, SolarRad);
// Set the fPort
m_lora_app_data.port = 2;
// Set the packet size
m_lora_app_data.buffsize = g_solution_data.getSize();
// Copy the data into the data packet
memcpy(m_lora_app_data_buffer, g_solution_data.getBuffer(), g_solution_data.getSize());
lmh_send(&m_lora_app_data, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment