@alteriom/painlessmesh 1.7.9 → 1.8.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 (34) hide show
  1. package/CHANGELOG.md +94 -2
  2. package/README.md +108 -1
  3. package/docs/BRIDGE_FAILOVER.md +512 -0
  4. package/docs/BRIDGE_HEALTH_MONITORING.md +293 -0
  5. package/docs/CREATE_MISSING_RELEASES.md +321 -0
  6. package/docs/releases/RELEASE_SUMMARY_v1.7.8.md +523 -0
  7. package/docs/releases/RELEASE_SUMMARY_v1.7.9.md +542 -0
  8. package/examples/alteriom/alteriom_sensor_package.hpp +213 -0
  9. package/examples/alteriomSensorNode/alteriom_sensor_package.hpp +1014 -11
  10. package/examples/basic/basic.ino +6 -2
  11. package/examples/bridge/bridge.ino +44 -23
  12. package/examples/bridge/bridge_health_monitoring_example.ino +188 -0
  13. package/examples/bridgeAwareSensorNode/alteriom_sensor_package.hpp +1227 -0
  14. package/examples/bridgeAwareSensorNode/bridgeAwareSensorNode.ino +343 -0
  15. package/examples/bridgeAwareSensorNode/platformio.ini +26 -0
  16. package/examples/bridge_failover/README.md +358 -0
  17. package/examples/bridge_failover/bridge_failover.ino +180 -0
  18. package/examples/bridge_failover/platformio.ini +27 -0
  19. package/examples/diagnosticsExample/diagnosticsExample.ino +171 -0
  20. package/examples/diagnosticsExample/platformio.ini +26 -0
  21. package/examples/ntpTimeSyncBridge/alteriom_sensor_package.hpp +1383 -0
  22. package/examples/ntpTimeSyncBridge/ntpTimeSyncBridge.ino +81 -0
  23. package/examples/ntpTimeSyncNode/alteriom_sensor_package.hpp +1383 -0
  24. package/examples/ntpTimeSyncNode/ntpTimeSyncNode.ino +109 -0
  25. package/examples/rtcIntegration/README.md +235 -0
  26. package/examples/rtcIntegration/rtcIntegration.ino +196 -0
  27. package/library.json +1 -1
  28. package/library.properties +1 -1
  29. package/package.json +1 -1
  30. package/src/arduino/wifi.hpp +572 -0
  31. package/src/painlessMeshSTA.cpp +63 -0
  32. package/src/painlessMeshSTA.h +3 -0
  33. package/src/painlessmesh/mesh.hpp +1127 -4
  34. package/src/painlessmesh/rtc.hpp +203 -0
package/CHANGELOG.md CHANGED
@@ -7,18 +7,110 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.8.0] - 2025-11-09
11
+
10
12
  ### Added
11
13
 
