@alteriom/painlessmesh 1.6.1 → 1.7.2

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 (129) hide show
  1. package/CHANGELOG.md +380 -143
  2. package/LICENSE +674 -674
  3. package/README.md +477 -434
  4. package/RELEASE_GUIDE.md +504 -418
  5. package/docs/DOCUMENTATION_MIGRATION_PLAN.md +175 -175
  6. package/docs/IMPLEMENTATION_PLAN_MESH_TOPOLOGY.md +1062 -0
  7. package/docs/MESH_TOPOLOGY_GUIDE.md +992 -0
  8. package/docs/MESH_TOPOLOGY_PROGRESS.md +422 -0
  9. package/docs/MQTT_BRIDGE_COMMANDS.md +894 -0
  10. package/docs/MQTT_BRIDGE_IMPLEMENTATION_SUMMARY.md +324 -0
  11. package/docs/MQTT_COMMAND_SCHEMA_PROPOSAL.md +576 -0
  12. package/docs/MQTT_SCHEMA_COMPLIANCE.md +285 -0
  13. package/docs/MQTT_SCHEMA_PROPOSALS.md +446 -0
  14. package/docs/MQTT_SCHEMA_REVIEW.md +690 -0
  15. package/docs/OTA_COMMANDS_REFERENCE.md +554 -0
  16. package/docs/PHASE1_GUIDE.md +349 -0
  17. package/docs/PHASE2_GUIDE.md +543 -0
  18. package/docs/README.md +77 -70
  19. package/docs/SCHEMA_VALIDATION_CHECKLIST.md +222 -0
  20. package/docs/alteriom/overview.md +507 -507
  21. package/docs/api/core-api.md +606 -606
  22. package/docs/architecture/mesh-architecture.md +378 -378
  23. package/docs/architecture/plugin-system.md +516 -516
  24. package/docs/getting-started/first-mesh.md +409 -409
  25. package/docs/getting-started/installation.md +274 -274
  26. package/docs/getting-started/quickstart.md +157 -157
  27. package/docs/improvements/FEATURE_PROPOSALS.md +337 -0
  28. package/docs/improvements/PHASE1_IMPLEMENTATION.md +325 -0
  29. package/docs/improvements/PHASE2_IMPLEMENTATION.md +567 -0
  30. package/docs/improvements/README.md +86 -68
  31. package/docs/improvements/ota-and-status-enhancements.md +911 -0
  32. package/docs/improvements/ota-status-architecture-diagrams.md +658 -0
  33. package/docs/improvements/ota-status-quick-reference.md +284 -0
  34. package/docs/platformio-publishing.md +255 -0
  35. package/docs/platformio-setup-summary.md +121 -0
  36. package/docs/troubleshooting/common-issues.md +520 -520
  37. package/docs/troubleshooting/faq.md +472 -472
  38. package/docs/tutorials/basic-examples.md +717 -717
  39. package/docs/wiki/API-Reference.md +245 -245
  40. package/docs/wiki/Complete-Documentation.md +122 -122
  41. package/examples/alteriom/README.md +139 -81
  42. package/examples/alteriom/alteriom.ino +186 -185
  43. package/examples/alteriom/alteriom_sensor_package.hpp +240 -127
  44. package/examples/alteriom/platformio.ini +24 -24
  45. package/examples/alteriomImproved/alteriom_sensor_package.hpp +224 -0
  46. package/examples/{alteriom → alteriomImproved}/improved_sensor_node.ino +245 -245
  47. package/examples/alteriomImproved/platformio.ini +25 -0
  48. package/examples/alteriomPhase1/alteriom_sensor_package.hpp +224 -0
  49. package/examples/alteriomPhase1/phase1_features.ino +242 -0
  50. package/examples/alteriomPhase1/platformio.ini +25 -0
  51. package/examples/alteriomPhase2/alteriom_sensor_package.hpp +224 -0
  52. package/examples/alteriomPhase2/phase2_features.ino +186 -0
  53. package/examples/alteriomPhase2/platformio.ini +25 -0
  54. package/examples/{alteriom → alteriomSensorNode}/alteriom_sensor_node.ino +183 -183
  55. package/examples/alteriomSensorNode/alteriom_sensor_package.hpp +224 -0
  56. package/examples/alteriomSensorNode/platformio.ini +25 -0
  57. package/examples/basic/basic.ino +66 -66
  58. package/examples/basic/platformio.ini +25 -25
  59. package/examples/bridge/bridge.ino +51 -51
  60. package/examples/bridge/mesh_event_publisher.hpp +253 -0
  61. package/examples/bridge/mesh_topology_reporter.hpp +303 -0
  62. package/examples/bridge/mqtt_command_bridge.hpp +459 -0
  63. package/examples/bridge/mqtt_status_bridge.hpp +519 -0
  64. package/examples/bridge/platformio.ini +25 -25
  65. package/examples/echoNode/echoNode.ino +33 -33
  66. package/examples/echoNode/platformio.ini +25 -25
  67. package/examples/logClient/logClient.ino +109 -109
  68. package/examples/logClient/platformio.ini +25 -25
  69. package/examples/logServer/logServer.ino +81 -81
  70. package/examples/logServer/platformio.ini +25 -25
  71. package/examples/meshCommandNode/alteriom_sensor_package.hpp +235 -0
  72. package/examples/meshCommandNode/meshCommandNode.ino +263 -0
  73. package/examples/meshCommandNode/platformio.ini +25 -0
  74. package/examples/mqttBridge/mqttBridge.ino +118 -118
  75. package/examples/mqttBridge/platformio.ini +26 -26
  76. package/examples/mqttCommandBridge/alteriom_sensor_package.hpp +235 -0
  77. package/examples/mqttCommandBridge/mesh_event_publisher.hpp +253 -0
  78. package/examples/mqttCommandBridge/mesh_topology_reporter.hpp +303 -0
  79. package/examples/mqttCommandBridge/mqttCommandBridge.ino +252 -0
  80. package/examples/mqttCommandBridge/mqtt_command_bridge.hpp +459 -0
  81. package/examples/mqttCommandBridge/platformio.ini +26 -0
  82. package/examples/mqttStatusBridge/mqttStatusBridge.ino +216 -0
  83. package/examples/mqttStatusBridge/mqtt_status_bridge.hpp +522 -0
  84. package/examples/mqttStatusBridge/platformio.ini +26 -0
  85. package/examples/mqttTopologyTest/README.md +467 -0
  86. package/examples/mqttTopologyTest/mqttTopologyTest.ino +748 -0
  87. package/examples/mqttTopologyTest/platformio.ini +26 -0
  88. package/examples/namedMesh/namedMesh.ino +97 -97
  89. package/examples/namedMesh/platformio.ini +25 -25
  90. package/examples/otaReceiver/otaReceiver.ino +79 -79
  91. package/examples/otaReceiver/platformio.ini +25 -25
  92. package/examples/otaSender/otaSender.ino +160 -151
  93. package/examples/otaSender/platformio.ini +25 -25
  94. package/examples/startHere/platformio.ini +25 -25
  95. package/examples/startHere/startHere.ino +159 -159
  96. package/examples/webServer/platformio.ini +27 -27
  97. package/examples/webServer/webServer.ino +89 -89
  98. package/keywords.txt +48 -48
  99. package/library.json +55 -34
  100. package/library.properties +10 -10
  101. package/package.json +86 -78
  102. package/src/AlteriomPainlessMesh.h +97 -97
  103. package/src/arduino/wifi.hpp +365 -365
  104. package/src/boost/asynctcp.hpp +279 -279
  105. package/src/painlessMesh.h +70 -70
  106. package/src/painlessMeshSTA.cpp +236 -236
  107. package/src/painlessMeshSTA.h +58 -58
  108. package/src/painlessTaskOptions.h +4 -4
  109. package/src/painlessmesh/base64.hpp +111 -111
  110. package/src/painlessmesh/buffer.hpp +229 -229
  111. package/src/painlessmesh/callback.hpp +91 -91
  112. package/src/painlessmesh/configuration.hpp +77 -77
  113. package/src/painlessmesh/connection.hpp +192 -192
  114. package/src/painlessmesh/layout.hpp +188 -188
  115. package/src/painlessmesh/logger.hpp +158 -158
  116. package/src/painlessmesh/memory.hpp +119 -119
  117. package/src/painlessmesh/mesh.hpp +761 -560
  118. package/src/painlessmesh/metrics.hpp +322 -322
  119. package/src/painlessmesh/ntp.hpp +263 -263
  120. package/src/painlessmesh/ota.hpp +582 -553
  121. package/src/painlessmesh/plugin.hpp +188 -188
  122. package/src/painlessmesh/protocol.hpp +813 -813
  123. package/src/painlessmesh/router.hpp +322 -322
  124. package/src/painlessmesh/tcp.hpp +71 -71
  125. package/src/painlessmesh/validation.hpp +238 -238
  126. package/src/plugin/performance.hpp +214 -214
  127. package/src/plugin/remote.hpp +64 -64
  128. package/src/scheduler.cpp +10 -10
  129. package/src/wifi.cpp +2 -2
