@alteriom/painlessmesh 1.9.18 → 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.
- package/CHANGELOG.md +62 -0
- package/README.md +82 -63
- package/examples/alteriom/README.md +4 -4
- package/examples/alteriom/alteriom_custom_package_template.hpp +320 -0
- package/examples/alteriom/alteriom_sensor_package.hpp +1 -1
- package/examples/alteriom/mppt_example/alteriom_mppt_example.ino +208 -0
- package/examples/bridge_failover/bridge_failover.ino +17 -0
- package/examples/sendToInternet/CMakeLists.txt +54 -0
- package/examples/sendToInternet/PC_NODE_README.md +517 -0
- package/examples/sendToInternet/README.md +39 -1
- package/examples/sendToInternet/build.sh +153 -0
- package/examples/sendToInternet/mock_server_test.ino +361 -0
- package/examples/sendToInternet/pc_mesh_node.cpp +361 -0
- package/library.json +4 -1
- package/library.properties +1 -1
- package/package.json +3 -3
- package/src/AlteriomPainlessMesh.h +5 -13
- package/src/arduino/wifi.hpp +306 -100
- package/src/connection.cpp +10 -0
- package/src/painlessMesh.h +1 -14
- package/src/painlessmesh/connection.hpp +11 -16
- package/src/painlessmesh/gateway.hpp +0 -1061
- package/src/painlessmesh/mesh.hpp +58 -86
- package/src/painlessmesh/message_queue.hpp +1 -2
- package/src/painlessmesh/metrics.hpp +2 -262
- package/src/painlessmesh/validation.hpp +0 -143
- package/docs/README.md +0 -132
- package/docs/alteriom/overview.md +0 -531
- package/docs/api/core-api.md +0 -607
- package/docs/api/shared-gateway.md +0 -1207
- package/docs/architecture/mesh-architecture.md +0 -399
- package/docs/architecture/plugin-system.md +0 -517
- package/docs/getting-started/arduino-manual-install.md +0 -313
- package/docs/getting-started/first-mesh.md +0 -410
- package/docs/getting-started/installation.md +0 -275
- package/docs/getting-started/quickstart.md +0 -158
- package/docs/troubleshooting/common-issues.md +0 -679
- package/docs/troubleshooting/debugging.md +0 -455
- package/docs/troubleshooting/external-device-connection.md +0 -283
- package/docs/troubleshooting/faq.md +0 -574
- package/docs/tutorials/basic-examples.md +0 -718
package/docs/README.md
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
# 📚 AlteriomPainlessMesh Documentation
|
|
2
|
-
|
|
3
|
-
Welcome to the comprehensive documentation for the Alteriom fork of painlessMesh - a user-friendly ESP8266/ESP32 mesh networking library with advanced OTA updates, MQTT integration, and structured IoT packages.
|
|
4
|
-
|
|
5
|
-
## 🌟 What's New in Alteriom Fork
|
|
6
|
-
|
|
7
|
-
- **Broadcast OTA Distribution** - 98% network traffic reduction for large meshes
|
|
8
|
-
- **MQTT Status Bridge** - Enterprise monitoring integration (Grafana, InfluxDB)
|
|
9
|
-
- **Structured Packages** - SensorPackage, CommandPackage, StatusPackage
|
|
10
|
-
- **Enhanced CI/CD** - Automated releases to NPM, PlatformIO, Arduino Library Manager
|
|
11
|
-
|
|
12
|
-
## 📖 Documentation Structure
|
|
13
|
-
|
|
14
|
-
### Getting Started
|
|
15
|
-
|
|
16
|
-
- [Quick Start Guide](getting-started/quickstart.md) - Get up and running in minutes
|
|
17
|
-
- [Installation](getting-started/installation.md) - Detailed installation instructions
|
|
18
|
-
- [First Mesh Network](getting-started/first-mesh.md) - Your first working mesh
|
|
19
|
-
|
|
20
|
-
### Architecture & Design
|
|
21
|
-
|
|
22
|
-
- [Mesh Architecture](architecture/mesh-architecture.md) - How painlessMesh works internally
|
|
23
|
-
- [Plugin System](architecture/plugin-system.md) - Understanding the plugin architecture
|
|
24
|
-
- [Message Routing](architecture/routing.md) - Message routing algorithms and strategies
|
|
25
|
-
- [Time Synchronization](architecture/time-sync.md) - Mesh-wide time synchronization
|
|
26
|
-
|
|
27
|
-
### API Reference
|
|
28
|
-
|
|
29
|
-
- [Core API](api/core-api.md) - Main painlessMesh class methods
|
|
30
|
-
- [Shared Gateway API](api/shared-gateway.md) - Shared Gateway Mode reference (v1.9.0+)
|
|
31
|
-
- [Plugin API](api/plugin-api.md) - Creating custom packages and plugins
|
|
32
|
-
- [Configuration](api/configuration.md) - Configuration options and constants
|
|
33
|
-
- [Callbacks](api/callbacks.md) - Event handling and callbacks
|
|
34
|
-
|
|
35
|
-
### Tutorials & Examples
|
|
36
|
-
|
|
37
|
-
- [Basic Examples](tutorials/basic-examples.md) - Simple mesh networking examples
|
|
38
|
-
- [Custom Packages](tutorials/custom-packages.md) - Creating your own message types
|
|
39
|
-
- [Sensor Networks](tutorials/sensor-networks.md) - Building IoT sensor networks
|
|
40
|
-
- [Bridge to Internet](../BRIDGE_TO_INTERNET.md) - Connecting mesh to WiFi/Internet/MQTT
|
|
41
|
-
|
|
42
|
-
### Alteriom Extensions
|
|
43
|
-
|
|
44
|
-
- [Alteriom Overview](alteriom/overview.md) - Alteriom-specific functionality
|
|
45
|
-
- [Sensor Packages](alteriom/sensor-packages.md) - Environmental sensor data handling
|
|
46
|
-
- [Command System](alteriom/command-system.md) - Device command and control
|
|
47
|
-
- [Status Monitoring](alteriom/status-monitoring.md) - Device health and diagnostics
|
|
48
|
-
|
|
49
|
-
### 📡 MQTT Integration
|
|
50
|
-
|
|
51
|
-
- **[MQTT Bridge Commands](MQTT_BRIDGE_COMMANDS.md)** - Complete MQTT command API
|
|
52
|
-
- **[MQTT Bridge Implementation](MQTT_BRIDGE_IMPLEMENTATION_SUMMARY.md)** - Implementation details
|
|
53
|
-
- **[MQTT Schema Compliance](MQTT_SCHEMA_COMPLIANCE.md)** - Schema validation
|
|
54
|
-
- **[OTA Commands Reference](OTA_COMMANDS_REFERENCE.md)** - OTA update commands
|
|
55
|
-
- **[Mesh Topology Guide](MESH_TOPOLOGY_GUIDE.md)** - Topology reporting over MQTT
|
|
56
|
-
|
|
57
|
-
### Advanced Topics
|
|
58
|
-
|
|
59
|
-
- [Performance Optimization](advanced/performance.md) - Optimizing mesh performance
|
|
60
|
-
- [Memory Management](advanced/memory.md) - Managing ESP8266/ESP32 memory constraints
|
|
61
|
-
- [Security Considerations](advanced/security.md) - Securing your mesh network
|
|
62
|
-
- [OTA Updates](advanced/ota.md) - Over-the-air firmware updates in mesh
|
|
63
|
-
|
|
64
|
-
### Troubleshooting
|
|
65
|
-
|
|
66
|
-
- [Common Issues](troubleshooting/common-issues.md) - Solutions to frequent problems
|
|
67
|
-
- [ESP32-C6 Compatibility](troubleshooting/ESP32_C6_COMPATIBILITY.md) - ESP32-C6 specific issues and solutions
|
|
68
|
-
- [Debugging Guide](troubleshooting/debugging.md) - Tools and techniques for debugging
|
|
69
|
-
- [FAQ](troubleshooting/faq.md) - Frequently asked questions
|
|
70
|
-
- [Network Issues](troubleshooting/network-issues.md) - Connectivity and mesh topology problems
|
|
71
|
-
|
|
72
|
-
### Development
|
|
73
|
-
|
|
74
|
-
- [Contributing](development/contributing.md) - How to contribute to painlessMesh
|
|
75
|
-
- [Building & Testing](development/building.md) - Development environment setup
|
|
76
|
-
- [Documentation](development/documentation.md) - Contributing to documentation
|
|
77
|
-
- [Release Process](development/releases.md) - Understanding releases and versioning
|
|
78
|
-
- **[Docker Testing](development/DOCKER_TESTING.md)** - Containerized testing environment
|
|
79
|
-
- **[Testing Summary](development/TESTING_SUMMARY.md)** - Complete test suite overview
|
|
80
|
-
- **[Arduino Compliance](development/ARDUINO_COMPLIANCE_SUMMARY.md)** - Arduino Library Manager standards
|
|
81
|
-
- **[PlatformIO Usage](development/PLATFORMIO_USAGE.md)** - PlatformIO integration guide
|
|
82
|
-
|
|
83
|
-
### 📦 Releases & Changelogs
|
|
84
|
-
|
|
85
|
-
- **[Feature History](releases/FEATURE_HISTORY.md)** - ⭐ Consolidated Phase 1 & 2 development history
|
|
86
|
-
- **[Release Notes v1.7.0](releases/RELEASE_NOTES_1.7.0.md)** - Detailed v1.7.0 release notes
|
|
87
|
-
- **[CHANGELOG](../CHANGELOG.md)** - Complete version history
|
|
88
|
-
- **[RELEASE_GUIDE](../RELEASE_GUIDE.md)** - Maintainer release process
|
|
89
|
-
- [Phase 1 Details](releases/PHASE1_SUMMARY.md) - v1.6.x detailed summary (archived)
|
|
90
|
-
- [Phase 2 Details](releases/PHASE2_SUMMARY.md) - v1.7.x detailed summary (archived)
|
|
91
|
-
|
|
92
|
-
### 🗂️ Core Documentation (Root)
|
|
93
|
-
|
|
94
|
-
- **[Main README](../README.md)** - Project overview and quick start
|
|
95
|
-
- **[CONTRIBUTING](../CONTRIBUTING.md)** - Contribution guidelines
|
|
96
|
-
- **[LICENSE](../LICENSE)** - LGPL-3.0 license terms
|
|
97
|
-
|
|
98
|
-
### 🗃️ Historical & Archive
|
|
99
|
-
|
|
100
|
-
- **[Archive](archive/)** - Historical bug fixes and obsolete documentation
|
|
101
|
-
- Bug fix documentation (SCONS, VECTOR, LIBRARY fixes)
|
|
102
|
-
- Legacy deployment guides
|
|
103
|
-
- Superseded release documentation
|
|
104
|
-
|
|
105
|
-
### 🚀 Improvements & Enhancements
|
|
106
|
-
|
|
107
|
-
- **[Improvements Overview](improvements/README.md)** - Complete guide to library enhancements
|
|
108
|
-
- **[OTA & Status Enhancements](improvements/OTA_STATUS_ENHANCEMENTS.md)** 📋 - Complete reference for all options
|
|
109
|
-
- ✅ Phase 1 (v1.6.x): Compressed OTA + Enhanced Status
|
|
110
|
-
- ✅ Phase 2 (v1.7.0): Broadcast OTA + MQTT Bridge
|
|
111
|
-
- 📋 Phase 3 (Future): Progressive rollout, P2P distribution, real-time telemetry
|
|
112
|
-
- **[Implementation History](improvements/IMPLEMENTATION_HISTORY.md)** 🔧 - Technical details for Phases 1-2
|
|
113
|
-
- **[Future Proposals](improvements/FUTURE_PROPOSALS.md)** 🚀 - Phase 3+ roadmap and specifications
|
|
114
|
-
|
|
115
|
-
## Quick Links
|
|
116
|
-
|
|
117
|
-
- **[GitHub Repository](https://github.com/Alteriom/painlessMesh)**
|
|
118
|
-
- **[API Documentation](https://alteriom.github.io/painlessMesh/#/api/doxygen)**
|
|
119
|
-
- **[Community Forum](https://groups.google.com/forum/#!forum/painlessmesh-user)**
|
|
120
|
-
- **[Issue Tracker](https://github.com/Alteriom/painlessMesh/issues)**
|
|
121
|
-
|
|
122
|
-
## Need Help?
|
|
123
|
-
|
|
124
|
-
- Start with the [Quick Start Guide](getting-started/quickstart.md)
|
|
125
|
-
- Check the [FAQ](troubleshooting/faq.md) for common questions
|
|
126
|
-
- Browse [Examples](tutorials/basic-examples.md) for practical use cases
|
|
127
|
-
- Join our [Community Forum](https://groups.google.com/forum/#!forum/painlessmesh-user)
|
|
128
|
-
- Report bugs on the [Issue Tracker](https://github.com/Alteriom/painlessMesh/issues)
|
|
129
|
-
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
This documentation is maintained by the painlessMesh community. Contributions are welcome! See our [Documentation Contributing Guide](development/documentation.md) to get started.
|
|
@@ -1,531 +0,0 @@
|
|
|
1
|
-
# Alteriom Extensions Overview
|
|
2
|
-
|
|
3
|
-
The Alteriom extensions provide production-ready, type-safe packages for common IoT scenarios. These extensions demonstrate best practices for the painlessMesh plugin system while providing immediately useful functionality for sensor networks, device control, and system monitoring.
|
|
4
|
-
|
|
5
|
-
## What are Alteriom Extensions?
|
|
6
|
-
|
|
7
|
-
Alteriom extensions are pre-built painlessMesh packages that handle common IoT communication patterns:
|
|
8
|
-
|
|
9
|
-
- **Environmental Monitoring**: Temperature, humidity, pressure sensors
|
|
10
|
-
- **Device Control**: Commands for actuators, displays, relays
|
|
11
|
-
- **Health Monitoring**: Device status, diagnostics, and telemetry
|
|
12
|
-
- **Type Safety**: Compile-time validation and automatic serialization
|
|
13
|
-
- **Production Ready**: Tested, documented, and optimized implementations
|
|
14
|
-
|
|
15
|
-
## Package Types
|
|
16
|
-
|
|
17
|
-
### SensorPackage (Type 200)
|
|
18
|
-
For broadcasting environmental sensor data across the mesh.
|
|
19
|
-
|
|
20
|
-
```cpp
|
|
21
|
-
alteriom::SensorPackage sensor;
|
|
22
|
-
sensor.temperature = 23.5;
|
|
23
|
-
sensor.humidity = 65.0;
|
|
24
|
-
sensor.pressure = 1013.25;
|
|
25
|
-
sensor.sensorId = 1001;
|
|
26
|
-
sensor.timestamp = mesh.getNodeTime();
|
|
27
|
-
sensor.batteryLevel = 85;
|
|
28
|
-
|
|
29
|
-
mesh.sendPackage(&sensor);
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
**Use Cases:**
|
|
33
|
-
- Weather stations
|
|
34
|
-
- Environmental monitoring
|
|
35
|
-
- HVAC system feedback
|
|
36
|
-
- Greenhouse automation
|
|
37
|
-
- Industrial sensor networks
|
|
38
|
-
|
|
39
|
-
### CommandPackage (Type 400)
|
|
40
|
-
For sending control commands to specific devices.
|
|
41
|
-
|
|
42
|
-
```cpp
|
|
43
|
-
alteriom::CommandPackage cmd;
|
|
44
|
-
cmd.dest = targetNodeId;
|
|
45
|
-
cmd.command = 1; // LED_CONTROL
|
|
46
|
-
cmd.targetDevice = 100; // LED strip ID
|
|
47
|
-
cmd.parameters = "{\"brightness\":75,\"color\":\"blue\"}";
|
|
48
|
-
cmd.commandId = generateCommandId();
|
|
49
|
-
|
|
50
|
-
mesh.sendPackage(&cmd);
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
**Use Cases:**
|
|
54
|
-
- Remote device control
|
|
55
|
-
- Actuator management
|
|
56
|
-
- Display updates
|
|
57
|
-
- System configuration
|
|
58
|
-
- Automation triggers
|
|
59
|
-
|
|
60
|
-
### StatusPackage (Type 202)
|
|
61
|
-
For broadcasting device health and operational status.
|
|
62
|
-
|
|
63
|
-
```cpp
|
|
64
|
-
alteriom::StatusPackage status;
|
|
65
|
-
status.deviceStatus = 1; // OPERATIONAL
|
|
66
|
-
status.uptime = millis() / 1000;
|
|
67
|
-
status.freeMemory = ESP.getFreeHeap();
|
|
68
|
-
status.wifiStrength = WiFi.RSSI();
|
|
69
|
-
status.firmwareVersion = "1.2.3";
|
|
70
|
-
|
|
71
|
-
mesh.sendPackage(&status);
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
**Use Cases:**
|
|
75
|
-
- System monitoring
|
|
76
|
-
- Predictive maintenance
|
|
77
|
-
- Network diagnostics
|
|
78
|
-
- Performance tracking
|
|
79
|
-
- Remote troubleshooting
|
|
80
|
-
|
|
81
|
-
## Key Features
|
|
82
|
-
|
|
83
|
-
### Type Safety
|
|
84
|
-
Compile-time validation prevents common messaging errors:
|
|
85
|
-
|
|
86
|
-
```cpp
|
|
87
|
-
// Compile error if field types don't match
|
|
88
|
-
sensor.temperature = "invalid"; // ❌ Compiler error
|
|
89
|
-
sensor.temperature = 25.0; // ✅ Correct
|
|
90
|
-
|
|
91
|
-
// IDE autocomplete for all fields
|
|
92
|
-
sensor.| // IDE shows: temperature, humidity, pressure, etc.
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Automatic Serialization
|
|
96
|
-
No manual JSON handling required:
|
|
97
|
-
|
|
98
|
-
```cpp
|
|
99
|
-
// Automatic serialization to JSON
|
|
100
|
-
mesh.sendPackage(&sensor);
|
|
101
|
-
|
|
102
|
-
// Automatic deserialization from JSON
|
|
103
|
-
mesh.onPackage(200, [](protocol::Variant& variant) {
|
|
104
|
-
alteriom::SensorPackage received = variant.to<alteriom::SensorPackage>();
|
|
105
|
-
// All fields automatically populated
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Cross-Platform Compatibility
|
|
110
|
-
Works on ESP32, ESP8266, and desktop platforms:
|
|
111
|
-
|
|
112
|
-
```cpp
|
|
113
|
-
// TSTRING adapts to platform
|
|
114
|
-
#ifdef ESP32
|
|
115
|
-
// Uses Arduino String class
|
|
116
|
-
#else
|
|
117
|
-
// Uses std::string on desktop
|
|
118
|
-
#endif
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Memory Optimization
|
|
122
|
-
Efficient memory usage for resource-constrained devices:
|
|
123
|
-
|
|
124
|
-
```cpp
|
|
125
|
-
// Accurate buffer sizing
|
|
126
|
-
size_t bufferSize = sensor.jsonObjectSize();
|
|
127
|
-
|
|
128
|
-
// Minimal memory footprint
|
|
129
|
-
// No unnecessary string copies or allocations
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## Architecture Integration
|
|
133
|
-
|
|
134
|
-
### Plugin System
|
|
135
|
-
Alteriom packages integrate seamlessly with painlessMesh's plugin architecture:
|
|
136
|
-
|
|
137
|
-
```
|
|
138
|
-
Application Layer (Your Code)
|
|
139
|
-
↓
|
|
140
|
-
Alteriom Packages (SensorPackage, CommandPackage, StatusPackage)
|
|
141
|
-
↓
|
|
142
|
-
painlessMesh Plugin System (SinglePackage, BroadcastPackage)
|
|
143
|
-
↓
|
|
144
|
-
painlessMesh Core (Mesh, Protocol, Network)
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Message Flow
|
|
148
|
-
```
|
|
149
|
-
Sensor Reading → SensorPackage → JSON → Mesh Network → JSON → SensorPackage → Handler
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
### Type ID Allocation
|
|
153
|
-
Alteriom uses reserved type ID range 200-299:
|
|
154
|
-
|
|
155
|
-
```cpp
|
|
156
|
-
enum AlteriomTypes {
|
|
157
|
-
ALTERIOM_SENSOR = 200, // SensorPackage
|
|
158
|
-
ALTERIOM_COMMAND = 400, // CommandPackage
|
|
159
|
-
ALTERIOM_STATUS = 202, // StatusPackage
|
|
160
|
-
// 203-299 reserved for future Alteriom packages
|
|
161
|
-
};
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## Getting Started
|
|
165
|
-
|
|
166
|
-
### 1. Include Alteriom Headers
|
|
167
|
-
|
|
168
|
-
```cpp
|
|
169
|
-
#include "painlessMesh.h"
|
|
170
|
-
#include "examples/alteriom/alteriom_sensor_package.hpp"
|
|
171
|
-
|
|
172
|
-
using namespace alteriom; // For convenience
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### 2. Register Package Handlers
|
|
176
|
-
|
|
177
|
-
```cpp
|
|
178
|
-
void setup() {
|
|
179
|
-
mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
|
|
180
|
-
|
|
181
|
-
// Register handlers for Alteriom packages
|
|
182
|
-
mesh.onPackage(ALTERIOM_SENSOR, handleSensorData);
|
|
183
|
-
mesh.onPackage(ALTERIOM_COMMAND, handleCommand);
|
|
184
|
-
mesh.onPackage(ALTERIOM_STATUS, handleStatus);
|
|
185
|
-
}
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
### 3. Implement Handlers
|
|
189
|
-
|
|
190
|
-
```cpp
|
|
191
|
-
void handleSensorData(protocol::Variant& variant) {
|
|
192
|
-
SensorPackage sensor = variant.to<SensorPackage>();
|
|
193
|
-
|
|
194
|
-
Serial.printf("Sensor %u: T=%.1f°C, H=%.1f%%, P=%.1f hPa\n",
|
|
195
|
-
sensor.sensorId, sensor.temperature,
|
|
196
|
-
sensor.humidity, sensor.pressure);
|
|
197
|
-
|
|
198
|
-
// Process sensor data (store, analyze, forward, etc.)
|
|
199
|
-
if (sensor.temperature > 30.0) {
|
|
200
|
-
triggerCooling();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
void handleCommand(protocol::Variant& variant) {
|
|
205
|
-
CommandPackage cmd = variant.to<CommandPackage>();
|
|
206
|
-
|
|
207
|
-
if (cmd.dest != mesh.getNodeId()) {
|
|
208
|
-
return; // Not for this node
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
Serial.printf("Command %u for device %u: %u\n",
|
|
212
|
-
cmd.commandId, cmd.targetDevice, cmd.command);
|
|
213
|
-
|
|
214
|
-
// Execute command
|
|
215
|
-
executeDeviceCommand(cmd);
|
|
216
|
-
|
|
217
|
-
// Send acknowledgment
|
|
218
|
-
sendCommandAcknowledgment(cmd);
|
|
219
|
-
}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
### 4. Send Packages
|
|
223
|
-
|
|
224
|
-
```cpp
|
|
225
|
-
// Send sensor data every 30 seconds
|
|
226
|
-
Task taskSensorData(30000, TASK_FOREVER, [](){
|
|
227
|
-
SensorPackage sensor;
|
|
228
|
-
sensor.from = mesh.getNodeId();
|
|
229
|
-
sensor.temperature = readTemperature();
|
|
230
|
-
sensor.humidity = readHumidity();
|
|
231
|
-
sensor.pressure = readPressure();
|
|
232
|
-
sensor.sensorId = SENSOR_ID;
|
|
233
|
-
sensor.timestamp = mesh.getNodeTime();
|
|
234
|
-
sensor.batteryLevel = readBatteryLevel();
|
|
235
|
-
|
|
236
|
-
mesh.sendPackage(&sensor);
|
|
237
|
-
});
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
## Advanced Usage
|
|
241
|
-
|
|
242
|
-
### Custom Command Types
|
|
243
|
-
|
|
244
|
-
Define application-specific command types:
|
|
245
|
-
|
|
246
|
-
```cpp
|
|
247
|
-
enum DeviceCommands {
|
|
248
|
-
LED_CONTROL = 1,
|
|
249
|
-
SERVO_POSITION = 2,
|
|
250
|
-
RELAY_SWITCH = 3,
|
|
251
|
-
DISPLAY_UPDATE = 4,
|
|
252
|
-
SENSOR_CALIBRATION = 5
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
void executeDeviceCommand(const CommandPackage& cmd) {
|
|
256
|
-
switch(cmd.command) {
|
|
257
|
-
case LED_CONTROL:
|
|
258
|
-
handleLEDCommand(cmd);
|
|
259
|
-
break;
|
|
260
|
-
case SERVO_POSITION:
|
|
261
|
-
handleServoCommand(cmd);
|
|
262
|
-
break;
|
|
263
|
-
// ... other commands
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
### Command Parameters
|
|
269
|
-
|
|
270
|
-
Use JSON parameters for complex commands:
|
|
271
|
-
|
|
272
|
-
```cpp
|
|
273
|
-
void handleLEDCommand(const CommandPackage& cmd) {
|
|
274
|
-
// Parse JSON parameters
|
|
275
|
-
DynamicJsonDocument doc(256);
|
|
276
|
-
deserializeJson(doc, cmd.parameters);
|
|
277
|
-
|
|
278
|
-
int brightness = doc["brightness"];
|
|
279
|
-
String color = doc["color"];
|
|
280
|
-
int duration = doc["duration"];
|
|
281
|
-
|
|
282
|
-
// Execute LED control
|
|
283
|
-
setLEDColor(color);
|
|
284
|
-
setLEDBrightness(brightness);
|
|
285
|
-
if (duration > 0) {
|
|
286
|
-
scheduleAutoOff(duration);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
### Status Monitoring
|
|
292
|
-
|
|
293
|
-
Implement comprehensive device monitoring:
|
|
294
|
-
|
|
295
|
-
```cpp
|
|
296
|
-
void sendStatusUpdate() {
|
|
297
|
-
StatusPackage status;
|
|
298
|
-
status.from = mesh.getNodeId();
|
|
299
|
-
status.deviceStatus = getDeviceStatus();
|
|
300
|
-
status.uptime = millis() / 1000;
|
|
301
|
-
status.freeMemory = ESP.getFreeHeap();
|
|
302
|
-
status.wifiStrength = WiFi.RSSI();
|
|
303
|
-
status.firmwareVersion = FIRMWARE_VERSION;
|
|
304
|
-
|
|
305
|
-
// Add custom diagnostics
|
|
306
|
-
if (ESP.getFreeHeap() < 10000) {
|
|
307
|
-
status.deviceStatus |= STATUS_LOW_MEMORY;
|
|
308
|
-
}
|
|
309
|
-
if (WiFi.RSSI() < -80) {
|
|
310
|
-
status.deviceStatus |= STATUS_WEAK_SIGNAL;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
mesh.sendPackage(&status);
|
|
314
|
-
}
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
### Error Handling
|
|
318
|
-
|
|
319
|
-
Implement robust error handling:
|
|
320
|
-
|
|
321
|
-
```cpp
|
|
322
|
-
void handleSensorData(protocol::Variant& variant) {
|
|
323
|
-
try {
|
|
324
|
-
SensorPackage sensor = variant.to<SensorPackage>();
|
|
325
|
-
|
|
326
|
-
// Validate sensor data
|
|
327
|
-
if (!isValidSensorReading(sensor)) {
|
|
328
|
-
Serial.printf("Invalid sensor data from node %u\n", sensor.from);
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Check data age
|
|
333
|
-
uint32_t age = mesh.getNodeTime() - sensor.timestamp;
|
|
334
|
-
if (age > MAX_DATA_AGE) {
|
|
335
|
-
Serial.printf("Stale sensor data (age: %u µs)\n", age);
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
processSensorData(sensor);
|
|
340
|
-
|
|
341
|
-
} catch (const std::exception& e) {
|
|
342
|
-
Serial.printf("Error processing sensor data: %s\n", e.what());
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
## Integration Patterns
|
|
348
|
-
|
|
349
|
-
### Sensor Network Pattern
|
|
350
|
-
|
|
351
|
-
Central collector with multiple sensor nodes:
|
|
352
|
-
|
|
353
|
-
```cpp
|
|
354
|
-
class SensorCollector {
|
|
355
|
-
private:
|
|
356
|
-
std::map<uint32_t, SensorData> sensorReadings;
|
|
357
|
-
|
|
358
|
-
public:
|
|
359
|
-
void setup() {
|
|
360
|
-
mesh.onPackage(ALTERIOM_SENSOR, [this](protocol::Variant& variant) {
|
|
361
|
-
SensorPackage sensor = variant.to<SensorPackage>();
|
|
362
|
-
storeSensorReading(sensor);
|
|
363
|
-
return false;
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
void storeSensorReading(const SensorPackage& sensor) {
|
|
368
|
-
sensorReadings[sensor.from] = {
|
|
369
|
-
sensor.temperature,
|
|
370
|
-
sensor.humidity,
|
|
371
|
-
sensor.pressure,
|
|
372
|
-
sensor.timestamp
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
// Trigger analysis
|
|
376
|
-
analyzeEnvironmentalData();
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
### Command and Control Pattern
|
|
382
|
-
|
|
383
|
-
Central controller managing multiple devices:
|
|
384
|
-
|
|
385
|
-
```cpp
|
|
386
|
-
class DeviceController {
|
|
387
|
-
private:
|
|
388
|
-
std::map<uint32_t, DeviceInfo> devices;
|
|
389
|
-
|
|
390
|
-
public:
|
|
391
|
-
void controlDevice(uint32_t nodeId, uint32_t deviceId,
|
|
392
|
-
uint8_t command, const String& parameters) {
|
|
393
|
-
CommandPackage cmd;
|
|
394
|
-
cmd.dest = nodeId;
|
|
395
|
-
cmd.command = command;
|
|
396
|
-
cmd.targetDevice = deviceId;
|
|
397
|
-
cmd.parameters = parameters;
|
|
398
|
-
cmd.commandId = generateCommandId();
|
|
399
|
-
|
|
400
|
-
mesh.sendPackage(&cmd);
|
|
401
|
-
|
|
402
|
-
// Track pending command
|
|
403
|
-
pendingCommands[cmd.commandId] = {nodeId, millis()};
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
void handleCommandAck(const CommandPackage& ack) {
|
|
407
|
-
auto it = pendingCommands.find(ack.commandId);
|
|
408
|
-
if (it != pendingCommands.end()) {
|
|
409
|
-
Serial.printf("Command %u acknowledged by node %u\n",
|
|
410
|
-
ack.commandId, ack.from);
|
|
411
|
-
pendingCommands.erase(it);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
### Health Monitoring Pattern
|
|
418
|
-
|
|
419
|
-
Network-wide device health monitoring:
|
|
420
|
-
|
|
421
|
-
```cpp
|
|
422
|
-
class HealthMonitor {
|
|
423
|
-
private:
|
|
424
|
-
std::map<uint32_t, DeviceHealth> deviceHealth;
|
|
425
|
-
|
|
426
|
-
public:
|
|
427
|
-
void setup() {
|
|
428
|
-
mesh.onPackage(ALTERIOM_STATUS, [this](protocol::Variant& variant) {
|
|
429
|
-
StatusPackage status = variant.to<StatusPackage>();
|
|
430
|
-
updateDeviceHealth(status);
|
|
431
|
-
return false;
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
// Check for unhealthy devices every minute
|
|
435
|
-
userScheduler.addTask(Task(60000, TASK_FOREVER, [this]() {
|
|
436
|
-
checkDeviceHealth();
|
|
437
|
-
}));
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
void updateDeviceHealth(const StatusPackage& status) {
|
|
441
|
-
deviceHealth[status.from] = {
|
|
442
|
-
status.deviceStatus,
|
|
443
|
-
status.uptime,
|
|
444
|
-
status.freeMemory,
|
|
445
|
-
status.wifiStrength,
|
|
446
|
-
mesh.getNodeTime() // Last seen
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
void checkDeviceHealth() {
|
|
451
|
-
uint32_t now = mesh.getNodeTime();
|
|
452
|
-
|
|
453
|
-
for (auto& [nodeId, health] : deviceHealth) {
|
|
454
|
-
uint32_t timeSinceLastSeen = now - health.lastSeen;
|
|
455
|
-
|
|
456
|
-
if (timeSinceLastSeen > DEVICE_TIMEOUT) {
|
|
457
|
-
Serial.printf("Device %u appears offline\n", nodeId);
|
|
458
|
-
triggerAlert(nodeId, "Device offline");
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (health.freeMemory < LOW_MEMORY_THRESHOLD) {
|
|
462
|
-
Serial.printf("Device %u low memory: %u bytes\n",
|
|
463
|
-
nodeId, health.freeMemory);
|
|
464
|
-
triggerAlert(nodeId, "Low memory");
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
## Best Practices
|
|
472
|
-
|
|
473
|
-
### Performance Optimization
|
|
474
|
-
|
|
475
|
-
1. **Batch sensor readings** when possible
|
|
476
|
-
2. **Use appropriate message frequency** (don't spam the network)
|
|
477
|
-
3. **Implement message filtering** to avoid processing irrelevant data
|
|
478
|
-
4. **Monitor memory usage** especially on ESP8266
|
|
479
|
-
|
|
480
|
-
### Reliability
|
|
481
|
-
|
|
482
|
-
1. **Validate all received data** before processing
|
|
483
|
-
2. **Implement timeouts** for commands and responses
|
|
484
|
-
3. **Handle network partitions** gracefully
|
|
485
|
-
4. **Add retry logic** for critical commands
|
|
486
|
-
|
|
487
|
-
### Security
|
|
488
|
-
|
|
489
|
-
1. **Validate message sources** in handlers
|
|
490
|
-
2. **Sanitize command parameters** before execution
|
|
491
|
-
3. **Implement rate limiting** for commands
|
|
492
|
-
4. **Consider encryption** for sensitive data
|
|
493
|
-
|
|
494
|
-
### Testing
|
|
495
|
-
|
|
496
|
-
1. **Test with realistic network loads**
|
|
497
|
-
2. **Simulate node failures** and recovery
|
|
498
|
-
3. **Validate under memory pressure**
|
|
499
|
-
4. **Test with maximum expected node count**
|
|
500
|
-
|
|
501
|
-
## Code Conventions
|
|
502
|
-
|
|
503
|
-
### Boolean Field Naming
|
|
504
|
-
|
|
505
|
-
Alteriom packages follow a consistent naming convention for boolean fields to improve code clarity:
|
|
506
|
-
|
|
507
|
-
- **`*Set` suffix**: Configuration data has been provided (e.g., `deviceSecretSet`)
|
|
508
|
-
- **`*Enabled` suffix**: Feature is currently active (e.g., `displayEnabled`)
|
|
509
|
-
- **`is*` prefix or `*Connected`**: Current runtime state (e.g., `mqttConnected`)
|
|
510
|
-
|
|
511
|
-
See [Boolean Naming Convention](../BOOLEAN_NAMING_CONVENTION.md) for complete guidelines.
|
|
512
|
-
|
|
513
|
-
### Time Field Naming
|
|
514
|
-
|
|
515
|
-
Time-based configuration fields follow a dual-unit convention:
|
|
516
|
-
|
|
517
|
-
- **Internal storage**: Always milliseconds (e.g., `sensorReadInterval`)
|
|
518
|
-
- **JSON serialization**: Both milliseconds (`_ms`) and seconds (`_s`) variants
|
|
519
|
-
- **JSON deserialization**: Read from milliseconds (`_ms`) variant
|
|
520
|
-
|
|
521
|
-
See package header documentation for complete details.
|
|
522
|
-
|
|
523
|
-
## Next Steps
|
|
524
|
-
|
|
525
|
-
- Learn about [Sensor Packages](sensor-packages.md) in detail
|
|
526
|
-
- Explore [Command System](command-system.md) implementation
|
|
527
|
-
- Study [Status Monitoring](status-monitoring.md) patterns
|
|
528
|
-
- Review [Boolean Naming Convention](../BOOLEAN_NAMING_CONVENTION.md) guidelines
|
|
529
|
-
- See [Tutorial Examples](../tutorials/sensor-networks.md) for hands-on practice
|
|
530
|
-
|
|
531
|
-
The Alteriom extensions provide a solid foundation for building robust IoT applications with painlessMesh. They demonstrate production-ready patterns while remaining flexible enough to adapt to your specific needs.
|