diff --git a/README.md b/README.md index 7787a0c..c1c03c1 100644 --- a/README.md +++ b/README.md @@ -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): diff --git a/src/lora_transport.cpp b/src/lora_transport.cpp index aa15d73..d315176 100644 --- a/src/lora_transport.cpp +++ b/src/lora_transport.cpp @@ -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(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(t1 - t0), + static_cast(t2 - t1), + static_cast(t3 - t2), + static_cast(t4 - t3), + static_cast(t4 - t0), + static_cast(idx)); + } return result == 1; }