@alteriom/painlessmesh 1.8.15 → 1.9.0

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 (208) hide show
  1. package/BRIDGE_TO_INTERNET.md +229 -0
  2. package/CHANGELOG.md +61 -1
  3. package/CONTRIBUTING.md +79 -0
  4. package/README.md +69 -144
  5. package/docs/README.md +1 -0
  6. package/docs/api/shared-gateway.md +1207 -0
  7. package/examples/bridge_failover/README.md +81 -0
  8. package/examples/bridge_failover/bridge_failover.ino +35 -4
  9. package/examples/sharedGateway/README.md +235 -0
  10. package/examples/{meshCommandNode → sharedGateway}/platformio.ini +3 -2
  11. package/examples/sharedGateway/sharedGateway.ino +303 -0
  12. package/library.json +3 -22
  13. package/library.properties +1 -1
  14. package/package.json +3 -6
  15. package/src/arduino/wifi.hpp +342 -4
  16. package/src/painlessmesh/gateway.hpp +2120 -0
  17. package/src/painlessmesh/mesh.hpp +1034 -6
  18. package/src/painlessmesh/message_tracker.hpp +311 -0
  19. package/src/painlessmesh/protocol.hpp +6 -0
  20. package/DOCUMENTATION_INDEX.md +0 -146
  21. package/RELEASE_NOTES_1.8.15.md +0 -160
  22. package/RELEASE_READINESS_PLAN.md +0 -323
  23. package/TESTING_WITH_SIMULATOR.md +0 -259
  24. package/docs/API_DESIGN_GUIDELINES.md +0 -414
  25. package/docs/ARDUINO_LIBRARY_MANAGER_SUBMISSION.md +0 -331
  26. package/docs/BOOLEAN_NAMING_CONVENTION.md +0 -235
  27. package/docs/BRIDGE_FAILOVER.md +0 -512
  28. package/docs/BRIDGE_HEALTH_MONITORING.md +0 -293
  29. package/docs/BRIDGE_INITIALIZATION_FALLBACK.md +0 -357
  30. package/docs/CHANNEL_SYNCHRONIZATION.md +0 -209
  31. package/docs/CREATE_MISSING_RELEASES.md +0 -321
  32. package/docs/DOCUMENTATION_MIGRATION_PLAN.md +0 -176
  33. package/docs/FAQ_VERSION_NUMBERS.md +0 -152
  34. package/docs/IMPLEMENTATION_PLAN_MESH_TOPOLOGY.md +0 -1062
  35. package/docs/MESH_TOPOLOGY_GUIDE.md +0 -992
  36. package/docs/MESH_TOPOLOGY_PROGRESS.md +0 -422
  37. package/docs/MQTT_BRIDGE_COMMANDS.md +0 -894
  38. package/docs/MQTT_BRIDGE_IMPLEMENTATION_SUMMARY.md +0 -324
  39. package/docs/MQTT_COMMAND_SCHEMA_PROPOSAL.md +0 -576
  40. package/docs/MQTT_SCHEMA_COMPLIANCE.md +0 -340
  41. package/docs/MQTT_SCHEMA_PROPOSALS.md +0 -446
  42. package/docs/MQTT_SCHEMA_REVIEW.md +0 -690
  43. package/docs/OTA_COMMANDS_REFERENCE.md +0 -554
  44. package/docs/PHASE1_GUIDE.md +0 -349
  45. package/docs/PHASE2_GUIDE.md +0 -543
  46. package/docs/QUICK_REFERENCE_VERSIONING.md +0 -127
  47. package/docs/RELEASE_AGENT_SUMMARY.md +0 -386
  48. package/docs/SCHEMA_VALIDATION_CHECKLIST.md +0 -222
  49. package/docs/SIMULATOR_TESTING.md +0 -408
  50. package/docs/VERSION_MANAGEMENT.md +0 -213
  51. package/docs/archive/DOCUSAURUS_DEPLOYMENT.md +0 -166
  52. package/docs/archive/FEATURE_PROPOSALS.md +0 -337
  53. package/docs/archive/LIBRARY_JSON_FIX.md +0 -98
  54. package/docs/archive/LIBRARY_STRUCTURE_FIX.md +0 -215
  55. package/docs/archive/PHASE1_IMPLEMENTATION.md +0 -325
  56. package/docs/archive/PHASE2_IMPLEMENTATION.md +0 -567
  57. package/docs/archive/RELEASE_SUMMARY.md +0 -173
  58. package/docs/archive/SCONS_BUILD_FIX.md +0 -313
  59. package/docs/archive/TRIGGER_RELEASE.md +0 -280
  60. package/docs/archive/VECTOR_INCLUDE_FIX.md +0 -129
  61. package/docs/archive/ota-and-status-enhancements.md +0 -911
  62. package/docs/archive/ota-status-architecture-diagrams.md +0 -658
  63. package/docs/archive/ota-status-quick-reference.md +0 -284
  64. package/docs/design/.gitkeep +0 -1
  65. package/docs/design/STATION_CREDENTIALS_DESIGN.md +0 -182
  66. package/docs/development/ARDUINO_COMPLIANCE_SUMMARY.md +0 -71
  67. package/docs/development/CODE_REFACTORING_RECOMMENDATIONS.md +0 -1011
  68. package/docs/development/DOCKER_TESTING.md +0 -196
  69. package/docs/development/PLATFORMIO_USAGE.md +0 -180
  70. package/docs/development/TESTING_SUMMARY.md +0 -126
  71. package/docs/development/contributing.md +0 -301
  72. package/docs/development/documentation.md +0 -583
  73. package/docs/features/DIAGNOSTICS_API.md +0 -534
  74. package/docs/implementation/BRIDGE_ARCHITECTURE_IMPLEMENTATION.md +0 -340
  75. package/docs/implementation/BRIDGE_HEALTH_MONITORING_IMPLEMENTATION.md +0 -213
  76. package/docs/implementation/BRIDGE_STATUS_FEATURE.md +0 -635
  77. package/docs/implementation/DIAGNOSTICS_API_IMPLEMENTATION.md +0 -232
  78. package/docs/implementation/IMPLEMENTATION_COMPLETE.md +0 -228
  79. package/docs/implementation/IMPLEMENTATION_NTP_TIME_SYNC.md +0 -325
  80. package/docs/implementation/IMPLEMENTATION_SUMMARY.md +0 -316
  81. package/docs/implementation/MESSAGE_QUEUE_IMPLEMENTATION.md +0 -405
  82. package/docs/implementation/MULTI_BRIDGE_IMPLEMENTATION.md +0 -520
  83. package/docs/implementation/NTP_TIME_SYNC_FEATURE.md +0 -392
  84. package/docs/improvements/FUTURE_PROPOSALS.md +0 -1016
  85. package/docs/improvements/IMPLEMENTATION_HISTORY.md +0 -1091
  86. package/docs/improvements/OTA_STATUS_ENHANCEMENTS.md +0 -709
  87. package/docs/improvements/README.md +0 -212
  88. package/docs/internal/CUSTOM_AGENT_ANALYSIS.md +0 -391
  89. package/docs/internal/ISSUE_65_VERIFICATION.md +0 -947
  90. package/docs/internal/ISSUE_66_CLOSURE.md +0 -249
  91. package/docs/internal/ISSUE_66_STATUS.md +0 -316
  92. package/docs/internal/PR_SUMMARY.md +0 -315
  93. package/docs/internal/REVIEW_SUMMARY.md +0 -332
  94. package/docs/multi-bridge-setup.md +0 -1025
  95. package/docs/platformio-publishing.md +0 -255
  96. package/docs/platformio-setup-summary.md +0 -121
  97. package/docs/releases/ANNOUNCEMENT_v1.8.6.md +0 -63
  98. package/docs/releases/ANNOUNCEMENT_v1.8.7.md +0 -113
  99. package/docs/releases/BRIDGE_STATUS_SELF_REGISTRATION_FIX.md +0 -221
  100. package/docs/releases/FEATURE_HISTORY.md +0 -543
  101. package/docs/releases/GITHUB_RELEASE_v1.8.6.md +0 -71
  102. package/docs/releases/GITHUB_RELEASE_v1.8.7.md +0 -90
  103. package/docs/releases/PATCH_v1.7.2.md +0 -262
  104. package/docs/releases/PATCH_v1.7.3.md +0 -262
  105. package/docs/releases/PATCH_v1.7.4.md +0 -219
  106. package/docs/releases/PHASE1_SUMMARY.md +0 -246
  107. package/docs/releases/PHASE2_SUMMARY.md +0 -499
  108. package/docs/releases/PUBLISH_v1.8.0_INSTRUCTIONS.md +0 -163
  109. package/docs/releases/QUICK_START_RELEASES.md +0 -113
  110. package/docs/releases/RELEASE_CHECKLIST_1.8.10.md +0 -331
  111. package/docs/releases/RELEASE_CHECKLIST_1.8.9.md +0 -207
  112. package/docs/releases/RELEASE_CHECKLIST_v1.7.4.md +0 -253
  113. package/docs/releases/RELEASE_CHECKLIST_v1.7.5.md +0 -315
  114. package/docs/releases/RELEASE_CHECKLIST_v1.7.6.md +0 -389
  115. package/docs/releases/RELEASE_CHECKLIST_v1.8.0.md +0 -331
  116. package/docs/releases/RELEASE_CHECKLIST_v1.8.2.md +0 -309
  117. package/docs/releases/RELEASE_NOTES_1.7.0.md +0 -539
  118. package/docs/releases/RELEASE_NOTES_1.8.10.md +0 -239
  119. package/docs/releases/RELEASE_NOTES_1.8.9.md +0 -213
  120. package/docs/releases/RELEASE_NOTES_v1.8.0.md +0 -685
  121. package/docs/releases/RELEASE_NOTES_v1.8.1.md +0 -221
  122. package/docs/releases/RELEASE_NOTES_v1.8.2.md +0 -421
  123. package/docs/releases/RELEASE_NOTES_v1.8.3.md +0 -292
  124. package/docs/releases/RELEASE_NOTES_v1.8.4.md +0 -277
  125. package/docs/releases/RELEASE_NOTES_v1.8.6.md +0 -205
  126. package/docs/releases/RELEASE_NOTES_v1.8.7.md +0 -184
  127. package/docs/releases/RELEASE_PLAN_v1.7.6.md +0 -816
  128. package/docs/releases/RELEASE_SUMMARY_1.8.10.md +0 -193
  129. package/docs/releases/RELEASE_SUMMARY_v1.7.4.md +0 -276
  130. package/docs/releases/RELEASE_SUMMARY_v1.7.5.md +0 -322
  131. package/docs/releases/RELEASE_SUMMARY_v1.7.6.md +0 -436
  132. package/docs/releases/RELEASE_SUMMARY_v1.7.7.md +0 -391
  133. package/docs/releases/RELEASE_SUMMARY_v1.7.8.md +0 -523
  134. package/docs/releases/RELEASE_SUMMARY_v1.7.9.md +0 -542
  135. package/docs/troubleshooting/ARDUINO_IDE_VERSION_FIX_SUMMARY.md +0 -229
  136. package/docs/troubleshooting/ARDUINO_LIBRARY_NAME_FIX.md +0 -197
  137. package/docs/troubleshooting/CRASH_QUICK_REF.md +0 -93
  138. package/docs/troubleshooting/ESP32_C6_COMPATIBILITY.md +0 -157
  139. package/docs/troubleshooting/FREERTOS_ASSERTION_FAILURE.md +0 -288
  140. package/docs/troubleshooting/FREERTOS_FIX_IMPLEMENTATION.md +0 -267
  141. package/docs/troubleshooting/NPM_PUBLISHING_ISSUE_SUMMARY.md +0 -110
  142. package/docs/troubleshooting/PAINLESSMESH_V1.7.4_COMPILATION_ISSUES.md +0 -547
  143. package/docs/troubleshooting/QUICK_FIX_FREERTOS.md +0 -164
  144. package/docs/troubleshooting/SENSOR_NODE_CONNECTION_CRASH.md +0 -264
  145. package/docs/troubleshooting/common-architecture-mistakes.md +0 -438
  146. package/docs/troubleshooting/internet-access-faq.md +0 -299
  147. package/docs/troubleshooting/station-reconnection-issues.md +0 -172
  148. package/docs/v1.7.7_MQTT_IMPROVEMENTS.md +0 -794
  149. package/docs/wiki/API-Reference.md +0 -246
  150. package/docs/wiki/Complete-Documentation.md +0 -123
  151. package/examples/alteriomImproved/alteriom_sensor_package.hpp +0 -224
  152. package/examples/alteriomImproved/improved_sensor_node.ino +0 -248
  153. package/examples/alteriomImproved/platformio.ini +0 -32
  154. package/examples/alteriomMetricsHealth/alteriom_sensor_package.hpp +0 -796
  155. package/examples/alteriomMetricsHealth/metrics_health_node.ino +0 -429
  156. package/examples/alteriomMetricsHealth/platformio.ini +0 -26
  157. package/examples/alteriomPhase1/alteriom_sensor_package.hpp +0 -224
  158. package/examples/alteriomPhase1/phase1_features.ino +0 -242
  159. package/examples/alteriomPhase1/platformio.ini +0 -26
  160. package/examples/alteriomPhase2/alteriom_sensor_package.hpp +0 -224
  161. package/examples/alteriomPhase2/phase2_features.ino +0 -186
  162. package/examples/alteriomPhase2/platformio.ini +0 -26
  163. package/examples/alteriomSensorNode/alteriom_sensor_node.ino +0 -186
  164. package/examples/alteriomSensorNode/alteriom_sensor_package.hpp +0 -1227
  165. package/examples/alteriomSensorNode/platformio.ini +0 -26
  166. package/examples/bridge/alteriom_sensor_package.hpp +0 -1170
  167. package/examples/bridge/bridge_health_monitoring_example.ino +0 -188
  168. package/examples/bridge/enhanced_mqtt_bridge.hpp +0 -610
  169. package/examples/bridge/enhanced_mqtt_bridge_example.ino +0 -226
  170. package/examples/bridge/mesh_event_publisher.hpp +0 -253
  171. package/examples/bridge/mesh_topology_reporter.hpp +0 -303
  172. package/examples/bridge/mqtt_command_bridge.hpp +0 -459
  173. package/examples/bridge/mqtt_status_bridge.hpp +0 -519
  174. package/examples/bridgeAwareSensorNode/alteriom_sensor_package.hpp +0 -1227
  175. package/examples/bridgeAwareSensorNode/bridgeAwareSensorNode.ino +0 -342
  176. package/examples/bridgeAwareSensorNode/platformio.ini +0 -26
  177. package/examples/diagnosticsExample/diagnosticsExample.ino +0 -171
  178. package/examples/diagnosticsExample/platformio.ini +0 -26
  179. package/examples/echoNode/echoNode.ino +0 -33
  180. package/examples/echoNode/platformio.ini +0 -26
  181. package/examples/meshCommandNode/alteriom_sensor_package.hpp +0 -235
  182. package/examples/meshCommandNode/meshCommandNode.ino +0 -265
  183. package/examples/mqttCommandBridge/alteriom_sensor_package.hpp +0 -235
  184. package/examples/mqttCommandBridge/mesh_event_publisher.hpp +0 -253
  185. package/examples/mqttCommandBridge/mesh_topology_reporter.hpp +0 -303
  186. package/examples/mqttCommandBridge/mqttCommandBridge.ino +0 -254
  187. package/examples/mqttCommandBridge/mqtt_command_bridge.hpp +0 -462
  188. package/examples/mqttCommandBridge/platformio.ini +0 -27
  189. package/examples/mqttStatusBridge/mqttStatusBridge.ino +0 -218
  190. package/examples/mqttStatusBridge/mqtt_status_bridge.hpp +0 -522
  191. package/examples/mqttStatusBridge/platformio.ini +0 -27
  192. package/examples/mqttTopologyTest/README.md +0 -467
  193. package/examples/mqttTopologyTest/mqttTopologyTest.ino +0 -754
  194. package/examples/mqttTopologyTest/platformio.ini +0 -27
  195. package/examples/multi_bridge/README.md +0 -346
  196. package/examples/multi_bridge/primary_bridge.ino +0 -108
  197. package/examples/multi_bridge/regular_node.ino +0 -141
  198. package/examples/multi_bridge/secondary_bridge.ino +0 -123
  199. package/examples/ntpTimeSyncBridge/alteriom_sensor_package.hpp +0 -1383
  200. package/examples/ntpTimeSyncBridge/ntpTimeSyncBridge.ino +0 -86
  201. package/examples/ntpTimeSyncNode/alteriom_sensor_package.hpp +0 -1383
  202. package/examples/ntpTimeSyncNode/ntpTimeSyncNode.ino +0 -109
  203. package/examples/queued_alarms/README.md +0 -390
  204. package/examples/queued_alarms/queued_alarms.ino +0 -265
  205. package/examples/routing_demo/README.md +0 -172
  206. package/examples/routing_demo/routing_demo.ino +0 -102
  207. package/examples/rtcIntegration/README.md +0 -294
  208. package/examples/rtcIntegration/rtcIntegration.ino +0 -210
