@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,473 @@
1
+ # Frequently Asked Questions
2
+
3
+ ## General Questions
4
+
5
+ ### Q: What is painlessMesh?
6
+
7
+ **A:** painlessMesh is a library that makes it easy to create mesh networks with ESP8266 and ESP32 devices. It automatically handles:
8
+ - Node discovery and connection
9
+ - Message routing between nodes
10
+ - Network topology management
11
+ - Time synchronization across all nodes
12
+ - Self-healing when nodes join or leave
13
+
14
+ ### Q: How many nodes can I have in a mesh?
15
+
16
+ **A:** The practical limit depends on your ESP model and memory constraints:
17
+ - **ESP8266**: 10-20 nodes typically, limited by ~80KB RAM
18
+ - **ESP32**: 20-50+ nodes, limited by ~320KB RAM
19
+ - Network diameter should stay under 5-7 hops for good performance
20
+ - Each node can connect to 2-10 other nodes depending on memory
21
+
22
+ ### Q: What's the range of the mesh network?
23
+
24
+ **A:** Each WiFi connection has typical range of:
25
+ - **Indoor**: 30-50 meters
26
+ - **Outdoor (line of sight)**: 100-200 meters
27
+ - **Through walls**: 10-30 meters depending on construction
28
+
29
+ The mesh extends this by hopping through intermediate nodes. Total range depends on your network topology.
30
+
31
+ ### Q: Do I need a WiFi router for the mesh to work?
32
+
33
+ **A:** No! painlessMesh creates its own network. Nodes communicate directly with each other without needing internet or a router. However, you can add bridge nodes that connect the mesh to external networks.
34
+
35
+ ## Technical Questions
36
+
37
+ ### Q: How does message routing work?
38
+
39
+ **A:** painlessMesh uses a tree topology with automatic routing:
40
+
41
+ 1. **Broadcast messages** are sent to all nodes via flood routing
42
+ 2. **Single messages** use shortest-path routing to specific nodes
43
+ 3. **Neighbor messages** go only to directly connected nodes
44
+ 4. Routing tables update automatically as topology changes
45
+
46
+ See [Message Routing](../architecture/routing.md) for details.
47
+
48
+ ### Q: Are messages guaranteed to be delivered?
49
+
50
+ **A:** painlessMesh provides **best-effort delivery**:
51
+ - TCP connections provide reliability between directly connected nodes
52
+ - No end-to-end delivery guarantees across multiple hops
53
+ - Network partitions or node failures can cause message loss
54
+ - For critical messages, implement application-level acknowledgments
55
+
56
+ ### Q: How accurate is time synchronization?
57
+
58
+ **A:** Time sync accuracy is typically:
59
+ - **Direct connections**: ±1-5 milliseconds
60
+ - **Multi-hop**: ±10-50 milliseconds depending on network load
61
+ - **Stability**: Good for coordinating actions within ~100ms windows
62
+ - Clock drift is corrected automatically every few minutes
63
+
64
+ ### Q: Can I mix ESP8266 and ESP32 in the same mesh?
65
+
66
+ **A:** Yes! ESP8266 and ESP32 devices work together seamlessly in the same mesh. However:
67
+ - ESP8266 nodes will have fewer connections due to memory limits
68
+ - ESP32 nodes may become hubs due to their higher capacity
69
+ - Message size limits should account for ESP8266 constraints
70
+
71
+ ## Development Questions
72
+
73
+ ### Q: Which Arduino libraries do I need?
74
+
75
+ **A:** painlessMesh requires:
76
+ ```cpp
77
+ // Core dependencies (install these)
78
+ #include "painlessMesh.h"
79
+ #include "ArduinoJson.h" // v6.x
80
+ #include "TaskScheduler.h" // v3.x
81
+
82
+ // Platform libraries (built-in)
83
+ #include "WiFi.h" // ESP32
84
+ #include "ESP8266WiFi.h" // ESP8266
85
+ ```
86
+
87
+ ### Q: Can I use painlessMesh with other WiFi libraries?
88
+
89
+ **A:** painlessMesh manages WiFi internally and may conflict with other WiFi code. If you need external WiFi:
90
+ - Use bridge nodes that connect the mesh to external networks
91
+ - Avoid calling WiFi functions directly in mesh nodes
92
+ - Consider time-division approaches (mesh mode vs. WiFi mode)
93
+
94
+ ### Q: How do I send sensor data efficiently?
95
+
96
+ **A:** Use the plugin system for type-safe, efficient messaging:
97
+
98
+ ```cpp
99
+ // Define custom package
100
+ class SensorPackage : public painlessmesh::plugin::BroadcastPackage {
101
+ public:
102
+ float temperature, humidity;
103
+ uint32_t timestamp;
104
+
105
+ SensorPackage() : BroadcastPackage(100) {}
106
+ // ... implement serialization methods
107
+ };
108
+
109
+ // Send data
110
+ SensorPackage sensor;
111
+ sensor.temperature = readTemperature();
112
+ sensor.humidity = readHumidity();
113
+ sensor.timestamp = mesh.getNodeTime();
114
+ mesh.sendPackage(&sensor);
115
+ ```
116
+
117
+ ### Q: How do I handle different message types?
118
+
119
+ **A:** Use the plugin system with type-specific handlers:
120
+
121
+ ```cpp
122
+ // Register handlers for different types
123
+ mesh.onPackage(SENSOR_DATA, handleSensorData);
124
+ mesh.onPackage(COMMAND_MSG, handleCommand);
125
+ mesh.onPackage(STATUS_MSG, handleStatus);
126
+
127
+ // Or use the raw callback with type checking
128
+ mesh.onReceive([](uint32_t from, String& msg) {
129
+ DynamicJsonDocument doc(1024);
130
+ deserializeJson(doc, msg);
131
+
132
+ int msgType = doc["type"];
133
+ switch(msgType) {
134
+ case SENSOR_DATA:
135
+ // Handle sensor data
136
+ break;
137
+ case COMMAND_MSG:
138
+ // Handle commands
139
+ break;
140
+ }
141
+ });
142
+ ```
143
+
144
+ ## Network Design Questions
145
+
146
+ ### Q: What's the best network topology?
147
+
148
+ **A:** For most applications, aim for a **balanced tree**:
149
+ - Avoid long chains (high latency)
150
+ - Avoid star topologies (bottlenecks at center)
151
+ - Distribute connections evenly
152
+ - Place high-capacity nodes (ESP32) as hubs
153
+ - Keep network diameter under 5-7 hops
154
+
155
+ ### Q: How do I make the mesh more reliable?
156
+
157
+ **A:** Follow these best practices:
158
+
159
+ 1. **Power supply**: Use stable, adequate power sources
160
+ 2. **Placement**: Ensure good WiFi coverage between nodes
161
+ 3. **Memory management**: Monitor and optimize memory usage
162
+ 4. **Error handling**: Implement callbacks for connection events
163
+ 5. **Redundancy**: Design for node failures
164
+ 6. **Testing**: Test with realistic loads and distances
165
+
166
+ ### Q: Can nodes sleep or use deep sleep?
167
+
168
+ **A:** Node sleep modes affect mesh connectivity:
169
+
170
+ - **Light sleep**: Node stays connected but may miss messages
171
+ - **Deep sleep**: Node disconnects from mesh entirely
172
+ - **Modem sleep**: WiFi radio sleeps between messages (automatic)
173
+
174
+ For battery-powered nodes:
175
+ ```cpp
176
+ void enterSleepMode() {
177
+ // Send status before sleeping
178
+ StatusPackage status;
179
+ status.sleepDuration = 300; // 5 minutes
180
+ mesh.sendPackage(&status);
181
+
182
+ // Give time for message to send
183
+ delay(1000);
184
+
185
+ // Disconnect cleanly
186
+ mesh.stop();
187
+
188
+ // Deep sleep
189
+ ESP.deepSleep(300e6); // 5 minutes in microseconds
190
+ }
191
+ ```
192
+
193
+ ## Performance Questions
194
+
195
+ ### Q: Why are my messages slow?
196
+
197
+ **A:** Common causes of slow message delivery:
198
+
199
+ 1. **Network topology**: Long chains or bottlenecked hubs
200
+ 2. **Message frequency**: Too many messages causing congestion
201
+ 3. **Message size**: Large messages take longer to transmit
202
+ 4. **CPU load**: Other tasks interfering with mesh processing
203
+ 5. **WiFi interference**: Congested 2.4GHz band
204
+
205
+ ### Q: How can I optimize performance?
206
+
207
+ **A:** Performance optimization strategies:
208
+
209
+ ```cpp
210
+ // 1. Reduce message frequency
211
+ Task slowTask(30000, TASK_FOREVER, &sendData); // Every 30s instead of 1s
212
+
213
+ // 2. Compact message format
214
+ String msg = "{\"t\":" + String(temp) + ",\"h\":" + String(hum) + "}";
215
+
216
+ // 3. Batch multiple values
217
+ String msg = "{\"sensors\":[" + temp + "," + hum + "," + pressure + "]}";
218
+
219
+ // 4. Use appropriate routing
220
+ mesh.sendSingle(targetNode, msg); // Instead of broadcast when possible
221
+
222
+ // 5. Optimize task timing
223
+ mesh.update(); // Call regularly but don't block
224
+ yield(); // Allow other tasks to run
225
+ ```
226
+
227
+ ### Q: How much memory does painlessMesh use?
228
+
229
+ **A:** Typical memory usage:
230
+ - **Core library**: ~20-30KB
231
+ - **Per connection**: ~5-10KB
232
+ - **Message buffers**: ~2-5KB per connection
233
+ - **JSON processing**: ~1-2KB per message
234
+
235
+ Monitor memory usage:
236
+ ```cpp
237
+ void checkMemory() {
238
+ Serial.printf("Free heap: %u bytes\n", ESP.getFreeHeap());
239
+ Serial.printf("Largest block: %u bytes\n", ESP.getMaxAllocHeap());
240
+ }
241
+ ```
242
+
243
+ ## Security Questions
244
+
245
+ ### Q: Is painlessMesh secure?
246
+
247
+ **A:** Current security features are basic:
248
+ - **Network password**: WPA2 protection for WiFi connections
249
+ - **No message encryption**: Messages are sent in plaintext
250
+ - **No authentication**: Any device with the password can join
251
+
252
+ ### Q: How can I improve security?
253
+
254
+ **A:** Security enhancement options:
255
+
256
+ ```cpp
257
+ // 1. Change default passwords regularly
258
+ #define MESH_PASSWORD "UniquePassword123!" // Use strong passwords
259
+
260
+ // 2. Implement application-level encryption
261
+ String encryptMessage(String plaintext) {
262
+ // Add your encryption here
263
+ return encryptedMessage;
264
+ }
265
+
266
+ // 3. Validate message sources
267
+ mesh.onReceive([](uint32_t from, String& msg) {
268
+ if (!isAuthorizedNode(from)) {
269
+ Serial.printf("Ignoring message from unauthorized node: %u\n", from);
270
+ return;
271
+ }
272
+ processMessage(msg);
273
+ });
274
+
275
+ // 4. Use message authentication
276
+ String createSecureMessage(String data) {
277
+ String timestamp = String(mesh.getNodeTime());
278
+ String signature = calculateHMAC(data + timestamp + secretKey);
279
+ return "{\"data\":\"" + data + "\",\"time\":" + timestamp +
280
+ ",\"sig\":\"" + signature + "\"}";
281
+ }
282
+ ```
283
+
284
+ ### Q: Can someone intercept my mesh messages?
285
+
286
+ **A:** Yes, without additional encryption:
287
+ - WiFi traffic can be intercepted with standard tools
288
+ - Messages are JSON plaintext by default
289
+ - Network password only protects WiFi association
290
+ - Consider application-level encryption for sensitive data
291
+
292
+ ## Integration Questions
293
+
294
+ ### Q: Can I connect the mesh to the internet?
295
+
296
+ **A:** Yes, using bridge nodes:
297
+
298
+ ```cpp
299
+ // Bridge node connects to both mesh and internet
300
+ void setup() {
301
+ // Connect to mesh
302
+ mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
303
+
304
+ // Also connect to home WiFi
305
+ WiFi.begin("HomeWiFi", "password");
306
+ while (WiFi.status() != WL_CONNECTED) {
307
+ delay(500);
308
+ }
309
+
310
+ Serial.println("Bridge node: Connected to both mesh and internet");
311
+ }
312
+
313
+ // Forward mesh data to internet services
314
+ mesh.onReceive([](uint32_t from, String& msg) {
315
+ // Forward to HTTP server, MQTT broker, etc.
316
+ httpClient.POST("http://myserver.com/api/data", msg);
317
+ });
318
+ ```
319
+
320
+ ### Q: Can I use MQTT with painlessMesh?
321
+
322
+ **A:** Yes, through bridge nodes or by running MQTT alongside the mesh:
323
+
324
+ ```cpp
325
+ #include "PubSubClient.h"
326
+
327
+ WiFiClient wifiClient;
328
+ PubSubClient mqttClient(wifiClient);
329
+
330
+ // Bridge mesh messages to MQTT
331
+ mesh.onReceive([](uint32_t from, String& msg) {
332
+ String topic = "mesh/node/" + String(from);
333
+ mqttClient.publish(topic.c_str(), msg.c_str());
334
+ });
335
+
336
+ // Bridge MQTT messages to mesh
337
+ void mqttCallback(char* topic, byte* payload, unsigned int length) {
338
+ String msg = String((char*)payload);
339
+ mesh.sendBroadcast(msg);
340
+ }
341
+ ```
342
+
343
+ ### Q: How do I integrate with home automation systems?
344
+
345
+ **A:** Common integration approaches:
346
+
347
+ 1. **HTTP REST API**: Bridge node exposes REST endpoints
348
+ 2. **MQTT**: Bridge publishes sensor data to MQTT broker
349
+ 3. **Home Assistant**: Use MQTT discovery or custom integration
350
+ 4. **Node-RED**: Connect via MQTT or HTTP
351
+ 5. **Direct integration**: Custom protocol over TCP/WebSocket
352
+
353
+ ## Alteriom-Specific Questions
354
+
355
+ ### Q: What are Alteriom extensions?
356
+
357
+ **A:** Alteriom provides pre-built packages for common IoT use cases:
358
+
359
+ - **SensorPackage**: Environmental sensor data (temperature, humidity, pressure)
360
+ - **CommandPackage**: Device control commands
361
+ - **StatusPackage**: Device health monitoring
362
+
363
+ See [Alteriom Overview](../alteriom/overview.md) for details.
364
+
365
+ ### Q: Can I use Alteriom packages in my own projects?
366
+
367
+ **A:** Yes! The Alteriom packages are examples you can:
368
+ - Use directly in your projects
369
+ - Modify for your specific needs
370
+ - Use as templates for your own packages
371
+
372
+ ```cpp
373
+ #include "examples/alteriom/alteriom_sensor_package.hpp"
374
+ using namespace alteriom;
375
+
376
+ // Use directly
377
+ SensorPackage sensor;
378
+ sensor.temperature = 25.0;
379
+ mesh.sendPackage(&sensor);
380
+
381
+ // Or extend for your needs
382
+ class MySensorPackage : public SensorPackage {
383
+ public:
384
+ float lightLevel = 0.0; // Add custom field
385
+ // ... implement serialization
386
+ };
387
+ ```
388
+
389
+ ## Troubleshooting Questions
390
+
391
+ ### Q: My ESP keeps crashing. What should I check?
392
+
393
+ **A:** Common crash causes:
394
+
395
+ 1. **Memory issues**: Monitor heap usage
396
+ 2. **Power supply**: Ensure stable, adequate power
397
+ 3. **Stack overflow**: Reduce recursion, large local variables
398
+ 4. **Watchdog timeout**: Add `yield()` calls in long loops
399
+ 5. **Hardware issues**: Bad connections, damaged ESP
400
+
401
+ Enable crash debugging:
402
+ ```cpp
403
+ // ESP32
404
+ #include "esp_system.h"
405
+ esp_core_dump_init();
406
+
407
+ // ESP8266
408
+ Serial.println("Last reset reason: " + ESP.getResetReason());
409
+ ```
410
+
411
+ ### Q: Why can't I see debug messages?
412
+
413
+ **A:** Debug message troubleshooting:
414
+
415
+ ```cpp
416
+ void setup() {
417
+ Serial.begin(115200);
418
+ delay(1000); // Wait for serial to initialize
419
+
420
+ // Enable debug messages BEFORE mesh.init()
421
+ mesh.setDebugMsgTypes(ERROR | STARTUP | CONNECTION);
422
+
423
+ mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
424
+
425
+ Serial.println("Setup completed"); // Test message
426
+ }
427
+ ```
428
+
429
+ Check:
430
+ - Correct baud rate (115200)
431
+ - Serial cable supports data (not just power)
432
+ - Debug messages enabled before mesh initialization
433
+ - Serial monitor connected to correct COM port
434
+
435
+ ### Q: Messages work sometimes but not always. Why?
436
+
437
+ **A:** Intermittent message issues usually indicate:
438
+
439
+ 1. **Memory pressure**: Messages dropped when low memory
440
+ 2. **Network congestion**: Too many messages simultaneously
441
+ 3. **Connection instability**: Nodes connecting/disconnecting
442
+ 4. **Power issues**: Voltage drops during transmission
443
+ 5. **WiFi interference**: Other 2.4GHz devices
444
+
445
+ Add reliability checks:
446
+ ```cpp
447
+ bool sendReliableMessage(String msg) {
448
+ bool sent = mesh.sendBroadcast(msg);
449
+ if (!sent) {
450
+ Serial.println("Failed to send - will retry");
451
+ delay(1000);
452
+ return mesh.sendBroadcast(msg); // Retry once
453
+ }
454
+ return true;
455
+ }
456
+ ```
457
+
458
+ ## Getting More Help
459
+
460
+ If your question isn't answered here:
461
+
462
+ 1. Check [Common Issues](common-issues.md) for detailed troubleshooting
463
+ 2. Search the [GitHub Issues](https://github.com/Alteriom/painlessMesh/issues)
464
+ 3. Post in the [Community Forum](https://groups.google.com/forum/#!forum/painlessmesh-user)
465
+ 4. Review the [API Documentation](../api/core-api.md)
466
+ 5. Look at [Example Code](../tutorials/basic-examples.md) for working implementations
467
+
468
+ When asking for help, include:
469
+ - Hardware details (ESP32/ESP8266 model)
470
+ - Library versions
471
+ - Complete code example
472
+ - Serial output with debug enabled
473
+ - Network topology description