Add LoRa TX timing diagnostics

- Log idle/begin/write/end timing for LoRa TX under SERIAL_DEBUG_MODE
- Document TX timing logs in README
This commit is contained in:
2026-02-04 00:48:20 +01:00
parent 0a99bf3268
commit 5a86d1bd30
2 changed files with 30 additions and 1 deletions

View File

@@ -188,6 +188,7 @@ Packet layout:
LoRa radio settings:
- Frequency: **433 MHz** or **868 MHz** (set by build env via `LORA_FREQUENCY_HZ`)
- SF12, BW 125 kHz, CR 4/5, CRC on, Sync Word 0x34
- When `SERIAL_DEBUG_MODE` is enabled, LoRa TX logs include timing breakdowns for `idle/begin/write/end` to diagnose long transmit times.
## Data Format
MeterData JSON (sender + MQTT):

View File

@@ -33,6 +33,18 @@ bool lora_send(const LoraPacket &pkt) {
if (LORA_SEND_BYPASS) {
return true;
}
uint32_t t0 = 0;
uint32_t t1 = 0;
uint32_t t2 = 0;
uint32_t t3 = 0;
uint32_t t4 = 0;
if (SERIAL_DEBUG_MODE) {
t0 = millis();
}
LoRa.idle();
if (SERIAL_DEBUG_MODE) {
t1 = millis();
}
uint8_t buffer[5 + LORA_MAX_PAYLOAD + 2];
size_t idx = 0;
buffer[idx++] = pkt.protocol_version;
@@ -53,8 +65,24 @@ bool lora_send(const LoraPacket &pkt) {
buffer[idx++] = static_cast<uint8_t>(crc & 0xFF);
LoRa.beginPacket();
if (SERIAL_DEBUG_MODE) {
t2 = millis();
}
LoRa.write(buffer, idx);
int result = LoRa.endPacket();
if (SERIAL_DEBUG_MODE) {
t3 = millis();
}
int result = LoRa.endPacket(false);
if (SERIAL_DEBUG_MODE) {
t4 = millis();
Serial.printf("lora_tx: idle=%lums begin=%lums write=%lums end=%lums total=%lums len=%u\n",
static_cast<unsigned long>(t1 - t0),
static_cast<unsigned long>(t2 - t1),
static_cast<unsigned long>(t3 - t2),
static_cast<unsigned long>(t4 - t3),
static_cast<unsigned long>(t4 - t0),
static_cast<unsigned>(idx));
}
return result == 1;
}