Skip to content

Instantly share code, notes, and snippets.

@Arafat245
Created October 23, 2025 19:54
Show Gist options
  • Select an option

  • Save Arafat245/1a1ca82b276415998384aefd9f67349b to your computer and use it in GitHub Desktop.

Select an option

Save Arafat245/1a1ca82b276415998384aefd9f67349b to your computer and use it in GitHub Desktop.
prepare_data
// -------------------- Payload preparation --------------------
// Format: little-endian float32 (°C), to match the decodeUplink() shown.
static void prepareTxFrame(void) {
float t = temperatureRead(); // ESP32 on-die sensor (not ambient)
last_temp_cX100 = (int16_t) lroundf(t * 100.0f); // keep your existing status display state
// Serialize float32 to little-endian bytes explicitly
static_assert(sizeof(float) == 4, "float must be 4 bytes (IEEE-754)");
uint32_t raw;
memcpy(&raw, &t, sizeof(raw));
appDataSize = 4;
appData[0] = (uint8_t)((raw >> 0) & 0xFF); // LSB
appData[1] = (uint8_t)((raw >> 8) & 0xFF);
appData[2] = (uint8_t)((raw >> 16) & 0xFF);
appData[3] = (uint8_t)((raw >> 24) & 0xFF); // MSB
Serial.print("Temp (C): ");
Serial.println(t);
// Reuse your display helper; it expects centi-degrees
display_temperature_centi(last_temp_cX100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment