// Define task handle TaskHandle_t meshTaskHandle = NULL; // The task that will run mesh.loop() periodically void meshTask(void *parameter) { for(;;) { // Process mesh events mesh.loop(); // Small delay to prevent watchdog issues // Adjust as needed based on your application requirements vTaskDelay(10 / portTICK_PERIOD_MS); } } void setup() { // Initialize serial communication Serial.begin(115200); delay(1000); // Give serial time to initialize Serial.println("\n\n=== ESPNowMesh Serial Terminal Demo ==="); // Set initial role mesh.setRole("node"); // Initialize the mesh network mesh.begin(-80, 1); // RSSI threshold and WiFi channel mesh.onReceive(onMeshMessage); // Register message callback // Enable auto-discovery mesh.enableAutoDiscovery(10000); // Auto-discover every 10 seconds // Enable debug output mesh.enableDebug(true); // Register custom commands terminal.addCommand("stats", "Show message statistics", cmdStats); terminal.addCommand("resetstats", "Reset message statistics", cmdResetStats); // Initial discovery to find neighbors mesh.broadcastDiscovery(); // Print setup information Serial.println("Mesh network initialized"); Serial.println("MAC Address: " + WiFi.macAddress()); // Create the mesh processing task xTaskCreate( meshTask, // Task function "MeshTask", // Name for debugging 4096, // Stack size (bytes) NULL, // Task parameters 1, // Priority (1 is low, higher number = higher priority) &meshTaskHandle // Task handle ); Serial.println("\nType /help to see available commands"); Serial.print("> "); } void loop() { // Just process terminal commands - mesh.loop() runs in separate task terminal.process(); // Rest of your application code here }