@@ -1,293 +0,0 @@
1
- # Bridge Health Monitoring & Metrics Collection
2
-
3
- ## Overview
4
-
5
- The Bridge Health Monitoring feature provides comprehensive operational visibility into bridge health, connectivity quality, and performance metrics. This is essential for production deployments, troubleshooting, and capacity planning.
6
-
7
- ## Features
8
-
9
- ✅ **Connectivity Metrics** - Track uptime, internet connectivity, and disconnection events
10
- ✅ **Signal Quality** - Monitor WiFi signal strength (RSSI) statistics
11
- ✅ **Traffic Metrics** - Measure bytes and messages transmitted/received
12
- ✅ **Performance Metrics** - Calculate latency and packet loss
13
- ✅ **JSON Export** - Easy integration with monitoring tools
14
- ✅ **Prometheus Support** - Export metrics for Prometheus scraping
15
- ✅ **Periodic Callbacks** - Automated metric collection and reporting
16
-
17
- ## API Reference
18
-
19
- ### BridgeHealthMetrics Structure
20
-
21
- ```cpp
22
- struct BridgeHealthMetrics {
23
- // Connectivity
24
- uint32_t uptimeSeconds; // Total uptime in seconds
25
- uint32_t internetUptimeSeconds; // Time with Internet connection
26
- uint32_t totalDisconnects; // Number of disconnection events
27
- uint32_t currentUptime; // Current uptime in milliseconds
28
-
29
- // Signal Quality
30
- int8_t currentRSSI; // Current WiFi signal strength (dBm)
31
- int8_t avgRSSI; // Average signal strength
32
- int8_t minRSSI; // Minimum observed signal strength
33
- int8_t maxRSSI; // Maximum observed signal strength
34
-
35
- // Traffic
36
- uint64_t bytesRx; // Total bytes received
37
- uint64_t bytesTx; // Total bytes transmitted
38
- uint32_t messagesRx; // Total messages received
39
- uint32_t messagesTx; // Total messages transmitted
40
- uint32_t messagesQueued; // Messages currently queued
41
- uint32_t messagesDropped; // Messages that failed to send
42
-
43
- // Performance
44
- uint32_t avgLatencyMs; // Average message latency
45
- uint8_t packetLossPercent; // Packet loss percentage (0-100)
46
- uint32_t meshNodeCount; // Number of nodes in mesh
47
- };
48
- ```
49
-
50
- ### Methods
51
-
52
- #### getBridgeHealthMetrics()
53
-
54
- Get current health metrics snapshot.
55
-
56
- ```cpp
57
- BridgeHealthMetrics metrics = mesh.getBridgeHealthMetrics();
58
-
59
- Serial.printf("Uptime: %u s\n", metrics.uptimeSeconds);
60
- Serial.printf("Messages RX: %u\n", metrics.messagesRx);
61
- Serial.printf("Avg Latency: %u ms\n", metrics.avgLatencyMs);
62
- ```
63
-
64
- #### resetHealthMetrics()
65
-
66
- Reset all counters to zero. Useful for periodic monitoring windows.
67
-
68
- ```cpp
69
- mesh.resetHealthMetrics();
70
- ```
71
-
72
- **Note:** This resets counters (messages, bytes, disconnects) but keeps current state metrics (RSSI, node count).
73
-
74
- #### getHealthMetricsJSON()
75
-
76
- Export metrics as JSON string for easy integration.
77
-
78
- ```cpp
79
- String json = mesh.getHealthMetricsJSON();
80
- mqttClient.publish("bridge/metrics", json.c_str());
81
- ```
82
-
83
- **JSON Format:**
84
- ```json
85
- {
86
- "connectivity": {
87
- "uptimeSeconds": 3600,
88
- "internetUptimeSeconds": 3540,
89
- "totalDisconnects": 2,
90
- "currentUptime": 3600000
91
- },
92
- "signalQuality": {
93
- "currentRSSI": -65,
94
- "avgRSSI": -68,
95
- "minRSSI": -75,
96
- "maxRSSI": -60
97
- },
98
- "traffic": {
99
- "bytesRx": 1048576,
100
- "bytesTx": 524288,
101
- "messagesRx": 1234,
102
- "messagesTx": 567,
103
- "messagesQueued": 0,
104
- "messagesDropped": 5
105
- },
106
- "performance": {
107
- "avgLatencyMs": 45,
108
- "packetLossPercent": 1,
109
- "meshNodeCount": 8
110
- }
111
- }
112
- ```
113
-
114
- #### onHealthMetricsUpdate()
115
-
116
- Register a periodic callback for automated monitoring.
117
-
118
- ```cpp
119
- mesh.onHealthMetricsUpdate([](BridgeHealthMetrics metrics) {
120
- // Process metrics
121
- Serial.printf("Nodes: %u, Latency: %u ms\n",
122
- metrics.meshNodeCount, metrics.avgLatencyMs);
123
- }, 60000); // Every 60 seconds
124
- ```
125
-
126
- ## Integration Examples
127
-
128
- ### MQTT Publishing
129
-
130
- ```cpp
131
- #include <PubSubClient.h>
132
-
133
- WiFiClient espClient;
134
- PubSubClient mqttClient(espClient);
135
-
136
- void metricsCallback(BridgeHealthMetrics metrics) {
137
- if (mqttClient.connected()) {
138
- String json = mesh.getHealthMetricsJSON();
139
- mqttClient.publish("bridge/metrics", json.c_str());
140
- }
141
- }
142
-
143
- void setup() {
144
- // ... mesh setup ...
145
- mesh.onHealthMetricsUpdate(metricsCallback, 60000);
146
- }
147
- ```
148
-
149
- ### Prometheus Exporter
150
-
151
- ```cpp
152
- #include <ESPAsyncWebServer.h>
153
-
154
- AsyncWebServer server(80);
155
-
156
- String exportPrometheus() {
157
- auto metrics = mesh.getBridgeHealthMetrics();
158
-
159
- String output = "";
160
- output += "# HELP bridge_uptime_seconds Bridge uptime\n";
161
- output += "# TYPE bridge_uptime_seconds counter\n";
162
- output += "bridge_uptime_seconds " + String(metrics.uptimeSeconds) + "\n";
163
-
164
- output += "# HELP bridge_rssi_dbm WiFi signal strength\n";
165
- output += "# TYPE bridge_rssi_dbm gauge\n";
166
- output += "bridge_rssi_dbm " + String(metrics.currentRSSI) + "\n";
167
-
168
- // Add more metrics...
169
-
170
- return output;
171
- }
172
-
173
- void setup() {
174
- // ... mesh setup ...
175
-
176
- server.on("/metrics", HTTP_GET, [](AsyncWebServerRequest *request){
177
- request->send(200, "text/plain", exportPrometheus());
178
- });
179
-
180
- server.begin();
181
- }
182
- ```
183
-
184
- ### Grafana Dashboard
185
-
186
- Use the Prometheus exporter above with Grafana to create monitoring dashboards:
187
-
188
- 1. Configure Prometheus to scrape your bridge node: `http://bridge-ip/metrics`
189
- 2. Import metrics into Grafana
190
- 3. Create panels for:
191
- - Uptime and availability
192
- - Signal strength trends
193
- - Traffic throughput
194
- - Latency and packet loss
195
- - Mesh topology changes
196
-
197
- ### Cloud Logging (AWS CloudWatch, Azure Monitor, etc.)
198
-
199
- ```cpp
200
- void metricsCallback(BridgeHealthMetrics metrics) {
201
- String json = mesh.getHealthMetricsJSON();
202
-
203
- // Send to CloudWatch
204
- httpClient.post("/cloudwatch", json);
205
-
206
- // Send to Azure Monitor
207
- httpClient.post("/azure-monitor", json);
208
- }
209
- ```
210
-
211
- ## Use Cases
212
-
213
- ### Production Monitoring
214
-
215
- Monitor bridge health in production deployments:
216
- - Track uptime and availability
217
- - Detect connectivity issues early
218
- - Analyze signal quality trends
219
- - Capacity planning based on traffic patterns
220
-
221
- ### Troubleshooting
222
-
223
- Debug network issues:
224
- - Identify sources of packet loss
225
- - Locate signal strength problems
226
- - Diagnose latency spikes
227
- - Track disconnection patterns
228
-
229
- ### Performance Optimization
230
-
231
- Optimize mesh performance:
232
- - Analyze traffic patterns
233
- - Identify bottlenecks
234
- - Optimize node placement based on RSSI
235
- - Fine-tune routing strategies
236
-
237
- ## Best Practices
238
-
239
- ### Monitoring Intervals
240
-
241
- - **Development:** 10-30 seconds for rapid feedback
242
- - **Production:** 60-300 seconds to reduce overhead
243
- - **Critical Systems:** 30-60 seconds with alerting
244
-
245
- ### Metric Storage
246
-
247
- - Use time-series databases (InfluxDB, Prometheus)
248
- - Retain raw metrics for 7-30 days
249
- - Aggregate to hourly/daily for long-term storage
250
- - Set up automated retention policies
251
-
252
- ### Alerting
253
-
254
- Set up alerts for:
255
- - Packet loss > 5%
256
- - Latency > 200ms
257
- - Signal strength < -80 dBm
258
- - Frequent disconnections (> 3/hour)
259
- - Node count drops
260
-
261
- ### Resource Management
262
-
263
- On ESP8266 (limited RAM):
264
- - Use longer intervals (120-300 seconds)
265
- - Minimize callback complexity
266
- - Consider offloading processing to gateway
267
-
268
- On ESP32 (more RAM):
269
- - Can use shorter intervals (30-60 seconds)
270
- - More sophisticated processing possible
271
- - Support multiple monitoring integrations
272
-
273
- ## Example: Complete Monitoring Setup
274
-
275
- See `examples/bridge/bridge_health_monitoring_example.ino` for a complete working example with:
276
- - Periodic metrics logging
277
- - MQTT integration
278
- - Prometheus export endpoint
279
- - Manual metrics queries
280
-
281
- ## Version History
282
-
283
- - **v1.8.0** - Initial release
284
- - Basic metrics collection
285
- - JSON export
286
- - Periodic callbacks
287
- - MQTT and Prometheus examples
288
-
289
- ## See Also
290
-
291
- - [Bridge Architecture](BRIDGE_ARCHITECTURE_IMPLEMENTATION.md)
292
- - [Bridge Status Feature](BRIDGE_STATUS_FEATURE.md)
293
- - [MQTT Bridge Examples](../examples/bridge/)
@@ -1,357 +0,0 @@
1
- # Bridge Initialization and Fallback Patterns
2
-
3
- ## Overview
4
-
5
- This document describes the behavior of `initAsBridge()` when router connection fails, and demonstrates recommended fallback patterns that give library users control over error handling and recovery strategies.
6
-
7
- ## Design Philosophy
8
-
9
- As a library, painlessMesh provides the building blocks for mesh networking but **does not dictate application-level recovery strategies**. When bridge initialization fails, the library:
10
-
11
- 1. **Returns failure status** (`false`) instead of forcing actions like restart
12
- 2. **Provides clear error logging** to help diagnose issues
13
- 3. **Leaves mesh state clean** for user-controlled recovery
14
- 4. **Allows graceful fallback** to regular mesh node
15
-
16
- This design enables flexible deployment patterns:
17
- - Single-bridge networks with manual recovery
18
- - Multi-bridge networks with automatic redundancy
19
- - Hybrid approaches with controlled failover behavior
20
-
21
- ## Bridge Initialization Behavior
22
-
23
- ### Success Path
24
-
25
- When `initAsBridge()` successfully connects to the router:
26
-
27
- ```cpp
28
- bool initAsBridge(TSTRING meshSSID, TSTRING meshPassword,
29
- TSTRING routerSSID, TSTRING routerPassword,
30
- Scheduler *baseScheduler, uint16_t port = 5555);
31
- ```
32
-
33
- **Steps:**
34
- 1. Disconnect from any existing WiFi connections
35
- 2. Connect to router in STA mode (30 second timeout)
36
- 3. Detect router's WiFi channel
37
- 4. Initialize mesh AP on same channel as router
38
- 5. Re-establish router connection using stationManual
39
- 6. Set node as root/bridge
40
- 7. Start bridge status broadcasting
41
- 8. **Return `true`**
42
-
43
- **Result:** Device functions as bridge on router's channel, maintaining both router and mesh connectivity.
44
-
45
- ### Failure Path
46
-
47
- When router connection fails (timeout after 30 seconds):
48
-
49
- **Steps:**
50
- 1. Log error: "Failed to connect to router"
51
- 2. Log error: "Cannot become bridge without router connection"
52
- 3. Log error: "Bridge initialization aborted - remaining as regular node"
53
- 4. **Return `false` without initializing mesh**
54
-
55
- **Result:** Device is not initialized as bridge OR regular node. User code must decide next steps.
56
-
57
- ### Why No Automatic Recovery?
58
-
59
- The library does not automatically restart or force fallback because:
60
-
61
- 1. **User control**: Application knows its deployment context and requirements
62
- 2. **Network stability**: Avoid restart loops that could destabilize mesh
63
- 3. **Flexibility**: Different use cases need different recovery strategies
64
- 4. **Predictability**: Library behavior should be deterministic and explicit
65
-
66
- ## Recommended Fallback Patterns
67
-
68
- ### Pattern 1: Fallback to Regular Node (Basic)
69
-
70
- **Use Case:** Single bridge network where bridge is not critical to mesh operation.
71
-
72
- ```cpp
73
- bool bridgeSuccess = mesh.initAsBridge(MESH_PREFIX, MESH_PASSWORD,
74
- ROUTER_SSID, ROUTER_PASSWORD,
75
- &userScheduler, MESH_PORT);
76
-
77
- if (!bridgeSuccess) {
78
- Serial.println("✗ Failed to initialize as bridge!");
79
- Serial.println("Router unreachable - falling back to regular mesh node");
80
-
81
- // Fallback: Initialize as regular mesh node
82
- // Device can still participate in mesh without bridge functionality
83
- mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
84
-
85
- Serial.println("✓ Initialized as regular mesh node");
86
- Serial.println("Note: To function as a bridge, fix router and restart");
87
- }
88
- ```
89
-
90
- **Benefits:**
91
- - Device remains part of mesh network
92
- - Can receive messages from other nodes
93
- - Can participate in mesh topology
94
- - Manual intervention needed to restore bridge role
95
-
96
- ### Pattern 2: Fallback with Auto-Promotion (Recommended)
97
-
98
- **Use Case:** Networks where any node can become bridge when router becomes available.
99
-
100
- ```cpp
101
- bool bridgeSuccess = mesh.initAsBridge(MESH_PREFIX, MESH_PASSWORD,
102
- ROUTER_SSID, ROUTER_PASSWORD,
103
- &userScheduler, MESH_PORT);
104
-
105
- if (!bridgeSuccess) {
106
- Serial.println("✗ Failed to initialize as bridge!");
107
- Serial.println("Router unreachable - enabling bridge failover");
108
-
109
- // Fallback: Regular node with automatic bridge promotion
110
- mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
111
- mesh.setRouterCredentials(ROUTER_SSID, ROUTER_PASSWORD);
112
- mesh.enableBridgeFailover(true);
113
- mesh.setElectionTimeout(5000);
114
-
115
- Serial.println("✓ Running as regular node");
116
- Serial.println("Will auto-promote to bridge when router available");
117
- }
118
- ```
119
-
120
- **Benefits:**
121
- - Automatic recovery when router comes online
122
- - No manual intervention needed
123
- - Participates in bridge elections
124
- - Maintains mesh connectivity throughout
125
-
126
- ### Pattern 3: Multi-Bridge Redundancy
127
-
128
- **Use Case:** Critical networks with multiple potential bridges.
129
-
130
- **Primary Bridge:**
131
- ```cpp
132
- bool bridgeSuccess = mesh.initAsBridge(MESH_PREFIX, MESH_PASSWORD,
133
- ROUTER_SSID, ROUTER_PASSWORD,
134
- &userScheduler, MESH_PORT, 10); // Priority 10
135
-
136
- if (!bridgeSuccess) {
137
- Serial.println("✗ Primary bridge init failed!");
138
- Serial.println("Router unreachable - secondary should be active");
139
-
140
- // Fallback: Regular node (secondary bridge takes over)
141
- mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
142
-
143
- Serial.println("✓ Running as regular node");
144
- Serial.println("Secondary bridge should provide connectivity");
145
- }
146
- ```
147
-
148
- **Secondary Bridge:**
149
- ```cpp
150
- // Secondary bridge configuration (priority 5)
151
- // If primary fails, secondary provides redundancy
152
- ```
153
-
154
- **Benefits:**
155
- - Immediate redundancy via secondary bridge
156
- - Graceful degradation of primary
157
- - No single point of failure
158
- - Maintains Internet connectivity for mesh
159
-
160
- ### Pattern 4: Retry with Exponential Backoff
161
-
162
- **Use Case:** Environments with intermittent router availability.
163
-
164
- ```cpp
165
- const int MAX_RETRIES = 3;
166
- int retryCount = 0;
167
- int retryDelay = 5000; // Start with 5 seconds
168
-
169
- while (retryCount < MAX_RETRIES) {
170
- bool bridgeSuccess = mesh.initAsBridge(MESH_PREFIX, MESH_PASSWORD,
171
- ROUTER_SSID, ROUTER_PASSWORD,
172
- &userScheduler, MESH_PORT);
173
-
174
- if (bridgeSuccess) {
175
- Serial.println("✓ Bridge initialized successfully");
176
- break;
177
- }
178
-
179
- retryCount++;
180
- if (retryCount < MAX_RETRIES) {
181
- Serial.printf("Retry %d/%d in %d seconds...\n",
182
- retryCount, MAX_RETRIES, retryDelay/1000);
183
- delay(retryDelay);
184
- retryDelay *= 2; // Exponential backoff
185
- }
186
- }
187
-
188
- if (retryCount >= MAX_RETRIES) {
189
- Serial.println("Max retries reached - falling back to regular node");
190
- mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
191
- }
192
- ```
193
-
194
- **Benefits:**
195
- - Handles temporary router outages
196
- - Exponential backoff prevents network flooding
197
- - Eventually falls back if persistent failure
198
- - Configurable retry strategy
199
-
200
- ### Pattern 5: User-Controlled Restart
201
-
202
- **Use Case:** Explicit bridge nodes that require bridge functionality to operate.
203
-
204
- ```cpp
205
- bool bridgeSuccess = mesh.initAsBridge(MESH_PREFIX, MESH_PASSWORD,
206
- ROUTER_SSID, ROUTER_PASSWORD,
207
- &userScheduler, MESH_PORT);
208
-
209
- if (!bridgeSuccess) {
210
- Serial.println("✗ Failed to initialize as bridge!");
211
- Serial.println("This device must function as a bridge");
212
- Serial.println("Restarting in 30 seconds to retry...");
213
- delay(30000);
214
- ESP.restart(); // User's choice to restart
215
- }
216
- ```
217
-
218
- **Benefits:**
219
- - Clear intent that bridge role is required
220
- - User controls restart timing
221
- - Can implement watchdog or LED indicators
222
- - Appropriate for dedicated bridge hardware
223
-
224
- ## Channel Discovery and Mesh Formation
225
-
226
- ### Two Nodes on Different Channels
227
-
228
- When two mesh nodes start on different channels:
229
-
230
- 1. **Station Scan Discovery:**
231
- - Each node scans for mesh SSID on all channels
232
- - Nodes discover each other via beacon frames
233
- - Connection negotiation determines channel
234
-
235
- 2. **Channel Selection:**
236
- - Node with more connections typically maintains its channel
237
- - New node switches to join existing network
238
- - Root node (bridge) has priority in channel selection
239
-
240
- 3. **Bridge Channel Priority:**
241
- - Bridge nodes maintain router's channel
242
- - Regular nodes switch to bridge's channel to join
243
- - This ensures bridge maintains router connection
244
-
245
- ### Bridge Appearance and Channel Changes
246
-
247
- When a new bridge appears in an existing mesh:
248
-
249
- 1. **Bridge Broadcasts Status (Type 610):**
250
- - Announces presence on its channel (router's channel)
251
- - Other nodes receive status updates
252
-
253
- 2. **Nodes Evaluate Connectivity:**
254
- - If bridge is on different channel, nodes must decide:
255
- - Stay on current mesh channel?
256
- - Switch to bridge's channel for Internet access?
257
-
258
- 3. **Channel Re-synchronization:**
259
- - Nodes may perform channel re-sync if mesh fragmented
260
- - After 6 consecutive empty scans, trigger re-sync
261
- - Re-scan all channels to find mesh
262
-
263
- 4. **Avoiding Channel Chase Loops:**
264
- - Election mechanism includes channel check
265
- - Nodes defer election if approaching re-sync threshold
266
- - Prevents oscillation between channels
267
-
268
- ## Best Practices
269
-
270
- ### 1. Choose Appropriate Fallback Pattern
271
-
272
- - **Critical Infrastructure:** Use Pattern 3 (Multi-Bridge Redundancy)
273
- - **General IoT:** Use Pattern 2 (Auto-Promotion)
274
- - **Testing/Development:** Use Pattern 1 (Basic Fallback)
275
- - **Dedicated Bridges:** Use Pattern 5 (User-Controlled Restart)
276
-
277
- ### 2. Monitor Bridge Status
278
-
279
- ```cpp
280
- mesh.onBridgeStatusChanged([](uint32_t bridgeNodeId, bool hasInternet) {
281
- Serial.printf("Bridge %u: Internet %s\n",
282
- bridgeNodeId, hasInternet ? "UP" : "DOWN");
283
- });
284
- ```
285
-
286
- ### 3. Handle Bridge Role Changes
287
-
288
- ```cpp
289
- mesh.onBridgeRoleChanged([](bool isBridge, String reason) {
290
- if (isBridge) {
291
- Serial.printf("Promoted to bridge: %s\n", reason.c_str());
292
- } else {
293
- Serial.printf("Demoted from bridge: %s\n", reason.c_str());
294
- }
295
- });
296
- ```
297
-
298
- ### 4. Avoid Restart Loops
299
-
300
- - Implement maximum retry counts
301
- - Use exponential backoff for retries
302
- - Monitor consecutive failures and adjust strategy
303
- - Consider manual intervention threshold
304
-
305
- ### 5. Document Deployment Strategy
306
-
307
- Clearly document in your application code:
308
- - Which fallback pattern is used
309
- - Why that pattern was chosen
310
- - Expected behavior during failures
311
- - Manual recovery procedures if needed
312
-
313
- ## Testing Recommendations
314
-
315
- ### Test Scenario 1: Router Unreachable at Startup
316
-
317
- 1. Configure node as bridge
318
- 2. Make router unreachable (wrong password, powered off, etc.)
319
- 3. Verify node falls back gracefully
320
- 4. Check node can join mesh as regular node
321
- 5. Verify no restart loops occur
322
-
323
- ### Test Scenario 2: Router Becomes Available Later
324
-
325
- 1. Start with router unreachable
326
- 2. Node falls back to regular node with failover enabled
327
- 3. Power on router
328
- 4. Verify node detects router and promotes to bridge
329
- 5. Check channel switching works correctly
330
-
331
- ### Test Scenario 3: Multi-Bridge Failover
332
-
333
- 1. Start primary and secondary bridges
334
- 2. Make primary's router unreachable
335
- 3. Verify primary falls back to regular node
336
- 4. Check secondary bridge continues providing connectivity
337
- 5. Restore primary's router and verify it resumes bridge role
338
-
339
- ### Test Scenario 4: Channel Chase Prevention
340
-
341
- 1. Start mesh on channel 6
342
- 2. Add bridge on channel 11
343
- 3. Verify nodes handle channel mismatch
344
- 4. Check no continuous restart or channel oscillation
345
- 5. Verify eventual mesh convergence on single channel
346
-
347
- ## Summary
348
-
349
- painlessMesh provides flexible bridge initialization with graceful failure handling:
350
-
351
- - **Library returns status**, doesn't force actions
352
- - **Users choose recovery strategy** based on their requirements
353
- - **Multiple fallback patterns** for different use cases
354
- - **Channel management** prevents network instability
355
- - **Comprehensive callbacks** for monitoring and control
356
-
357
- This design philosophy ensures painlessMesh can be used in diverse deployments while maintaining network stability and giving users full control over their mesh behavior.