12
- - TBD
14
+ - **Diagnostics API for Bridge Operations** - Comprehensive monitoring and debugging tools
15
+ - New diagnostic methods for bridge state, topology, and connectivity
16
+ - Election history tracking with detailed event logging
17
+ - Network topology visualization with neighbor information
18
+ - Connectivity testing and validation tools
19
+ - Comprehensive diagnostic report generation
20
+ - Minimal overhead when diagnostics enabled
21
+ - Examples: `examples/diagnostics/` directory
22
+ - Documentation: `DIAGNOSTICS_API.md`
23
+
24
+ - **Bridge Health Monitoring & Metrics Collection** - Real-time bridge performance metrics
25
+ - New `BridgeHealthMetrics` struct with connectivity, signal, traffic, and performance data
26
+ - Four API methods: `getBridgeHealthMetrics()`, `resetHealthMetrics()`, `getHealthMetricsJSON()`, `onHealthMetricsUpdate()`
27
+ - Automatic tracking of uptime, disconnects, RSSI, traffic bytes, latency, and packet loss
28
+ - JSON export for integration with MQTT, Prometheus, Grafana, CloudWatch
29
+ - Periodic callback support for automated monitoring
30
+ - Zero overhead when not used
31
+ - Comprehensive unit tests (63 assertions)
32
+ - Example: `examples/bridge/bridge_health_monitoring_example.ino`
33
+ - Documentation: `docs/BRIDGE_HEALTH_MONITORING.md`
34
+
35
+ - **RTC (Real-Time Clock) Integration** - Hardware RTC support for offline timekeeping
36
+ - Support for DS3231, DS1307, and PCF8523 RTC modules
37
+ - Automatic time persistence across reboots and power failures
38
+ - Seamless integration with NTP time sync
39
+ - Comprehensive unit tests for RTC functionality
40
+ - Example sketches demonstrating RTC usage
41
+
42
+ - **Bridge Status Broadcast & Callback (Type 610)** - Real-time Internet connectivity monitoring
43
+ - Bridge nodes automatically broadcast connectivity status every 30 seconds
44
+ - New `onBridgeStatusChanged()` callback for connectivity state changes
45
+ - API methods: `hasInternetConnection()`, `getPrimaryBridge()`, `getBridges()`, `isBridge()`
46
+ - Status includes Internet connectivity, router RSSI, channel, uptime, gateway IP
47
+ - Enable offline mode and message queueing when Internet unavailable
48
+ - Support for bridge failover scenarios
49
+ - Documentation: `BRIDGE_STATUS_FEATURE.md`
50
+
51
+ - **Automatic Bridge Failover with RSSI-Based Election (Types 611, 612)** - High-availability bridge management
52
+ - Distributed bridge election protocol when primary bridge fails
53
+ - RSSI-based node selection for optimal bridge placement
54
+ - New `BridgeElectionPackage` (Type 611) for election coordination
55
+ - New `BridgeTakeoverPackage` (Type 612) for bridge transition announcements
56
+ - API methods: `enableBridgeFailover()`, `setRouterCredentials()`, `onBridgeRoleChanged()`
57
+ - Automatic promotion of best-positioned node to bridge role
58
+ - Tiebreaker rules: uptime, free memory, node ID
59
+ - Split-brain prevention and oscillation protection
60
+ - Graceful handling of multiple sequential failures
61
+ - Critical for production high-availability systems (Issue #64)
62
+
63
+ - **NTP Time Synchronization (Type 614)** - Bridge-to-mesh NTP time distribution
64
+ - New `NTPTimeSyncPackage` for broadcasting NTP time from bridge nodes
65
+ - Bridge nodes with Internet distribute authoritative time to entire mesh
66
+ - Eliminates per-node NTP queries (saves bandwidth and power)
67
+ - Supports RTC synchronization for offline operation
68
+ - Includes accuracy field for time uncertainty tracking
69
+ - Comprehensive unit tests (5 scenarios, 38 assertions)
70
+ - Example sketches: `ntpTimeSyncBridge.ino` and `ntpTimeSyncNode.ino`
71
+ - Documentation: `NTP_TIME_SYNC_FEATURE.md`
72
+
73
+ - **Bridge-Centric Architecture** - New `initAsBridge()` method for automatic channel detection
74
+ - Bridge nodes now connect to router first and auto-detect its channel
75
+ - Mesh network automatically configured on router's channel
76
+ - Eliminates need for manual channel configuration
77
+ - Automatically sets root node flags
78
+ - Graceful fallback to channel 1 if router connection fails
79
+
80
+ - **Auto Channel Detection for Regular Nodes** - Support for `channel=0` in `init()`
81
+ - Regular nodes can now auto-detect mesh channel by scanning all channels
82
+ - Falls back to channel 1 if mesh not found
83
+ - Simplifies multi-node deployments
84
+
85
+ - **Helper Function** - New `scanForMeshChannel()` static method
86
+ - Scans all 13 WiFi channels to find mesh SSID
87
+ - Supports hidden networks
88
+ - Returns detected channel or 0 if not found
89
+ - Detailed logging for troubleshooting
13
90
 
14
91
  ### Changed
15
92
 
16
- - TBD
93
+ - **Enhanced Documentation** - Updated bridge and basic examples
94
+ - `examples/bridge/bridge.ino` now uses `initAsBridge()` API
95
+ - `examples/basic/basic.ino` demonstrates auto channel detection
96
+ - `BRIDGE_TO_INTERNET.md` rewritten with bridge-centric approach
97
+ - `README.md` includes bridge quick start guide
98
+
99
+ - **StationScan Enhancement** - Modified `stationScan()` to support all-channel scanning
100
+ - When `channel=0`, automatically scans all channels before connecting
101
+ - Auto-updates mesh channel based on detected network
17
102
 
18
103
  ### Fixed
19
104
 
20
105
  - TBD
21
106
 
107
+ ### Backward Compatibility
108
+
109
+ - All existing code continues to work without changes
110
+ - Manual channel configuration (`mesh.init(..., channel)`) still supported
111
+ - Legacy `stationManual()` approach still available
112
+ - No breaking API changes
113
+
22
114
  ## [1.7.9] - 2025-11-08
23
115
 
24
116
  ### Fixed
package/README.md CHANGED
@@ -97,7 +97,27 @@ This fork includes specialized packages for structured IoT communication:
97
97
  - Gateway node identification
98
98
  - Enables heterogeneous mesh networks
99
99
 
100
- All packages provide type-safe serialization, automatic JSON conversion, and mesh-wide broadcasting or targeted messaging. They align with mqtt-schema v0.7.2+ for enterprise IoT integration.
100
+ **Bridge Failover & High Availability (v1.8.0):**
101
+
102
+ - **`BridgeStatusPackage`** (Type 610) - Bridge health monitoring (BRIDGE_STATUS per mqtt-schema v0.7.3+)
103
+ - Internet connectivity status
104
+ - Router signal strength (RSSI)
105
+ - Gateway IP and router channel
106
+ - Heartbeat for failure detection
107
+
108
+ - **`BridgeElectionPackage`** (Type 611) - Automatic failover election (BRIDGE_ELECTION per mqtt-schema v0.7.3+)
109
+ - Router RSSI measurement
110
+ - Node uptime and free memory
111
+ - Distributed consensus protocol
112
+ - RSSI-based winner selection
113
+
114
+ - **`BridgeTakeoverPackage`** (Type 612) - Bridge role announcement (BRIDGE_TAKEOVER per mqtt-schema v0.7.3+)
115
+ - New bridge identification
116
+ - Previous bridge tracking
117
+ - Takeover reason and timestamp
118
+ - Seamless failover notification
119
+
120
+ All packages provide type-safe serialization, automatic JSON conversion, and mesh-wide broadcasting or targeted messaging. They align with mqtt-schema v0.7.3+ for enterprise IoT integration.
101
121
 
102
122
  #### 🚀 Phase 2 Features (v1.7.0+)
103
123
 
@@ -117,6 +137,38 @@ All packages provide type-safe serialization, automatic JSON conversion, and mes
117
137
 
118
138
  See [Phase 2 Guide](docs/PHASE2_GUIDE.md) for complete documentation.
119
139
 
140
+ #### 🔄 Automatic Bridge Failover (v1.8.0)
141
+
142
+ **High Availability for Critical Systems**
143
+
144
+ - 🎯 **RSSI-Based Election** - Best signal strength wins bridge role
145
+ - 🔍 **Automatic Detection** - 60-second failure detection via heartbeats
146
+ - ⚡ **Fast Failover** - 60-70 second typical recovery time
147
+ - 🌐 **Distributed Consensus** - No single coordinator, deterministic winner selection
148
+ - 🛡️ **Split-Brain Prevention** - State machine prevents concurrent elections
149
+ - 📊 **Tiebreaker Rules** - RSSI → Uptime → Memory → Node ID
150
+
151
+ **Use Cases:**
152
+ - Fish farm alarm systems requiring 24/7 Internet connectivity
153
+ - Industrial IoT networks with critical sensor monitoring
154
+ - Smart building systems needing continuous cloud connectivity
155
+
156
+ **Example:**
157
+ ```cpp
158
+ // Enable automatic bridge failover
159
+ mesh.setRouterCredentials(ROUTER_SSID, ROUTER_PASSWORD);
160
+ mesh.enableBridgeFailover(true);
161
+ mesh.onBridgeRoleChanged(&bridgeRoleCallback);
162
+
163
+ void bridgeRoleCallback(bool isBridge, String reason) {
164
+ if (isBridge) {
165
+ Serial.printf("🎯 Promoted to bridge: %s\n", reason.c_str());
166
+ }
167
+ }
168
+ ```
169
+
170
+ See [Bridge Failover Guide](docs/BRIDGE_FAILOVER.md) and [bridge_failover example](examples/bridge_failover/) for complete documentation.
171
+
120
172
  #### MQTT Bridge Commands
121
173
 
122
174
  The MQTT bridge enables bidirectional communication between MQTT brokers and mesh networks:
@@ -242,6 +294,61 @@ void receivedCallback(uint32_t from, String& msg) {
242
294
  }
243
295
  ```
244
296
 
297
+ ### Bridge to Internet (Auto Channel Detection)
298
+
299
+ The new bridge-centric architecture makes it easy to connect your mesh to the Internet via a router. The bridge node automatically detects the router's channel and configures the mesh accordingly.
300
+
301
+ #### Bridge Node
302
+
303
+ ```cpp
304
+ #include "painlessMesh.h"
305
+
306
+ #define MESH_PREFIX "MyMeshNetwork"
307
+ #define MESH_PASSWORD "somethingSneaky"
308
+ #define ROUTER_SSID "YourRouterSSID"
309
+ #define ROUTER_PASSWORD "YourRouterPassword"
310
+
311
+ Scheduler userScheduler;
312
+ painlessMesh mesh;
313
+
314
+ void setup() {
315
+ Serial.begin(115200);
316
+ mesh.setDebugMsgTypes(ERROR | STARTUP | CONNECTION);
317
+
318
+ // Single call does everything:
319
+ // 1. Connects to router and detects its channel
320
+ // 2. Initializes mesh on detected channel
321
+ // 3. Sets node as root/bridge
322
+ mesh.initAsBridge(MESH_PREFIX, MESH_PASSWORD,
323
+ ROUTER_SSID, ROUTER_PASSWORD,
324
+ &userScheduler, 5555);
325
+
326
+ mesh.onReceive(&receivedCallback);
327
+ }
328
+
329
+ void loop() { mesh.update(); }
330
+
331
+ void receivedCallback(uint32_t from, String& msg) {
332
+ // Forward mesh data to Internet services (MQTT, HTTP, etc.)
333
+ }
334
+ ```
335
+
336
+ #### Regular Nodes (Auto Channel Detection)
337
+
338
+ ```cpp
339
+ void setup() {
340
+ Serial.begin(115200);
341
+
342
+ // channel=0 means auto-detect the mesh channel
343
+ mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, 5555,
344
+ WIFI_AP_STA, 0);
345
+
346
+ mesh.onReceive(&receivedCallback);
347
+ }
348
+ ```
349
+
350
+ See [BRIDGE_TO_INTERNET.md](BRIDGE_TO_INTERNET.md) for complete documentation.
351
+
245
352
  ### Package Types
246
353
 
247
354
  | Type | Class | Purpose | Fields |