@alteriom/painlessmesh 1.9.19 → 1.9.20

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 (41) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +82 -63
  3. package/examples/alteriom/README.md +4 -4
  4. package/examples/alteriom/alteriom_custom_package_template.hpp +320 -0
  5. package/examples/alteriom/alteriom_sensor_package.hpp +1 -1
  6. package/examples/alteriom/mppt_example/alteriom_mppt_example.ino +208 -0
  7. package/examples/bridge_failover/bridge_failover.ino +17 -0
  8. package/examples/sendToInternet/CMakeLists.txt +54 -0
  9. package/examples/sendToInternet/PC_NODE_README.md +517 -0
  10. package/examples/sendToInternet/README.md +39 -1
  11. package/examples/sendToInternet/build.sh +153 -0
  12. package/examples/sendToInternet/mock_server_test.ino +361 -0
  13. package/examples/sendToInternet/pc_mesh_node.cpp +361 -0
  14. package/library.json +4 -1
  15. package/library.properties +1 -1
  16. package/package.json +3 -3
  17. package/src/AlteriomPainlessMesh.h +5 -13
  18. package/src/arduino/wifi.hpp +306 -100
  19. package/src/connection.cpp +10 -0
  20. package/src/painlessMesh.h +1 -14
  21. package/src/painlessmesh/connection.hpp +11 -16
  22. package/src/painlessmesh/gateway.hpp +0 -1061
  23. package/src/painlessmesh/mesh.hpp +29 -85
  24. package/src/painlessmesh/message_queue.hpp +1 -2
  25. package/src/painlessmesh/metrics.hpp +2 -262
  26. package/src/painlessmesh/validation.hpp +0 -143
  27. package/docs/README.md +0 -132
  28. package/docs/alteriom/overview.md +0 -531
  29. package/docs/api/core-api.md +0 -607
  30. package/docs/api/shared-gateway.md +0 -1207
  31. package/docs/architecture/mesh-architecture.md +0 -399
  32. package/docs/architecture/plugin-system.md +0 -517
  33. package/docs/getting-started/arduino-manual-install.md +0 -313
  34. package/docs/getting-started/first-mesh.md +0 -410
  35. package/docs/getting-started/installation.md +0 -275
  36. package/docs/getting-started/quickstart.md +0 -158
  37. package/docs/troubleshooting/common-issues.md +0 -679
  38. package/docs/troubleshooting/debugging.md +0 -455
  39. package/docs/troubleshooting/external-device-connection.md +0 -283
  40. package/docs/troubleshooting/faq.md +0 -574
  41. package/docs/tutorials/basic-examples.md +0 -718