@@ -0,0 +1,324 @@
1
+ # MQTT Bridge Command System - Implementation Summary
2
+
3
+ ## Overview
4
+
5
+ Successfully implemented a comprehensive MQTT-to-mesh bridge command system for painlessMesh Alteriom fork. This enables bidirectional communication between MQTT brokers and mesh networks, allowing web applications and external systems to control and monitor mesh nodes.
6
+
7
+ ## Files Created
8
+
9
+ ### Documentation
10
+
11
+ 1. **`docs/MQTT_BRIDGE_COMMANDS.md`** (551 lines)
12
+ - Complete command reference with 25+ command types
13
+ - MQTT topic structure and naming conventions
14
+ - Implementation guide with code examples
15
+ - JavaScript and Python client examples
16
+ - Troubleshooting guide and best practices
17
+
18
+ ### Implementation
19
+
20
+ 2. **`examples/bridge/mqtt_command_bridge.hpp`** (417 lines)
21
+ - Bidirectional MQTT-mesh bridge class
22
+ - Command routing and forwarding logic
23
+ - Configuration management
24
+ - Response handling and topic mapping
25
+ - Support for all command types (device control, configuration, status)
26
+
27
+ 3. **`examples/mqttCommandBridge/mqttCommandBridge.ino`** (181 lines)
28
+ - Complete gateway bridge Arduino sketch
29
+ - WiFi and MQTT connection management
30
+ - Periodic status reporting
31
+ - Topology updates
32
+ - Event notifications (node connections/disconnections)
33
+
34
+ 4. **`examples/alteriom/mesh_command_node.ino`** (217 lines)
35
+ - Mesh node command handler example
36
+ - Support for LED control, relay switching, PWM, sleep commands
37
+ - Configuration management
38
+ - Status reporting
39
+ - Command acknowledgment system
40
+
41
+ ### Core Package Enhancement
42
+
43
+ 5. **`examples/alteriom/alteriom_sensor_package.hpp`** (Modified)
44
+ - Added `responseToCommand` field to StatusPackage
45
+ - Added `responseMessage` field to StatusPackage
46
+ - Enhanced JSON serialization to include response fields
47
+ - Maintains backward compatibility (fields only included when non-zero)
48
+
49
+ ### Testing
50
+
51
+ 6. **`test/catch/catch_mqtt_bridge.cpp`** (430 lines)
52
+ - 8 comprehensive test scenarios
53
+ - Command routing tests
54
+ - Parameter parsing tests
55
+ - Configuration management tests
56
+ - Command ID tracking tests
57
+ - Broadcast command tests
58
+ - Error handling tests
59
+ - 45+ individual test assertions
60
+
61
+ ### Repository Updates
62
+
63
+ 7. **`README.md`** (Modified)
64
+ - Added "MQTT Bridge Commands" section
65
+ - Linked to new documentation
66
+ - Listed example sketches
67
+ - Highlighted key capabilities
68
+
69
+ ## Command Types Implemented
70
+
71
+ ### Device Control (1-99)
72
+ - RESET (1) - Restart device
73
+ - SLEEP (2) - Enter deep sleep
74
+ - WAKE (3) - Wake from sleep
75
+ - LED_CONTROL (10) - Control onboard LED
76
+ - RELAY_SWITCH (11) - Control relay output
77
+ - PWM_SET (12) - Set PWM output
78
+ - SENSOR_ENABLE (20) - Enable/disable sensor
79
+ - SENSOR_CALIBRATE (21) - Calibrate sensor
80
+
81
+ ### Configuration (100-199)
82
+ - GET_CONFIG (100) - Request current configuration
83
+ - SET_CONFIG (101) - Update configuration
84
+ - RESET_CONFIG (102) - Reset to factory defaults
85
+ - SAVE_CONFIG (103) - Persist config to flash
86
+ - SET_SAMPLE_RATE (110) - Change sensor sample rate
87
+ - SET_DEVICE_NAME (111) - Update device name
88
+
89
+ ### Status (200-255)
90
+ - GET_STATUS (200) - Request basic status
91
+ - GET_METRICS (201) - Request performance metrics
92
+ - GET_DIAGNOSTICS (202) - Request detailed diagnostics
93
+ - START_MONITORING (210) - Begin continuous monitoring
94
+ - STOP_MONITORING (211) - Stop continuous monitoring
95
+
96
+ ## MQTT Topics
97
+
98
+ ### Command Topics (Published by Web App)
99
+ ```
100
+ mesh/command/{nodeId} # Send command to specific node
101
+ mesh/command/broadcast # Broadcast command to all nodes
102
+ mesh/config/{nodeId}/get # Request configuration
103
+ mesh/config/{nodeId}/set # Update configuration
104
+ mesh/ota/{nodeId}/start # Initiate OTA update
105
+ ```
106
+
107
+ ### Response Topics (Published by Gateway Bridge)
108
+ ```
109
+ mesh/response/{nodeId} # Command acknowledgments
110
+ mesh/status/{nodeId} # Status updates (Type 202)
111
+ mesh/sensor/{nodeId} # Sensor data (Type 200)
112
+ mesh/health/{nodeId} # Enhanced status (Type 203)
113
+ mesh/config/{nodeId} # Configuration data
114
+ mesh/error/{nodeId} # Error reports
115
+ ```
116
+
117
+ ### System Topics
118
+ ```
119
+ mesh/gateway/status # Gateway bridge health
120
+ mesh/topology # Mesh network topology
121
+ mesh/nodes # List of connected nodes
122
+ mesh/events # Connection/disconnection events
123
+ ```
124
+
125
+ ## Architecture
126
+
127
+ ```
128
+ ┌─────────────────┐ MQTT ┌──────────────┐ Mesh ┌────────────┐
129
+ │ Web Application │ ◄──────────────► │ Gateway Node │ ◄──────────────► │ Mesh Nodes │
130
+ │ (Publisher) │ │ (Bridge) │ │ (Handlers) │
131
+ └─────────────────┘ └──────────────┘ └────────────┘
132
+
133
+
134
+ ┌──────────────┐
135
+ │ MQTT Broker │
136
+ │ (Mosquitto) │
137
+ └──────────────┘
138
+ ```
139
+
140
+ ## Key Features
141
+
142
+ ### 1. Command Routing
143
+ - **Unicast**: Commands targeted at specific nodes by nodeId
144
+ - **Broadcast**: Commands sent to all mesh nodes (targetDevice = 0)
145
+ - **Local Execution**: Gateway can execute commands on itself
146
+ - **Forwarding**: Automatic routing through mesh network
147
+
148
+ ### 2. Response Tracking
149
+ - **Command IDs**: Unique identifiers for request/response matching
150
+ - **Acknowledgments**: Nodes send responses back through gateway
151
+ - **Status Codes**: 0=OK, 1=Warning, 2=Error
152
+ - **Message Context**: Detailed success/error messages
153
+
154
+ ### 3. Configuration Management
155
+ - **Get Configuration**: Request current node settings
156
+ - **Set Configuration**: Update node settings remotely
157
+ - **Validation**: Parameter validation before applying
158
+ - **Persistence**: Support for saving to flash/EEPROM
159
+
160
+ ### 4. Event Notifications
161
+ - **Node Connections**: Notifications when nodes join mesh
162
+ - **Node Disconnections**: Notifications when nodes leave mesh
163
+ - **Topology Updates**: Periodic mesh network structure reports
164
+ - **Gateway Health**: Regular heartbeat from gateway
165
+
166
+ ## Usage Examples
167
+
168
+ ### JavaScript (Node.js)
169
+ ```javascript
170
+ const mqtt = require('mqtt');
171
+ const client = mqtt.connect('mqtt://192.168.1.100:1883');
172
+
173
+ // Send LED control command
174
+ const command = {
175
+ type: 201,
176
+ command: 10,
177
+ targetDevice: 123456,
178
+ commandId: Date.now(),
179
+ parameters: JSON.stringify({ state: true, brightness: 75 })
180
+ };
181
+
182
+ client.publish('mesh/command/123456', JSON.stringify(command));
183
+
184
+ // Listen for response
185
+ client.subscribe('mesh/response/123456');
186
+ client.on('message', (topic, message) => {
187
+ const response = JSON.parse(message.toString());
188
+ console.log(`Command ${response.responseToCommand}: ${response.responseMessage}`);
189
+ });
190
+ ```
191
+
192
+ ### Python
193
+ ```python
194
+ import paho.mqtt.client as mqtt
195
+ import json
196
+
197
+ def on_message(client, userdata, msg):
198
+ response = json.loads(msg.payload.decode())
199
+ if "responseToCommand" in response:
200
+ print(f"Command {response['responseToCommand']}: {response['responseMessage']}")
201
+
202
+ client = mqtt.Client()
203
+ client.on_message = on_message
204
+ client.connect("192.168.1.100", 1883, 60)
205
+
206
+ # Send command
207
+ command = {
208
+ "type": 201,
209
+ "command": 10,
210
+ "targetDevice": 123456,
211
+ "commandId": 1001,
212
+ "parameters": json.dumps({"state": True, "brightness": 75})
213
+ }
214
+
215
+ client.publish("mesh/command/123456", json.dumps(command))
216
+ client.subscribe("mesh/response/123456")
217
+ client.loop_forever()
218
+ ```
219
+
220
+ ## Testing
221
+
222
+ ### Test Coverage
223
+ - ✅ Command package serialization/deserialization
224
+ - ✅ Parameter parsing for all command types
225
+ - ✅ Response field handling in StatusPackage
226
+ - ✅ Command ID tracking and matching
227
+ - ✅ Broadcast command routing
228
+ - ✅ Configuration management workflows
229
+ - ✅ Error handling and validation
230
+ - ✅ JSON format compliance
231
+
232
+ ### Test Execution
233
+ Tests are configured in `CMakeLists.txt` and will be auto-discovered:
234
+ ```bash
235
+ cmake -G Ninja .
236
+ ninja
237
+ ./bin/catch_mqtt_bridge
238
+ ```
239
+
240
+ ## Integration with Existing Phase 2 Features
241
+
242
+ ### OTA Updates via MQTT
243
+ The MQTT bridge can trigger OTA updates:
244
+ ```json
245
+ {
246
+ "topic": "mesh/ota/123456/start",
247
+ "payload": {
248
+ "role": "sensor",
249
+ "hardware": "ESP32",
250
+ "md5": "abc123...",
251
+ "broadcasted": true
252
+ }
253
+ }
254
+ ```
255
+
256
+ ### Status Reporting
257
+ Nodes automatically report status via MQTT:
258
+ - SensorPackage (200) → `mesh/sensor/{nodeId}`
259
+ - StatusPackage (202) → `mesh/status/{nodeId}`
260
+ - EnhancedStatusPackage (203) → `mesh/health/{nodeId}`
261
+
262
+ ## Dependencies
263
+
264
+ ### Arduino/PlatformIO
265
+ - painlessMesh (core library)
266
+ - PubSubClient (MQTT client)
267
+ - ArduinoJson (JSON serialization)
268
+ - TaskScheduler (background tasks)
269
+
270
+ ### MQTT Broker
271
+ - Mosquitto (recommended)
272
+ - HiveMQ
273
+ - AWS IoT Core
274
+ - Azure IoT Hub
275
+
276
+ ## Security Considerations
277
+
278
+ ### Current Implementation
279
+ - No authentication on MQTT commands (prototype)
280
+ - No command signature verification
281
+ - No rate limiting
282
+
283
+ ### Production Recommendations
284
+ 1. **Enable MQTT Authentication**: Use username/password or certificates
285
+ 2. **Implement ACLs**: Restrict topic access per client
286
+ 3. **Add Rate Limiting**: Prevent command flooding
287
+ 4. **Validate Commands**: Check command bounds and parameters
288
+ 5. **Use TLS/SSL**: Encrypt MQTT traffic
289
+ 6. **Command Signing**: Add HMAC signatures to verify command authenticity
290
+
291
+ ## Future Enhancements
292
+
293
+ ### Potential Features
294
+ 1. **Command Queue**: Store commands for offline nodes
295
+ 2. **Priority Commands**: Urgent commands bypass queue
296
+ 3. **Batch Commands**: Send multiple commands in one message
297
+ 4. **Command History**: Track all commands sent/received
298
+ 5. **Scheduled Commands**: Execute commands at specific times
299
+ 6. **Conditional Commands**: Execute based on node state
300
+ 7. **Command Templates**: Predefined command sequences
301
+
302
+ ### Performance Optimizations
303
+ 1. **Message Compression**: Reduce payload sizes
304
+ 2. **Persistent Sessions**: Maintain MQTT subscriptions
305
+ 3. **QoS Levels**: Adjust quality of service per topic
306
+ 4. **Topic Wildcards**: Reduce subscription count
307
+ 5. **Retained Messages**: Store last known values
308
+
309
+ ## Documentation Links
310
+
311
+ - 📖 [MQTT Bridge Commands Reference](../docs/MQTT_BRIDGE_COMMANDS.md)
312
+ - 🔧 [OTA Commands Reference](../docs/OTA_COMMANDS_REFERENCE.md)
313
+ - 🌉 [MQTT Command Bridge Example](../examples/mqttCommandBridge/mqttCommandBridge.ino)
314
+ - 📡 [Mesh Command Node Example](../examples/alteriom/mesh_command_node.ino)
315
+ - 📚 [API Documentation](https://alteriom.github.io/painlessMesh/)
316
+
317
+ ## Author
318
+
319
+ Alteriom Development Team
320
+ October 2024
321
+
322
+ ## License
323
+
324
+ Same as painlessMesh: GNU GENERAL PUBLIC LICENSE V3