@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.
- package/CHANGELOG.md +380 -143
- package/LICENSE +674 -674
- package/README.md +477 -434
- package/RELEASE_GUIDE.md +504 -418
- package/docs/DOCUMENTATION_MIGRATION_PLAN.md +175 -175
- package/docs/IMPLEMENTATION_PLAN_MESH_TOPOLOGY.md +1062 -0
- package/docs/MESH_TOPOLOGY_GUIDE.md +992 -0
- package/docs/MESH_TOPOLOGY_PROGRESS.md +422 -0
- package/docs/MQTT_BRIDGE_COMMANDS.md +894 -0
- package/docs/MQTT_BRIDGE_IMPLEMENTATION_SUMMARY.md +324 -0
- package/docs/MQTT_COMMAND_SCHEMA_PROPOSAL.md +576 -0
- package/docs/MQTT_SCHEMA_COMPLIANCE.md +285 -0
- package/docs/MQTT_SCHEMA_PROPOSALS.md +446 -0
- package/docs/MQTT_SCHEMA_REVIEW.md +690 -0
- package/docs/OTA_COMMANDS_REFERENCE.md +554 -0
- package/docs/PHASE1_GUIDE.md +349 -0
- package/docs/PHASE2_GUIDE.md +543 -0
- package/docs/README.md +77 -70
- package/docs/SCHEMA_VALIDATION_CHECKLIST.md +222 -0
- package/docs/alteriom/overview.md +507 -507
- package/docs/api/core-api.md +606 -606
- package/docs/architecture/mesh-architecture.md +378 -378
- package/docs/architecture/plugin-system.md +516 -516
- package/docs/getting-started/first-mesh.md +409 -409
- package/docs/getting-started/installation.md +274 -274
- package/docs/getting-started/quickstart.md +157 -157
- package/docs/improvements/FEATURE_PROPOSALS.md +337 -0
- package/docs/improvements/PHASE1_IMPLEMENTATION.md +325 -0
- package/docs/improvements/PHASE2_IMPLEMENTATION.md +567 -0
- package/docs/improvements/README.md +86 -68
- package/docs/improvements/ota-and-status-enhancements.md +911 -0
- package/docs/improvements/ota-status-architecture-diagrams.md +658 -0
- package/docs/improvements/ota-status-quick-reference.md +284 -0
- package/docs/platformio-publishing.md +255 -0
- package/docs/platformio-setup-summary.md +121 -0
- package/docs/troubleshooting/common-issues.md +520 -520
- package/docs/troubleshooting/faq.md +472 -472
- package/docs/tutorials/basic-examples.md +717 -717
- package/docs/wiki/API-Reference.md +245 -245
- package/docs/wiki/Complete-Documentation.md +122 -122
- package/examples/alteriom/README.md +139 -81
- package/examples/alteriom/alteriom.ino +186 -185
- package/examples/alteriom/alteriom_sensor_package.hpp +240 -127
- package/examples/alteriom/platformio.ini +24 -24
- package/examples/alteriomImproved/alteriom_sensor_package.hpp +224 -0
- package/examples/{alteriom → alteriomImproved}/improved_sensor_node.ino +245 -245
- package/examples/alteriomImproved/platformio.ini +25 -0
- package/examples/alteriomPhase1/alteriom_sensor_package.hpp +224 -0
- package/examples/alteriomPhase1/phase1_features.ino +242 -0
- package/examples/alteriomPhase1/platformio.ini +25 -0
- package/examples/alteriomPhase2/alteriom_sensor_package.hpp +224 -0
- package/examples/alteriomPhase2/phase2_features.ino +186 -0
- package/examples/alteriomPhase2/platformio.ini +25 -0
- package/examples/{alteriom → alteriomSensorNode}/alteriom_sensor_node.ino +183 -183
- package/examples/alteriomSensorNode/alteriom_sensor_package.hpp +224 -0
- package/examples/alteriomSensorNode/platformio.ini +25 -0
- package/examples/basic/basic.ino +66 -66
- package/examples/basic/platformio.ini +25 -25
- package/examples/bridge/bridge.ino +51 -51
- package/examples/bridge/mesh_event_publisher.hpp +253 -0
- package/examples/bridge/mesh_topology_reporter.hpp +303 -0
- package/examples/bridge/mqtt_command_bridge.hpp +459 -0
- package/examples/bridge/mqtt_status_bridge.hpp +519 -0
- package/examples/bridge/platformio.ini +25 -25
- package/examples/echoNode/echoNode.ino +33 -33
- package/examples/echoNode/platformio.ini +25 -25
- package/examples/logClient/logClient.ino +109 -109
- package/examples/logClient/platformio.ini +25 -25
- package/examples/logServer/logServer.ino +81 -81
- package/examples/logServer/platformio.ini +25 -25
- package/examples/meshCommandNode/alteriom_sensor_package.hpp +235 -0
- package/examples/meshCommandNode/meshCommandNode.ino +263 -0
- package/examples/meshCommandNode/platformio.ini +25 -0
- package/examples/mqttBridge/mqttBridge.ino +118 -118
- package/examples/mqttBridge/platformio.ini +26 -26
- package/examples/mqttCommandBridge/alteriom_sensor_package.hpp +235 -0
- package/examples/mqttCommandBridge/mesh_event_publisher.hpp +253 -0
- package/examples/mqttCommandBridge/mesh_topology_reporter.hpp +303 -0
- package/examples/mqttCommandBridge/mqttCommandBridge.ino +252 -0
- package/examples/mqttCommandBridge/mqtt_command_bridge.hpp +459 -0
- package/examples/mqttCommandBridge/platformio.ini +26 -0
- package/examples/mqttStatusBridge/mqttStatusBridge.ino +216 -0
- package/examples/mqttStatusBridge/mqtt_status_bridge.hpp +522 -0
- package/examples/mqttStatusBridge/platformio.ini +26 -0
- package/examples/mqttTopologyTest/README.md +467 -0
- package/examples/mqttTopologyTest/mqttTopologyTest.ino +748 -0
- package/examples/mqttTopologyTest/platformio.ini +26 -0
- package/examples/namedMesh/namedMesh.ino +97 -97
- package/examples/namedMesh/platformio.ini +25 -25
- package/examples/otaReceiver/otaReceiver.ino +79 -79
- package/examples/otaReceiver/platformio.ini +25 -25
- package/examples/otaSender/otaSender.ino +160 -151
- package/examples/otaSender/platformio.ini +25 -25
- package/examples/startHere/platformio.ini +25 -25
- package/examples/startHere/startHere.ino +159 -159
- package/examples/webServer/platformio.ini +27 -27
- package/examples/webServer/webServer.ino +89 -89
- package/keywords.txt +48 -48
- package/library.json +55 -34
- package/library.properties +10 -10
- package/package.json +86 -78
- package/src/AlteriomPainlessMesh.h +97 -97
- package/src/arduino/wifi.hpp +365 -365
- package/src/boost/asynctcp.hpp +279 -279
- package/src/painlessMesh.h +70 -70
- package/src/painlessMeshSTA.cpp +236 -236
- package/src/painlessMeshSTA.h +58 -58
- package/src/painlessTaskOptions.h +4 -4
- package/src/painlessmesh/base64.hpp +111 -111
- package/src/painlessmesh/buffer.hpp +229 -229
- package/src/painlessmesh/callback.hpp +91 -91
- package/src/painlessmesh/configuration.hpp +77 -77
- package/src/painlessmesh/connection.hpp +192 -192
- package/src/painlessmesh/layout.hpp +188 -188
- package/src/painlessmesh/logger.hpp +158 -158
- package/src/painlessmesh/memory.hpp +119 -119
- package/src/painlessmesh/mesh.hpp +761 -560
- package/src/painlessmesh/metrics.hpp +322 -322
- package/src/painlessmesh/ntp.hpp +263 -263
- package/src/painlessmesh/ota.hpp +582 -553
- package/src/painlessmesh/plugin.hpp +188 -188
- package/src/painlessmesh/protocol.hpp +813 -813
- package/src/painlessmesh/router.hpp +322 -322
- package/src/painlessmesh/tcp.hpp +71 -71
- package/src/painlessmesh/validation.hpp +238 -238
- package/src/plugin/performance.hpp +214 -214
- package/src/plugin/remote.hpp +64 -64
- package/src/scheduler.cpp +10 -10
- package/src/wifi.cpp +2 -2
|
@@ -1,246 +1,246 @@
|
|
|
1
|
-
# API Reference
|
|
2
|
-
|
|
3
|
-
This page contains the complete API reference for the Alteriom painlessMesh Library.
|
|
4
|
-
|
|
5
|
-
## Core Classes
|
|
6
|
-
|
|
7
|
-
### painlessMesh
|
|
8
|
-
|
|
9
|
-
The main class for creating and managing mesh networks.
|
|
10
|
-
|
|
11
|
-
#### Initialization Methods
|
|
12
|
-
|
|
13
|
-
```cpp
|
|
14
|
-
void init(String ssid, String password, Scheduler *baseScheduler, uint16_t port = 5555);
|
|
15
|
-
void setDebugMsgTypes(uint16_t types);
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
#### Network Management
|
|
19
|
-
|
|
20
|
-
```cpp
|
|
21
|
-
void update(); // Call in loop()
|
|
22
|
-
bool sendBroadcast(String &msg); // Send to all nodes
|
|
23
|
-
bool sendSingle(uint32_t &destId, String &msg); // Send to specific node
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
#### Event Callbacks
|
|
27
|
-
|
|
28
|
-
```cpp
|
|
29
|
-
void onReceive(std::function<void(uint32_t from, String &msg)> cb);
|
|
30
|
-
void onNewConnection(std::function<void(uint32_t nodeId)> cb);
|
|
31
|
-
void onChangedConnections(std::function<void()> cb);
|
|
32
|
-
void onNodeTimeAdjusted(std::function<void(int32_t offset)> cb);
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
#### Node Information
|
|
36
|
-
|
|
37
|
-
```cpp
|
|
38
|
-
uint32_t getNodeId(); // Get this node's ID
|
|
39
|
-
std::list<uint32_t> getNodeList(); // Get all connected nodes
|
|
40
|
-
uint32_t getNodeTime(); // Get synchronized time
|
|
41
|
-
size_t connectionCount(); // Number of direct connections
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Alteriom Extensions
|
|
45
|
-
|
|
46
|
-
### SensorPackage (Type 200)
|
|
47
|
-
|
|
48
|
-
Environmental data collection package for sensor networks.
|
|
49
|
-
|
|
50
|
-
```cpp
|
|
51
|
-
class SensorPackage : public painlessmesh::plugin::BroadcastPackage {
|
|
52
|
-
public:
|
|
53
|
-
uint32_t sensorId = 0; // Unique sensor identifier
|
|
54
|
-
uint32_t timestamp = 0; // Unix timestamp
|
|
55
|
-
double temperature = 0.0; // Temperature in Celsius
|
|
56
|
-
double humidity = 0.0; // Relative humidity (0-100%)
|
|
57
|
-
double pressure = 0.0; // Atmospheric pressure in hPa
|
|
58
|
-
uint8_t batteryLevel = 0; // Battery level (0-100%)
|
|
59
|
-
|
|
60
|
-
// Constructors
|
|
61
|
-
SensorPackage();
|
|
62
|
-
SensorPackage(JsonObject jsonObj);
|
|
63
|
-
|
|
64
|
-
// Serialization
|
|
65
|
-
JsonObject addTo(JsonObject&& jsonObj) const;
|
|
66
|
-
size_t jsonObjectSize() const;
|
|
67
|
-
};
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
**Usage Example:**
|
|
71
|
-
```cpp
|
|
72
|
-
SensorPackage sensor;
|
|
73
|
-
sensor.sensorId = mesh.getNodeId();
|
|
74
|
-
sensor.timestamp = mesh.getNodeTime();
|
|
75
|
-
sensor.temperature = 23.5;
|
|
76
|
-
sensor.humidity = 65.0;
|
|
77
|
-
sensor.pressure = 1013.25;
|
|
78
|
-
sensor.batteryLevel = 85;
|
|
79
|
-
|
|
80
|
-
// Send as broadcast
|
|
81
|
-
auto variant = painlessmesh::protocol::Variant(&sensor);
|
|
82
|
-
String message;
|
|
83
|
-
variant.printTo(message);
|
|
84
|
-
mesh.sendBroadcast(message);
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### CommandPackage (Type 201)
|
|
88
|
-
|
|
89
|
-
Device control and automation commands for remote node management.
|
|
90
|
-
|
|
91
|
-
```cpp
|
|
92
|
-
class CommandPackage : public painlessmesh::plugin::SinglePackage {
|
|
93
|
-
public:
|
|
94
|
-
uint8_t command = 0; // Command type identifier
|
|
95
|
-
uint32_t targetDevice = 0; // Target node ID
|
|
96
|
-
uint32_t commandId = 0; // Unique command identifier
|
|
97
|
-
TSTRING parameters = ""; // JSON parameters string
|
|
98
|
-
|
|
99
|
-
// Constructors
|
|
100
|
-
CommandPackage();
|
|
101
|
-
CommandPackage(JsonObject jsonObj);
|
|
102
|
-
|
|
103
|
-
// Serialization
|
|
104
|
-
JsonObject addTo(JsonObject&& jsonObj) const;
|
|
105
|
-
size_t jsonObjectSize() const;
|
|
106
|
-
};
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
**Usage Example:**
|
|
110
|
-
```cpp
|
|
111
|
-
CommandPackage cmd;
|
|
112
|
-
cmd.dest = targetNodeId;
|
|
113
|
-
cmd.command = 1; // LED control
|
|
114
|
-
cmd.targetDevice = targetNodeId;
|
|
115
|
-
cmd.commandId = millis();
|
|
116
|
-
cmd.parameters = "{\"state\":\"ON\",\"brightness\":75}";
|
|
117
|
-
|
|
118
|
-
// Send to specific node
|
|
119
|
-
auto variant = painlessmesh::protocol::Variant(&cmd);
|
|
120
|
-
String message;
|
|
121
|
-
variant.printTo(message);
|
|
122
|
-
mesh.sendSingle(targetNodeId, message);
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
### StatusPackage (Type 202)
|
|
126
|
-
|
|
127
|
-
Health monitoring and system status reporting for network diagnostics.
|
|
128
|
-
|
|
129
|
-
```cpp
|
|
130
|
-
class StatusPackage : public painlessmesh::plugin::BroadcastPackage {
|
|
131
|
-
public:
|
|
132
|
-
uint8_t deviceStatus = 0; // Device status flags
|
|
133
|
-
uint32_t uptime = 0; // Uptime in seconds
|
|
134
|
-
uint16_t freeMemory = 0; // Free memory in KB
|
|
135
|
-
uint8_t wifiStrength = 0; // WiFi signal strength (0-100)
|
|
136
|
-
TSTRING firmwareVersion = ""; // Firmware version string
|
|
137
|
-
|
|
138
|
-
// Constructors
|
|
139
|
-
StatusPackage();
|
|
140
|
-
StatusPackage(JsonObject jsonObj);
|
|
141
|
-
|
|
142
|
-
// Serialization
|
|
143
|
-
JsonObject addTo(JsonObject&& jsonObj) const;
|
|
144
|
-
size_t jsonObjectSize() const;
|
|
145
|
-
};
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
**Usage Example:**
|
|
149
|
-
```cpp
|
|
150
|
-
StatusPackage status;
|
|
151
|
-
status.deviceStatus = 0x01; // Operational
|
|
152
|
-
status.uptime = millis() / 1000;
|
|
153
|
-
status.freeMemory = ESP.getFreeHeap() / 1024;
|
|
154
|
-
status.wifiStrength = 75;
|
|
155
|
-
status.firmwareVersion = "1.6.1-alteriom";
|
|
156
|
-
|
|
157
|
-
// Broadcast status
|
|
158
|
-
auto variant = painlessmesh::protocol::Variant(&status);
|
|
159
|
-
String message;
|
|
160
|
-
variant.printTo(message);
|
|
161
|
-
mesh.sendBroadcast(message);
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## Message Handling
|
|
165
|
-
|
|
166
|
-
### Receiving Messages
|
|
167
|
-
|
|
168
|
-
```cpp
|
|
169
|
-
void receivedCallback(uint32_t from, String& msg) {
|
|
170
|
-
DynamicJsonDocument doc(1024);
|
|
171
|
-
deserializeJson(doc, msg);
|
|
172
|
-
JsonObject obj = doc.as<JsonObject>();
|
|
173
|
-
uint8_t msgType = obj["type"];
|
|
174
|
-
|
|
175
|
-
switch(msgType) {
|
|
176
|
-
case 200: // SensorPackage
|
|
177
|
-
handleSensorData(alteriom::SensorPackage(obj), from);
|
|
178
|
-
break;
|
|
179
|
-
case 201: // CommandPackage
|
|
180
|
-
handleCommand(alteriom::CommandPackage(obj), from);
|
|
181
|
-
break;
|
|
182
|
-
case 202: // StatusPackage
|
|
183
|
-
handleStatus(alteriom::StatusPackage(obj), from);
|
|
184
|
-
break;
|
|
185
|
-
default:
|
|
186
|
-
Serial.printf("Unknown message type: %d\n", msgType);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### Debug Message Types
|
|
192
|
-
|
|
193
|
-
```cpp
|
|
194
|
-
// Debug levels (can be combined with |)
|
|
195
|
-
#define ERROR 0x00000001
|
|
196
|
-
#define STARTUP 0x00000002
|
|
197
|
-
#define CONNECTION 0x00000004
|
|
198
|
-
#define SYNC 0x00000008
|
|
199
|
-
#define COMMUNICATION 0x00000010
|
|
200
|
-
#define GENERAL 0x00000020
|
|
201
|
-
#define MSG_TYPES 0x00000040
|
|
202
|
-
#define REMOTE 0x00000080
|
|
203
|
-
|
|
204
|
-
// Usage
|
|
205
|
-
mesh.setDebugMsgTypes(ERROR | STARTUP | CONNECTION);
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
## Platform Constants
|
|
209
|
-
|
|
210
|
-
### Memory Constraints
|
|
211
|
-
- **ESP32**: ~320KB RAM available
|
|
212
|
-
- **ESP8266**: ~80KB RAM available
|
|
213
|
-
- **MAX_CONN**: Typically 4-10 connections depending on platform
|
|
214
|
-
|
|
215
|
-
### Network Limits
|
|
216
|
-
- **Message Size**: Recommended max 4KB
|
|
217
|
-
- **String Length**: Recommended max 256 characters for compatibility
|
|
218
|
-
- **Network Delay**: ~50-200ms typical mesh routing delay
|
|
219
|
-
|
|
220
|
-
## Error Handling
|
|
221
|
-
|
|
222
|
-
### Common Return Values
|
|
223
|
-
- **`true`**: Operation successful
|
|
224
|
-
- **`false`**: Operation failed (check network/memory)
|
|
225
|
-
|
|
226
|
-
### Best Practices
|
|
227
|
-
```cpp
|
|
228
|
-
// Always check return values
|
|
229
|
-
if (!mesh.sendBroadcast(message)) {
|
|
230
|
-
Serial.println("Failed to send message");
|
|
231
|
-
// Implement retry logic or error handling
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Monitor connection changes
|
|
235
|
-
void changedConnectionCallback() {
|
|
236
|
-
auto nodeList = mesh.getNodeList();
|
|
237
|
-
Serial.printf("Network size: %d nodes\n", nodeList.size() + 1);
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
## See Also
|
|
242
|
-
|
|
243
|
-
- [Installation Guide](Installation)
|
|
244
|
-
- [Examples](Examples)
|
|
245
|
-
- [GitHub Repository](https://github.com/Alteriom/painlessMesh)
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
This page contains the complete API reference for the Alteriom painlessMesh Library.
|
|
4
|
+
|
|
5
|
+
## Core Classes
|
|
6
|
+
|
|
7
|
+
### painlessMesh
|
|
8
|
+
|
|
9
|
+
The main class for creating and managing mesh networks.
|
|
10
|
+
|
|
11
|
+
#### Initialization Methods
|
|
12
|
+
|
|
13
|
+
```cpp
|
|
14
|
+
void init(String ssid, String password, Scheduler *baseScheduler, uint16_t port = 5555);
|
|
15
|
+
void setDebugMsgTypes(uint16_t types);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
#### Network Management
|
|
19
|
+
|
|
20
|
+
```cpp
|
|
21
|
+
void update(); // Call in loop()
|
|
22
|
+
bool sendBroadcast(String &msg); // Send to all nodes
|
|
23
|
+
bool sendSingle(uint32_t &destId, String &msg); // Send to specific node
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
#### Event Callbacks
|
|
27
|
+
|
|
28
|
+
```cpp
|
|
29
|
+
void onReceive(std::function<void(uint32_t from, String &msg)> cb);
|
|
30
|
+
void onNewConnection(std::function<void(uint32_t nodeId)> cb);
|
|
31
|
+
void onChangedConnections(std::function<void()> cb);
|
|
32
|
+
void onNodeTimeAdjusted(std::function<void(int32_t offset)> cb);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
#### Node Information
|
|
36
|
+
|
|
37
|
+
```cpp
|
|
38
|
+
uint32_t getNodeId(); // Get this node's ID
|
|
39
|
+
std::list<uint32_t> getNodeList(); // Get all connected nodes
|
|
40
|
+
uint32_t getNodeTime(); // Get synchronized time
|
|
41
|
+
size_t connectionCount(); // Number of direct connections
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Alteriom Extensions
|
|
45
|
+
|
|
46
|
+
### SensorPackage (Type 200)
|
|
47
|
+
|
|
48
|
+
Environmental data collection package for sensor networks.
|
|
49
|
+
|
|
50
|
+
```cpp
|
|
51
|
+
class SensorPackage : public painlessmesh::plugin::BroadcastPackage {
|
|
52
|
+
public:
|
|
53
|
+
uint32_t sensorId = 0; // Unique sensor identifier
|
|
54
|
+
uint32_t timestamp = 0; // Unix timestamp
|
|
55
|
+
double temperature = 0.0; // Temperature in Celsius
|
|
56
|
+
double humidity = 0.0; // Relative humidity (0-100%)
|
|
57
|
+
double pressure = 0.0; // Atmospheric pressure in hPa
|
|
58
|
+
uint8_t batteryLevel = 0; // Battery level (0-100%)
|
|
59
|
+
|
|
60
|
+
// Constructors
|
|
61
|
+
SensorPackage();
|
|
62
|
+
SensorPackage(JsonObject jsonObj);
|
|
63
|
+
|
|
64
|
+
// Serialization
|
|
65
|
+
JsonObject addTo(JsonObject&& jsonObj) const;
|
|
66
|
+
size_t jsonObjectSize() const;
|
|
67
|
+
};
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Usage Example:**
|
|
71
|
+
```cpp
|
|
72
|
+
SensorPackage sensor;
|
|
73
|
+
sensor.sensorId = mesh.getNodeId();
|
|
74
|
+
sensor.timestamp = mesh.getNodeTime();
|
|
75
|
+
sensor.temperature = 23.5;
|
|
76
|
+
sensor.humidity = 65.0;
|
|
77
|
+
sensor.pressure = 1013.25;
|
|
78
|
+
sensor.batteryLevel = 85;
|
|
79
|
+
|
|
80
|
+
// Send as broadcast
|
|
81
|
+
auto variant = painlessmesh::protocol::Variant(&sensor);
|
|
82
|
+
String message;
|
|
83
|
+
variant.printTo(message);
|
|
84
|
+
mesh.sendBroadcast(message);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### CommandPackage (Type 201)
|
|
88
|
+
|
|
89
|
+
Device control and automation commands for remote node management.
|
|
90
|
+
|
|
91
|
+
```cpp
|
|
92
|
+
class CommandPackage : public painlessmesh::plugin::SinglePackage {
|
|
93
|
+
public:
|
|
94
|
+
uint8_t command = 0; // Command type identifier
|
|
95
|
+
uint32_t targetDevice = 0; // Target node ID
|
|
96
|
+
uint32_t commandId = 0; // Unique command identifier
|
|
97
|
+
TSTRING parameters = ""; // JSON parameters string
|
|
98
|
+
|
|
99
|
+
// Constructors
|
|
100
|
+
CommandPackage();
|
|
101
|
+
CommandPackage(JsonObject jsonObj);
|
|
102
|
+
|
|
103
|
+
// Serialization
|
|
104
|
+
JsonObject addTo(JsonObject&& jsonObj) const;
|
|
105
|
+
size_t jsonObjectSize() const;
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Usage Example:**
|
|
110
|
+
```cpp
|
|
111
|
+
CommandPackage cmd;
|
|
112
|
+
cmd.dest = targetNodeId;
|
|
113
|
+
cmd.command = 1; // LED control
|
|
114
|
+
cmd.targetDevice = targetNodeId;
|
|
115
|
+
cmd.commandId = millis();
|
|
116
|
+
cmd.parameters = "{\"state\":\"ON\",\"brightness\":75}";
|
|
117
|
+
|
|
118
|
+
// Send to specific node
|
|
119
|
+
auto variant = painlessmesh::protocol::Variant(&cmd);
|
|
120
|
+
String message;
|
|
121
|
+
variant.printTo(message);
|
|
122
|
+
mesh.sendSingle(targetNodeId, message);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### StatusPackage (Type 202)
|
|
126
|
+
|
|
127
|
+
Health monitoring and system status reporting for network diagnostics.
|
|
128
|
+
|
|
129
|
+
```cpp
|
|
130
|
+
class StatusPackage : public painlessmesh::plugin::BroadcastPackage {
|
|
131
|
+
public:
|
|
132
|
+
uint8_t deviceStatus = 0; // Device status flags
|
|
133
|
+
uint32_t uptime = 0; // Uptime in seconds
|
|
134
|
+
uint16_t freeMemory = 0; // Free memory in KB
|
|
135
|
+
uint8_t wifiStrength = 0; // WiFi signal strength (0-100)
|
|
136
|
+
TSTRING firmwareVersion = ""; // Firmware version string
|
|
137
|
+
|
|
138
|
+
// Constructors
|
|
139
|
+
StatusPackage();
|
|
140
|
+
StatusPackage(JsonObject jsonObj);
|
|
141
|
+
|
|
142
|
+
// Serialization
|
|
143
|
+
JsonObject addTo(JsonObject&& jsonObj) const;
|
|
144
|
+
size_t jsonObjectSize() const;
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Usage Example:**
|
|
149
|
+
```cpp
|
|
150
|
+
StatusPackage status;
|
|
151
|
+
status.deviceStatus = 0x01; // Operational
|
|
152
|
+
status.uptime = millis() / 1000;
|
|
153
|
+
status.freeMemory = ESP.getFreeHeap() / 1024;
|
|
154
|
+
status.wifiStrength = 75;
|
|
155
|
+
status.firmwareVersion = "1.6.1-alteriom";
|
|
156
|
+
|
|
157
|
+
// Broadcast status
|
|
158
|
+
auto variant = painlessmesh::protocol::Variant(&status);
|
|
159
|
+
String message;
|
|
160
|
+
variant.printTo(message);
|
|
161
|
+
mesh.sendBroadcast(message);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Message Handling
|
|
165
|
+
|
|
166
|
+
### Receiving Messages
|
|
167
|
+
|
|
168
|
+
```cpp
|
|
169
|
+
void receivedCallback(uint32_t from, String& msg) {
|
|
170
|
+
DynamicJsonDocument doc(1024);
|
|
171
|
+
deserializeJson(doc, msg);
|
|
172
|
+
JsonObject obj = doc.as<JsonObject>();
|
|
173
|
+
uint8_t msgType = obj["type"];
|
|
174
|
+
|
|
175
|
+
switch(msgType) {
|
|
176
|
+
case 200: // SensorPackage
|
|
177
|
+
handleSensorData(alteriom::SensorPackage(obj), from);
|
|
178
|
+
break;
|
|
179
|
+
case 201: // CommandPackage
|
|
180
|
+
handleCommand(alteriom::CommandPackage(obj), from);
|
|
181
|
+
break;
|
|
182
|
+
case 202: // StatusPackage
|
|
183
|
+
handleStatus(alteriom::StatusPackage(obj), from);
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
Serial.printf("Unknown message type: %d\n", msgType);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Debug Message Types
|
|
192
|
+
|
|
193
|
+
```cpp
|
|
194
|
+
// Debug levels (can be combined with |)
|
|
195
|
+
#define ERROR 0x00000001
|
|
196
|
+
#define STARTUP 0x00000002
|
|
197
|
+
#define CONNECTION 0x00000004
|
|
198
|
+
#define SYNC 0x00000008
|
|
199
|
+
#define COMMUNICATION 0x00000010
|
|
200
|
+
#define GENERAL 0x00000020
|
|
201
|
+
#define MSG_TYPES 0x00000040
|
|
202
|
+
#define REMOTE 0x00000080
|
|
203
|
+
|
|
204
|
+
// Usage
|
|
205
|
+
mesh.setDebugMsgTypes(ERROR | STARTUP | CONNECTION);
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Platform Constants
|
|
209
|
+
|
|
210
|
+
### Memory Constraints
|
|
211
|
+
- **ESP32**: ~320KB RAM available
|
|
212
|
+
- **ESP8266**: ~80KB RAM available
|
|
213
|
+
- **MAX_CONN**: Typically 4-10 connections depending on platform
|
|
214
|
+
|
|
215
|
+
### Network Limits
|
|
216
|
+
- **Message Size**: Recommended max 4KB
|
|
217
|
+
- **String Length**: Recommended max 256 characters for compatibility
|
|
218
|
+
- **Network Delay**: ~50-200ms typical mesh routing delay
|
|
219
|
+
|
|
220
|
+
## Error Handling
|
|
221
|
+
|
|
222
|
+
### Common Return Values
|
|
223
|
+
- **`true`**: Operation successful
|
|
224
|
+
- **`false`**: Operation failed (check network/memory)
|
|
225
|
+
|
|
226
|
+
### Best Practices
|
|
227
|
+
```cpp
|
|
228
|
+
// Always check return values
|
|
229
|
+
if (!mesh.sendBroadcast(message)) {
|
|
230
|
+
Serial.println("Failed to send message");
|
|
231
|
+
// Implement retry logic or error handling
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Monitor connection changes
|
|
235
|
+
void changedConnectionCallback() {
|
|
236
|
+
auto nodeList = mesh.getNodeList();
|
|
237
|
+
Serial.printf("Network size: %d nodes\n", nodeList.size() + 1);
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## See Also
|
|
242
|
+
|
|
243
|
+
- [Installation Guide](Installation)
|
|
244
|
+
- [Examples](Examples)
|
|
245
|
+
- [GitHub Repository](https://github.com/Alteriom/painlessMesh)
|
|
246
246
|
- [Release Notes](https://github.com/Alteriom/painlessMesh/releases)
|