@@ -1,399 +0,0 @@
1
- # Mesh Architecture
2
-
3
- This document explains how painlessMesh works internally, its design principles, and architectural decisions.
4
-
5
- ## Overview
6
-
7
- painlessMesh creates a self-organizing, self-healing wireless mesh network using ESP8266 and ESP32 devices. The mesh automatically handles:
8
-
9
- - **Node Discovery**: Devices find each other automatically
10
- - **Routing**: Messages find optimal paths through the network
11
- - **Topology Management**: Network adapts to nodes joining/leaving
12
- - **Time Synchronization**: All nodes maintain synchronized clocks
13
- - **Connection Management**: Automatic reconnection and load balancing
14
-
15
- ## Core Architecture
16
-
17
- ```
18
- ┌─────────────────────────────────────────────────────────────┐
19
- │ Application Layer │
20
- ├─────────────────────────────────────────────────────────────┤
21
- │ Plugin System │
22
- ├─────────────────────────────────────────────────────────────┤
23
- │ Mesh Layer │
24
- ├─────────────────────────────────────────────────────────────┤
25
- │ Protocol Layer │
26
- ├─────────────────────────────────────────────────────────────┤
27
- │ Network Layer (TCP) │
28
- ├─────────────────────────────────────────────────────────────┤
29
- │ WiFi Layer (ESP32/ESP8266) │
30
- └─────────────────────────────────────────────────────────────┘
31
- ```
32
-
33
- ### Layer Responsibilities
34
-
35
- **Application Layer**
36
- - User code and application logic
37
- - Custom message handling
38
- - Business logic implementation
39
-
40
- **Plugin System**
41
- - Type-safe message packaging
42
- - Custom package types (sensor data, commands, etc.)
43
- - Message serialization/deserialization
44
-
45
- **Mesh Layer**
46
- - Node discovery and connection management
47
- - Mesh topology maintenance
48
- - Time synchronization across nodes
49
-
50
- **Protocol Layer**
51
- - Message routing algorithms
52
- - Package type identification
53
- - Connection lifecycle management
54
-
55
- ### Protocol Message Types
56
-
57
- The protocol layer uses several internal message types for mesh management:
58
-
59
- | Type | Name | Purpose |
60
- |------|------|---------|
61
- | 3 | TIME_DELAY | Measures network latency between nodes for routing optimization |
62
- | 4 | TIME_SYNC | Synchronizes clocks across all mesh nodes |
63
- | 5 | NODE_SYNC_REQUEST | Requests node list and topology information |
64
- | 6 | NODE_SYNC_REPLY | Responds with node list and topology data |
65
- | 7 | CONTROL | Deprecated control messages (no longer used) |
66
- | 8 | BROADCAST | Routes application messages to all mesh nodes |
67
- | 9 | SINGLE | Routes application messages to a specific node |
68
-
69
- These protocol types are handled automatically by the mesh layer and enable:
70
- - **Automatic time synchronization** across all nodes
71
- - **Dynamic routing** based on measured network latency
72
- - **Topology discovery** when nodes join or leave
73
- - **Efficient message delivery** through the mesh network
74
-
75
- **Network Layer**
76
- - TCP connection handling
77
- - Message queuing and transmission
78
- - Connection multiplexing
79
-
80
- **WiFi Layer**
81
- - Low-level ESP32/ESP8266 WiFi management
82
- - Access point and station mode handling
83
- - Radio frequency management
84
-
85
- ## Network Topology
86
-
87
- painlessMesh creates a **dynamic tree topology** that automatically reorganizes based on network conditions.
88
-
89
- ### Tree Structure
90
-
91
- ```
92
- Root Node
93
- / | \
94
- Node1 Node2 Node3
95
- / \ |
96
- Node4 Node5 Node6
97
- ```
98
-
99
- ### Key Properties
100
-
101
- - **No Single Point of Failure**: If any node fails, the mesh reorganizes
102
- - **Shortest Path Routing**: Messages take optimal routes to destinations
103
- - **Load Distribution**: Connections balanced across available nodes
104
- - **Scalable**: Can handle dozens of nodes (limited by ESP memory)
105
-
106
- ### Node Roles
107
-
108
- **Root Node**
109
- - Acts as the network coordinator
110
- - Maintains network topology information
111
- - Can be any node in the network
112
- - Role automatically transfers if root fails
113
-
114
- **Intermediate Nodes**
115
- - Forward messages between other nodes
116
- - Maintain connections to parent and children
117
- - Participate in topology discovery
118
-
119
- **Leaf Nodes**
120
- - End devices with minimal connections
121
- - Typically sensor or actuator nodes
122
- - Minimal memory and processing overhead
123
-
124
- ## Message Routing
125
-
126
- painlessMesh implements multiple routing strategies:
127
-
128
- ### 1. Broadcast Routing
129
- Messages sent to all nodes in the network.
130
-
131
- ```cpp
132
- // Sender
133
- mesh.sendBroadcast("Hello everyone!");
134
-
135
- // All nodes receive the message
136
- void receivedCallback(uint32_t from, String &msg) {
137
- // Handle broadcast message
138
- }
139
- ```
140
-
141
- **Algorithm**:
142
- 1. Message originates at source node
143
- 2. Each node forwards to all connected neighbors (except sender)
144
- 3. Duplicate detection prevents loops
145
- 4. Message reaches all nodes in network
146
-
147
- ### 2. Single Node Routing
148
- Messages sent to a specific node by ID.
149
-
150
- ```cpp
151
- // Send to specific node
152
- mesh.sendSingle(targetNodeId, "Hello specific node!");
153
- ```
154
-
155
- **Algorithm**:
156
- 1. Source looks up target in routing table
157
- 2. Message forwarded to next hop toward target
158
- 3. Each intermediate node repeats until target reached
159
- 4. Automatic route discovery if target unknown
160
-
161
- ### 3. Neighbor Routing
162
- Messages sent only to directly connected neighbors.
163
-
164
- ```cpp
165
- // Plugin system example
166
- NeighbourPackage pkg;
167
- mesh.sendPackage(&pkg);
168
- ```
169
-
170
- **Use Cases**:
171
- - Topology discovery
172
- - Local status updates
173
- - Connection management
174
-
175
- ## Connection Management
176
-
177
- ### Connection Lifecycle
178
-
179
- ```
180
- Disconnected → Discovering → Connecting → Connected → Disconnected
181
- ↑ ↓
182
- └────────── Connection Lost ←───────────┘
183
- ```
184
-
185
- ### Discovery Process
186
-
187
- 1. **Scan Phase**: Node scans for available mesh networks
188
- 2. **Evaluation Phase**: Evaluates signal strength and load
189
- 3. **Connection Phase**: Establishes TCP connection
190
- 4. **Handshake Phase**: Exchanges node information
191
- 5. **Integration Phase**: Updates routing tables
192
-
193
- ### Connection Parameters
194
-
195
- ```cpp
196
- // Maximum connections per node
197
- #define MAX_CONN 4
198
-
199
- // Connection timeout
200
- #define CONNECTION_TIMEOUT 30000
201
-
202
- // Reconnection interval
203
- #define RECONNECT_INTERVAL 10000
204
- ```
205
-
206
- ### Load Balancing
207
-
208
- - Nodes prefer connections with fewer existing connections
209
- - Signal strength influences connection preference
210
- - Automatic connection redistribution when topology changes
211
-
212
- ## Time Synchronization
213
-
214
- painlessMesh maintains synchronized time across all nodes using a distributed algorithm.
215
-
216
- ### Synchronization Process
217
-
218
- 1. **Root Election**: Node with most connections becomes time root
219
- 2. **Time Distribution**: Root broadcasts its time periodically
220
- 3. **Offset Calculation**: Each node calculates offset from root
221
- 4. **Propagation**: Time updates propagate through mesh hierarchy
222
-
223
- ### Time API
224
-
225
- ```cpp
226
- // Get synchronized mesh time
227
- uint32_t meshTime = mesh.getNodeTime();
228
-
229
- // Convert to milliseconds since startup
230
- uint32_t meshTimeMs = meshTime / 1000;
231
-
232
- // Time adjustment callback
233
- void nodeTimeAdjustedCallback(int32_t offset) {
234
- Serial.printf("Time adjusted by %d microseconds\n", offset);
235
- }
236
- ```
237
-
238
- ### Use Cases
239
-
240
- - **Synchronized Actions**: All nodes can execute actions at same time
241
- - **Data Timestamping**: Consistent timestamps across sensors
242
- - **Event Correlation**: Match events across different nodes
243
- - **Scheduling**: Coordinate scheduled tasks
244
-
245
- ## Memory Management
246
-
247
- ### Memory Layout (ESP32)
248
-
249
- ```
250
- ┌─────────────────────┐ 320KB Total RAM
251
- │ Application │
252
- ├─────────────────────┤
253
- │ Mesh Buffers │ ~50-100KB
254
- ├─────────────────────┤
255
- │ TCP Buffers │ ~20-40KB
256
- ├─────────────────────┤
257
- │ WiFi Stack │ ~30-50KB
258
- ├─────────────────────┤
259
- │ System/FreeRTOS │ ~50-100KB
260
- └─────────────────────┘
261
- ```
262
-
263
- ### Memory Optimization
264
-
265
- **Message Queuing**
266
- - Outbound message queue per connection
267
- - Configurable queue sizes
268
- - Automatic message dropping under memory pressure
269
-
270
- **Connection Limits**
271
- - Maximum connections limit prevents memory exhaustion
272
- - Dynamic connection management based on available memory
273
-
274
- **Buffer Management**
275
- - Shared buffer pools for message processing
276
- - Automatic garbage collection of unused buffers
277
-
278
- ### ESP8266 Considerations
279
-
280
- - **Limited RAM**: ~80KB total, requires careful memory management
281
- - **Fewer Connections**: Typically 2-4 max connections
282
- - **Smaller Buffers**: Reduced message queue sizes
283
- - **Conservative Limits**: More aggressive connection limits
284
-
285
- ## Error Handling
286
-
287
- ### Connection Failures
288
-
289
- ```cpp
290
- void droppedConnectionCallback(uint32_t nodeId) {
291
- Serial.printf("Lost connection to node %u\n", nodeId);
292
- // Mesh automatically attempts reconnection
293
- }
294
- ```
295
-
296
- ### Message Delivery
297
-
298
- - **Best Effort**: No guaranteed delivery by default
299
- - **Automatic Retry**: Connection-level retries for TCP
300
- - **Route Recovery**: Automatic routing table updates
301
- - **Graceful Degradation**: Network continues with reduced connectivity
302
-
303
- ### Network Partitions
304
-
305
- When the mesh splits into separate networks:
306
-
307
- 1. **Detection**: Nodes detect missing connections
308
- 2. **Recovery Attempts**: Try to reconnect to lost nodes
309
- 3. **Partition Handling**: Each partition operates independently
310
- 4. **Reunification**: Automatic merge when connectivity restored
311
-
312
- ## Performance Characteristics
313
-
314
- ### Throughput
315
-
316
- - **Per Connection**: ~100-500 KB/s depending on ESP model
317
- - **Network Wide**: Scales with number of parallel paths
318
- - **Bottlenecks**: Root node can become bottleneck in star topology
319
-
320
- ### Latency
321
-
322
- - **Direct Connection**: 10-50ms typical
323
- - **Multi-hop**: +20-50ms per hop
324
- - **Factors**: Network load, message size, ESP processing speed
325
-
326
- ### Scalability
327
-
328
- - **Node Count**: 10-50 nodes typical (limited by memory and connections)
329
- - **Network Diameter**: 5-7 hops maximum recommended
330
- - **Geographic Range**: 50-200m typical WiFi range
331
-
332
- ## Design Decisions
333
-
334
- ### Why Tree Topology?
335
-
336
- **Advantages**:
337
- - Simple routing algorithms
338
- - No loops (prevents broadcast storms)
339
- - Efficient bandwidth utilization
340
- - Predictable behavior
341
-
342
- **Trade-offs**:
343
- - Single points of failure (mitigated by automatic reorganization)
344
- - Not optimal for all traffic patterns
345
- - Root node may become bottleneck
346
-
347
- ### Why TCP?
348
-
349
- **Advantages**:
350
- - Reliable delivery within connections
351
- - Flow control prevents buffer overflow
352
- - Standard protocol with good tools
353
-
354
- **Trade-offs**:
355
- - Higher overhead than UDP
356
- - Connection setup latency
357
- - Memory overhead for connection state
358
-
359
- ### Why JSON Messages?
360
-
361
- **Advantages**:
362
- - Human-readable debugging
363
- - Flexible schema evolution
364
- - Good library support
365
- - Cross-platform compatibility
366
-
367
- **Trade-offs**:
368
- - Higher bandwidth usage than binary
369
- - Parsing overhead
370
- - Larger memory footprint
371
-
372
- ## Security Considerations
373
-
374
- ### Current Security
375
-
376
- - **Network Password**: Simple WPA2 network password
377
- - **No Message Encryption**: Messages sent in plaintext over WiFi
378
- - **No Authentication**: Nodes with correct password can join
379
-
380
- ### Security Limitations
381
-
382
- - Vulnerable to network sniffing
383
- - No node authentication beyond network password
384
- - No message integrity verification
385
- - Susceptible to man-in-the-middle attacks
386
-
387
- ### Future Enhancements
388
-
389
- - Message-level encryption
390
- - Node certificates and authentication
391
- - Perfect forward secrecy
392
- - Secure key distribution
393
-
394
- ## Next Steps
395
-
396
- - Learn about the [Plugin System](plugin-system.md)
397
- - Understand [Message Routing](routing.md) in detail
398
- - Explore [Time Synchronization](time-sync.md) mechanisms
399
- - See [Performance Optimization](../advanced/performance.md) techniques