@alteriom/painlessmesh 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/LICENSE +674 -0
  3. package/README.md +434 -0
  4. package/RELEASE_GUIDE.md +419 -0
  5. package/docs/DOCUMENTATION_MIGRATION_PLAN.md +176 -0
  6. package/docs/README.md +71 -0
  7. package/docs/alteriom/overview.md +508 -0
  8. package/docs/api/core-api.md +607 -0
  9. package/docs/architecture/mesh-architecture.md +379 -0
  10. package/docs/architecture/plugin-system.md +517 -0
  11. package/docs/getting-started/first-mesh.md +410 -0
  12. package/docs/getting-started/installation.md +275 -0
  13. package/docs/getting-started/quickstart.md +158 -0
  14. package/docs/improvements/README.md +69 -0
  15. package/docs/troubleshooting/common-issues.md +521 -0
  16. package/docs/troubleshooting/faq.md +473 -0
  17. package/docs/tutorials/basic-examples.md +718 -0
  18. package/docs/wiki/API-Reference.md +246 -0
  19. package/docs/wiki/Complete-Documentation.md +123 -0
  20. package/examples/alteriom/README.md +82 -0
  21. package/examples/alteriom/alteriom.ino +186 -0
  22. package/examples/alteriom/alteriom_sensor_node.ino +184 -0
  23. package/examples/alteriom/alteriom_sensor_package.hpp +128 -0
  24. package/examples/alteriom/improved_sensor_node.ino +246 -0
  25. package/examples/alteriom/platformio.ini +25 -0
  26. package/examples/basic/basic.ino +66 -0
  27. package/examples/basic/platformio.ini +25 -0
  28. package/examples/bridge/bridge.ino +51 -0
  29. package/examples/bridge/platformio.ini +25 -0
  30. package/examples/echoNode/echoNode.ino +33 -0
  31. package/examples/echoNode/platformio.ini +25 -0
  32. package/examples/logClient/logClient.ino +109 -0
  33. package/examples/logClient/platformio.ini +25 -0
  34. package/examples/logServer/logServer.ino +81 -0
  35. package/examples/logServer/platformio.ini +25 -0
  36. package/examples/mqttBridge/mqttBridge.ino +118 -0
  37. package/examples/mqttBridge/platformio.ini +26 -0
  38. package/examples/namedMesh/namedMesh.ino +97 -0
  39. package/examples/namedMesh/platformio.ini +25 -0
  40. package/examples/otaReceiver/otaReceiver.ino +79 -0
  41. package/examples/otaReceiver/platformio.ini +25 -0
  42. package/examples/otaSender/nodemcu32s_connections.JPG +0 -0
  43. package/examples/otaSender/otaSender.ino +151 -0
  44. package/examples/otaSender/platformio.ini +25 -0
  45. package/examples/startHere/platformio.ini +25 -0
  46. package/examples/startHere/startHere.ino +159 -0
  47. package/examples/webServer/platformio.ini +27 -0
  48. package/examples/webServer/webServer.ino +89 -0
  49. package/keywords.txt +49 -0
  50. package/library.json +34 -0
  51. package/library.properties +11 -0
  52. package/package.json +78 -0
  53. package/src/AlteriomPainlessMesh.h +98 -0
  54. package/src/arduino/wifi.hpp +365 -0
  55. package/src/boost/asynctcp.hpp +279 -0
  56. package/src/painlessMesh.h +70 -0
  57. package/src/painlessMeshSTA.cpp +236 -0
  58. package/src/painlessMeshSTA.h +58 -0
  59. package/src/painlessTaskOptions.h +4 -0
  60. package/src/painlessmesh/base64.hpp +111 -0
  61. package/src/painlessmesh/buffer.hpp +229 -0
  62. package/src/painlessmesh/callback.hpp +91 -0
  63. package/src/painlessmesh/configuration.hpp +77 -0
  64. package/src/painlessmesh/connection.hpp +192 -0
  65. package/src/painlessmesh/layout.hpp +188 -0
  66. package/src/painlessmesh/logger.hpp +158 -0
  67. package/src/painlessmesh/memory.hpp +120 -0
  68. package/src/painlessmesh/mesh.hpp +560 -0
  69. package/src/painlessmesh/metrics.hpp +323 -0
  70. package/src/painlessmesh/ntp.hpp +263 -0
  71. package/src/painlessmesh/ota.hpp +553 -0
  72. package/src/painlessmesh/plugin.hpp +188 -0
  73. package/src/painlessmesh/protocol.hpp +813 -0
  74. package/src/painlessmesh/router.hpp +322 -0
  75. package/src/painlessmesh/tcp.hpp +71 -0
  76. package/src/painlessmesh/validation.hpp +239 -0
  77. package/src/plugin/performance.hpp +214 -0
  78. package/src/plugin/remote.hpp +64 -0
  79. package/src/scheduler.cpp +10 -0
  80. package/src/wifi.cpp +2 -0
