When you enabled syslog debugging with #define ENABLE_SYSLOG_DEBUG true, the program crashed immediately after printing the syslog server IP address.
What was happening:
1. setup() starts
2. setSyslogServer() is called → prints "Syslog server: 192.168.1.100:514" ✅
3. First DEBUG_PRINTLN() is called → "ESP32-S3 Weather Logger Starting"
4. println() tries to send UDP packet to syslog server 💥 CRASH!
5. WiFi not connected yet → WiFiUDP operations fail catastrophically
Root Cause: The syslog implementation tried to send UDP packets immediately when DEBUG_PRINTLN() was called, but this happened in setup() BEFORE WiFi was connected. Attempting UDP operations without an initialized WiFi connection causes a crash on ESP32.
Added a WiFi connection check before attempting to send syslog messages:
// Syslog output (send immediately - but only if WiFi is connected!)
if (syslogEnabled && syslogUdp && syslogServer != IPAddress(0, 0, 0, 0)) {
// Check if WiFi is connected before trying to send UDP
if (WiFi.status() == WL_CONNECTED) {
// RFC 3164 Syslog format: <PRI>TIMESTAMP HOSTNAME MESSAGE
String syslogMsg = "<134>" + syslogHostname + " ESP32: " + message;
syslogUdp->beginPacket(syslogServer, syslogPort);
syslogUdp->write((const uint8_t*)syslogMsg.c_str(), syslogMsg.length());
syslogUdp->endPacket();
}
// If WiFi not connected, silently skip syslog (messages still go to Serial/Remote)
}- ESP32_IoT_Utils.cpp - Added
WiFi.status() == WL_CONNECTEDcheck before sending syslog packets - ESP32_IoT_Utils.h - Added explicit
#include <WiFi.h>for WiFi status checking
- ✅ Serial debug works (if enabled)
- ✅ Remote debug buffered (sent after WiFi connects)
- ⏭️ Syslog silently skipped (no crash!)
- ✅ Serial debug works
- ✅ Remote debug works
- ✅ Syslog works (sends UDP packets)
=== Debug Logger Initialized ===
Serial Debug: ENABLED
Remote Debug: disabled
Syslog Debug: ENABLED
================================
Syslog server: 192.168.1.100:514 ← Prints successfully
=== ESP32-S3 Weather Logger Starting === ← No longer crashes!
Note: ESP32-S3 has BLE only (no Bluetooth Classic Serial)
Initializing HDC302x sensor on Wire1 (STEMMA QT)...
HDC302x sensor initialized!
...
Connecting to Adafruit IO...
.........
Adafruit IO connected! ← From this point on, syslog messages are sent!
| Phase | Serial | Remote | Syslog |
|---|---|---|---|
| Setup (before WiFi) | ✅ Works | ⏸️ Buffered | ⏭️ Skipped |
| After WiFi connects | ✅ Works | ✅ Works | ✅ Works |
| After disconnect | ✅ Works | ❌ Offline | ❌ Offline |
If you want ALL messages to go to syslog (including pre-WiFi setup messages), you could modify the sketch to:
- Buffer messages before WiFi (like remote debug does)
- Send buffered messages after WiFi connects
- Send live messages after that
But the current solution is simpler and works well for most use cases - early setup messages go to Serial, and once WiFi is up, syslog takes over.
- Set up a syslog server (examples: rsyslog on Linux, Kiwi Syslog on Windows)
- Configure in sketch:
#define ENABLE_SYSLOG_DEBUG true #define SYSLOG_SERVER_IP 192, 168, 1, 100 // Your server IP
- Upload and monitor:
- Serial Monitor shows all messages
- Syslog server receives messages after WiFi connects
- No crashes!
Messages follow RFC 3164 format:
<134>ESP32-Weather ESP32: Temperature: 72.50 °F
Where:
<134>= Priority (Facility 16/local0, Severity 6/info)ESP32-Weather= Hostname (configurable)ESP32:= Application identifier- Rest = Your debug message
With Serial + Remote + Syslog working together:
- Development - Use Serial for instant feedback
- Deployed - Use Remote (Adafruit IO) to check battery-powered sensors
- Integration - Use Syslog to integrate with existing monitoring systems
- Redundancy - If one output fails, you still have the others
- ✅
ESP32_IoT_Utils.cpp- Added WiFi.status() check before syslog UDP operations - ✅
ESP32_IoT_Utils.h- Added WiFi.h include
Pro Tip: You can enable/disable any combination of debug outputs at runtime without recompiling by changing the #define values:
#define ENABLE_SERIAL_DEBUG true // Local USB debugging
#define ENABLE_REMOTE_DEBUG true // Cloud logging (Adafruit IO)
#define ENABLE_SYSLOG_DEBUG true // Network logging (centralized)All three can be enabled simultaneously for maximum visibility!