@@ -0,0 +1,521 @@
1
+ # Common Issues and Solutions
2
+
3
+ This guide covers the most frequently encountered problems when working with painlessMesh and their solutions.
4
+
5
+ ## Connection Issues
6
+
7
+ ### Nodes Not Connecting
8
+
9
+ **Symptoms:**
10
+ - Nodes don't appear in each other's node lists
11
+ - No "New Connection" messages in serial output
12
+ - Mesh remains disconnected
13
+
14
+ **Solutions:**
15
+
16
+ #### 1. Check Network Credentials
17
+ Ensure all nodes use identical network settings:
18
+
19
+ ```cpp
20
+ // These MUST be identical on all nodes
21
+ #define MESH_PREFIX "MyMeshNetwork" // Exact match required
22
+ #define MESH_PASSWORD "password123" // Case sensitive
23
+ #define MESH_PORT 5555 // Must match
24
+ ```
25
+
26
+ #### 2. Verify WiFi Range
27
+ - Nodes must be within WiFi range (typically 50-200m)
28
+ - Check for interference from other 2.4GHz devices
29
+ - Try moving nodes closer together for testing
30
+
31
+ #### 3. Check Serial Output
32
+ Enable connection debugging:
33
+
34
+ ```cpp
35
+ mesh.setDebugMsgTypes(ERROR | STARTUP | CONNECTION);
36
+ ```
37
+
38
+ Look for error messages like:
39
+ - "Failed to connect to mesh"
40
+ - "Connection timeout"
41
+ - "Authentication failed"
42
+
43
+ #### 4. Reset Network Settings
44
+ Clear stored WiFi credentials:
45
+
46
+ ```cpp
47
+ void setup() {
48
+ // Add this before mesh.init()
49
+ WiFi.disconnect(true); // Clear stored networks
50
+ delay(1000);
51
+
52
+ mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
53
+ }
54
+ ```
55
+
56
+ ### Frequent Disconnections
57
+
58
+ **Symptoms:**
59
+ - Nodes connect but disconnect shortly after
60
+ - Repeated "Connection dropped" messages
61
+ - Unstable mesh topology
62
+
63
+ **Solutions:**
64
+
65
+ #### 1. Check Power Supply
66
+ - Ensure stable power supply (USB power can be insufficient)
67
+ - Use adequate power adapters (≥1A for ESP32, ≥500mA for ESP8266)
68
+ - Check for voltage drops during WiFi transmission
69
+
70
+ #### 2. Reduce Connection Load
71
+ Limit the number of simultaneous connections:
72
+
73
+ ```cpp
74
+ // Reduce connection count on ESP8266
75
+ #define MAX_CONN 2 // Instead of default 4
76
+ ```
77
+
78
+ #### 3. Increase Connection Timeout
79
+ ```cpp
80
+ // Extend connection timeouts
81
+ #define CONNECTION_TIMEOUT 60000 // 60 seconds instead of 30
82
+ ```
83
+
84
+ #### 4. Memory Issues
85
+ Monitor memory usage:
86
+
87
+ ```cpp
88
+ void checkMemory() {
89
+ Serial.printf("Free heap: %d bytes\n", ESP.getFreeHeap());
90
+ if (ESP.getFreeHeap() < 10000) { // ESP32
91
+ Serial.println("WARNING: Low memory!");
92
+ }
93
+ }
94
+ ```
95
+
96
+ ## Message Delivery Issues
97
+
98
+ ### Messages Not Being Received
99
+
100
+ **Symptoms:**
101
+ - `sendBroadcast()` returns `true` but messages don't arrive
102
+ - Callbacks not triggered
103
+ - Silent message failures
104
+
105
+ **Solutions:**
106
+
107
+ #### 1. Check Callback Registration
108
+ Ensure callbacks are set before `mesh.init()`:
109
+
110
+ ```cpp
111
+ void setup() {
112
+ Serial.begin(115200);
113
+
114
+ // Set callbacks BEFORE init
115
+ mesh.onReceive(&receivedCallback);
116
+ mesh.onNewConnection(&newConnectionCallback);
117
+
118
+ // Then initialize
119
+ mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
120
+ }
121
+ ```
122
+
123
+ #### 2. Verify Message Format
124
+ Check JSON formatting for custom messages:
125
+
126
+ ```cpp
127
+ void sendSensorData() {
128
+ // Proper JSON formatting
129
+ String msg = "{";
130
+ msg += "\"type\":\"sensor\",";
131
+ msg += "\"value\":" + String(sensorValue) + ",";
132
+ msg += "\"timestamp\":" + String(mesh.getNodeTime());
133
+ msg += "}"; // Don't forget closing brace
134
+
135
+ mesh.sendBroadcast(msg);
136
+ }
137
+ ```
138
+
139
+ #### 3. Enable Communication Debugging
140
+ ```cpp
141
+ mesh.setDebugMsgTypes(ERROR | STARTUP | CONNECTION | COMMUNICATION);
142
+ ```
143
+
144
+ #### 4. Check Network Congestion
145
+ Reduce message frequency if network is congested:
146
+
147
+ ```cpp
148
+ // Instead of every second
149
+ Task taskSendMessage(10000, TASK_FOREVER, &sendMessage); // Every 10 seconds
150
+ ```
151
+
152
+ ### Large Messages Being Dropped
153
+
154
+ **Symptoms:**
155
+ - Small messages work, large ones don't
156
+ - Memory errors in serial output
157
+ - Random message failures
158
+
159
+ **Solutions:**
160
+
161
+ #### 1. Reduce Message Size
162
+ ```cpp
163
+ // Keep messages under 1KB for reliability
164
+ String createMessage() {
165
+ String msg = "{\"data\":\"";
166
+ msg += shortData; // Keep data concise
167
+ msg += "\"}";
168
+
169
+ if (msg.length() > 1000) {
170
+ Serial.println("Warning: Message too large");
171
+ return "{}"; // Send empty object
172
+ }
173
+
174
+ return msg;
175
+ }
176
+ ```
177
+
178
+ #### 2. Split Large Data
179
+ ```cpp
180
+ void sendLargeData(String largeData) {
181
+ const size_t chunkSize = 500;
182
+
183
+ for (size_t i = 0; i < largeData.length(); i += chunkSize) {
184
+ String chunk = largeData.substring(i, i + chunkSize);
185
+ String msg = "{\"chunk\":" + String(i/chunkSize) + ",\"data\":\"" + chunk + "\"}";
186
+ mesh.sendBroadcast(msg);
187
+ delay(100); // Small delay between chunks
188
+ }
189
+ }
190
+ ```
191
+
192
+ ## Memory Issues
193
+
194
+ ### ESP8266 Memory Limitations
195
+
196
+ **Symptoms:**
197
+ - Frequent crashes or resets
198
+ - "Out of memory" errors
199
+ - Unstable behavior under load
200
+
201
+ **Solutions:**
202
+
203
+ #### 1. Reduce Buffer Sizes
204
+ ```cpp
205
+ // Use smaller JSON documents
206
+ DynamicJsonDocument doc(512); // Instead of 1024 or larger
207
+
208
+ // Limit string sizes
209
+ TSTRING deviceName;
210
+ deviceName.reserve(32); // Pre-allocate reasonable size
211
+ ```
212
+
213
+ #### 2. Limit Concurrent Connections
214
+ ```cpp
215
+ #define MAX_CONN 2 // ESP8266 works best with 2-3 connections
216
+ ```
217
+
218
+ #### 3. Optimize Task Usage
219
+ ```cpp
220
+ // Combine multiple tasks into one
221
+ Task taskMultiFunction(30000, TASK_FOREVER, [](){
222
+ sendSensorData();
223
+ checkStatus();
224
+ cleanupMemory();
225
+ });
226
+ ```
227
+
228
+ #### 4. Implement Memory Monitoring
229
+ ```cpp
230
+ void monitorMemory() {
231
+ uint32_t freeHeap = ESP.getFreeHeap();
232
+ Serial.printf("Free heap: %u bytes\n", freeHeap);
233
+
234
+ if (freeHeap < 5000) { // Critical threshold for ESP8266
235
+ Serial.println("CRITICAL: Very low memory!");
236
+ // Take corrective action
237
+ mesh.stop();
238
+ delay(1000);
239
+ ESP.restart();
240
+ }
241
+ }
242
+ ```
243
+
244
+ ### ESP32 Memory Issues
245
+
246
+ **Symptoms:**
247
+ - Slower performance over time
248
+ - Memory leaks
249
+ - Task watchdog timeouts
250
+
251
+ **Solutions:**
252
+
253
+ #### 1. Monitor Heap Fragmentation
254
+ ```cpp
255
+ void checkHeapHealth() {
256
+ Serial.printf("Free heap: %u bytes\n", ESP.getFreeHeap());
257
+ Serial.printf("Largest block: %u bytes\n", ESP.getMaxAllocHeap());
258
+
259
+ // If largest block is much smaller than free heap,
260
+ // heap is fragmented
261
+ if (ESP.getMaxAllocHeap() < ESP.getFreeHeap() / 2) {
262
+ Serial.println("Warning: Heap fragmentation detected");
263
+ }
264
+ }
265
+ ```
266
+
267
+ #### 2. Use Static Allocation When Possible
268
+ ```cpp
269
+ // Instead of dynamic allocation
270
+ StaticJsonDocument<1024> doc; // Pre-allocated
271
+
272
+ // Or use stack allocation for small objects
273
+ char buffer[256];
274
+ snprintf(buffer, sizeof(buffer), "{\"value\":%d}", value);
275
+ ```
276
+
277
+ ## Compilation Issues
278
+
279
+ ### Library Not Found
280
+
281
+ **Symptoms:**
282
+ - "painlessMesh.h: No such file or directory"
283
+ - Library compilation errors
284
+
285
+ **Solutions:**
286
+
287
+ #### 1. Arduino IDE
288
+ - Go to **Sketch → Include Library → Manage Libraries**
289
+ - Search for "painlessMesh" and install latest version
290
+ - Ensure ArduinoJson and TaskScheduler are also installed
291
+
292
+ #### 2. PlatformIO
293
+ Add to `platformio.ini`:
294
+ ```ini
295
+ lib_deps =
296
+ painlessMesh
297
+ bblanchon/ArduinoJson@^6.21.3
298
+ arkhipenko/TaskScheduler@^3.7.0
299
+ ```
300
+
301
+ ### Version Compatibility Issues
302
+
303
+ **Symptoms:**
304
+ - Compilation errors after library updates
305
+ - API function not found errors
306
+ - Deprecated warnings
307
+
308
+ **Solutions:**
309
+
310
+ #### 1. Check Version Compatibility
311
+ ```cpp
312
+ // Check painlessMesh version
313
+ #include "painlessMesh.h"
314
+ Serial.printf("painlessMesh version: %s\n", PAINLESSMESH_VERSION);
315
+ ```
316
+
317
+ #### 2. Lock Library Versions
318
+ In `platformio.ini`:
319
+ ```ini
320
+ lib_deps =
321
+ painlessMesh@1.5.0 # Lock to specific version
322
+ bblanchon/ArduinoJson@6.21.3
323
+ arkhipenko/TaskScheduler@3.7.0
324
+ ```
325
+
326
+ #### 3. Update Deprecated APIs
327
+ ```cpp
328
+ // Old API (deprecated)
329
+ mesh.onReceive(&receivedCallback);
330
+
331
+ // New API (if changed in your version)
332
+ mesh.onReceive([](uint32_t from, String& msg) {
333
+ receivedCallback(from, msg);
334
+ });
335
+ ```
336
+
337
+ ## Performance Issues
338
+
339
+ ### Slow Message Delivery
340
+
341
+ **Symptoms:**
342
+ - Messages take several seconds to arrive
343
+ - High latency in mesh communication
344
+ - Sluggish response times
345
+
346
+ **Solutions:**
347
+
348
+ #### 1. Check Network Topology
349
+ ```cpp
350
+ void printTopology() {
351
+ String topology = mesh.subConnectionJson(true);
352
+ Serial.println("Current topology:");
353
+ Serial.println(topology);
354
+
355
+ // Look for long chains or star topologies
356
+ // Optimal: balanced tree with short paths
357
+ }
358
+ ```
359
+
360
+ #### 2. Reduce Message Frequency
361
+ ```cpp
362
+ // Instead of high frequency
363
+ Task taskFastSender(1000, TASK_FOREVER, &sendMessage); // Every second
364
+
365
+ // Use lower frequency
366
+ Task taskSlowSender(10000, TASK_FOREVER, &sendMessage); // Every 10 seconds
367
+ ```
368
+
369
+ #### 3. Optimize Message Size
370
+ ```cpp
371
+ // Compact JSON formatting
372
+ String createOptimizedMessage() {
373
+ // Use short field names
374
+ String msg = "{\"t\":" + String(temp) + ",\"h\":" + String(hum) + "}";
375
+ return msg;
376
+ }
377
+ ```
378
+
379
+ ### High CPU Usage
380
+
381
+ **Symptoms:**
382
+ - ESP becomes hot during operation
383
+ - Watchdog timer resets
384
+ - Sluggish response to other tasks
385
+
386
+ **Solutions:**
387
+
388
+ #### 1. Add Delays in Tight Loops
389
+ ```cpp
390
+ void loop() {
391
+ mesh.update();
392
+
393
+ // Add small delay to prevent CPU overload
394
+ delay(10);
395
+
396
+ // Or yield to other tasks
397
+ yield();
398
+ }
399
+ ```
400
+
401
+ #### 2. Reduce Debug Output
402
+ ```cpp
403
+ // Only use essential debug messages in production
404
+ mesh.setDebugMsgTypes(ERROR); // Only errors
405
+ ```
406
+
407
+ #### 3. Optimize Task Scheduling
408
+ ```cpp
409
+ // Spread tasks over time
410
+ Task task1(30000, TASK_FOREVER, &function1); // Every 30s
411
+ Task task2(35000, TASK_FOREVER, &function2); // Every 35s (offset)
412
+ Task task3(40000, TASK_FOREVER, &function3); // Every 40s
413
+ ```
414
+
415
+ ## Platform-Specific Issues
416
+
417
+ ### ESP8266 Specific
418
+
419
+ **Reset Loops:**
420
+ ```cpp
421
+ // Increase watchdog timeout
422
+ ESP.wdtDisable();
423
+ // Perform long operations
424
+ ESP.wdtEnable(5000); // 5 second timeout
425
+ ```
426
+
427
+ **Flash Memory Issues:**
428
+ ```cpp
429
+ // Check flash size
430
+ Serial.printf("Flash size: %u bytes\n", ESP.getFlashChipSize());
431
+
432
+ // Ensure adequate space for SPIFFS/LittleFS
433
+ // Reserve at least 64KB for filesystem
434
+ ```
435
+
436
+ ### ESP32 Specific
437
+
438
+ **Core Affinity:**
439
+ ```cpp
440
+ // Pin mesh tasks to specific core if needed
441
+ void setup() {
442
+ // Use core 0 for mesh (core 1 for app)
443
+ xTaskCreatePinnedToCore(meshTask, "MeshTask", 8192, NULL, 1, NULL, 0);
444
+ }
445
+ ```
446
+
447
+ **Partition Scheme:**
448
+ Ensure adequate partition sizes in partition table:
449
+ ```
450
+ # Name, Type, SubType, Offset, Size, Flags
451
+ nvs, data, nvs, 0x9000, 0x5000,
452
+ otadata, data, ota, 0xe000, 0x2000,
453
+ app0, app, ota_0, 0x10000, 0x140000,
454
+ app1, app, ota_1, 0x150000,0x140000,
455
+ spiffs, data, spiffs, 0x290000,0x160000,
456
+ ```
457
+
458
+ ## Debugging Techniques
459
+
460
+ ### Serial Output Analysis
461
+
462
+ Enable comprehensive debugging:
463
+ ```cpp
464
+ mesh.setDebugMsgTypes(ERROR | STARTUP | CONNECTION | SYNC |
465
+ COMMUNICATION | GENERAL | MSG_TYPES | REMOTE);
466
+ ```
467
+
468
+ Look for patterns in the output:
469
+ - Repeated connection attempts
470
+ - Memory allocation failures
471
+ - Message transmission errors
472
+ - Time synchronization issues
473
+
474
+ ### Network Analysis
475
+
476
+ Use WiFi monitoring tools:
477
+ - WiFi Analyzer apps to check channel congestion
478
+ - Router logs to see connection patterns
479
+ - Packet capture tools for advanced debugging
480
+
481
+ ### Code Instrumentation
482
+
483
+ Add timing measurements:
484
+ ```cpp
485
+ void timedFunction() {
486
+ unsigned long start = millis();
487
+
488
+ // Your code here
489
+ performOperation();
490
+
491
+ unsigned long duration = millis() - start;
492
+ if (duration > 1000) { // Alert if > 1 second
493
+ Serial.printf("Slow operation: %lu ms\n", duration);
494
+ }
495
+ }
496
+ ```
497
+
498
+ ## Getting Help
499
+
500
+ If you're still experiencing issues:
501
+
502
+ 1. **Check the [FAQ](faq.md)** for additional solutions
503
+ 2. **Search existing issues** on [GitHub](https://github.com/Alteriom/painlessMesh/issues)
504
+ 3. **Post in the community forum** with:
505
+ - Complete serial output with debug enabled
506
+ - Hardware details (ESP32/ESP8266 model)
507
+ - Network topology (number of nodes, layout)
508
+ - Code snippets showing the problem
509
+ 4. **Create a minimal test case** that reproduces the issue
510
+ 5. **Include library versions** and platform information
511
+
512
+ ## Prevention Best Practices
513
+
514
+ - **Start simple** - Test with 2 nodes before scaling up
515
+ - **Monitor resources** - Check memory and CPU usage regularly
516
+ - **Use version control** - Track changes that might introduce issues
517
+ - **Test incremental changes** - Don't change everything at once
518
+ - **Document your setup** - Keep notes on working configurations
519
+ - **Regular testing** - Verify mesh operation after any changes
520
+
521
+ Remember: Most mesh networking issues are related to network configuration, power supply, or memory management. Check these fundamentals first before diving into complex debugging.