|
AlteriomPainlessMesh v2.1.1
Easy ESP32/ESP8266 mesh networking with Alteriom IoT extensions
|
Gateway Data Package for routing Internet requests through mesh. More...
#include <gateway.hpp>


Public Member Functions | |
| GatewayDataPackage () | |
| Default constructor. | |
| GatewayDataPackage (JsonObject jsonObj) | |
| Construct from JSON object. | |
| JsonObject | addTo (JsonObject &&jsonObj) const |
| Serialize to JSON object. | |
| size_t | jsonObjectSize () const |
| Calculate JSON object size for ArduinoJson v6. | |
Public Member Functions inherited from painlessmesh::plugin::SinglePackage | |
| SinglePackage (int type) | |
| SinglePackage (JsonObject jsonObj) | |
| JsonObject | addTo (JsonObject &&jsonObj) const |
Public Member Functions inherited from painlessmesh::protocol::PackageInterface | |
| virtual | ~PackageInterface ()=default |
Static Public Member Functions | |
| static uint32_t | generateMessageId (uint32_t nodeId) |
| Generate a unique message ID. | |
Public Attributes | |
| uint32_t | messageId = 0 |
| Unique message identifier. | |
| uint32_t | originNode = 0 |
| Node ID that originated this message. | |
| uint32_t | timestamp = 0 |
| Creation timestamp. | |
| uint8_t | priority = static_cast<uint8_t>(GatewayPriority::PRIORITY_NORMAL) |
| Message priority (0=CRITICAL, 1=HIGH, 2=NORMAL, 3=LOW) | |
| TSTRING | destination = "" |
| Destination URL or endpoint. | |
| TSTRING | payload = "" |
| Application payload data. | |
| TSTRING | contentType = "application/json" |
| MIME content type. | |
| uint8_t | retryCount = 0 |
| Number of relay attempts. | |
| bool | requiresAck = false |
| Whether acknowledgment is required. | |
| uint32_t | requestNonce = 0 |
| Random value drawn once per sendToInternet() call. | |
Public Attributes inherited from painlessmesh::plugin::SinglePackage | |
| uint32_t | from = 0 |
| uint32_t | dest = 0 |
| router::Type | routing = router::SINGLE |
| int | type = 0 |
| int | noJsonFields = 4 |
Static Public Attributes | |
| static constexpr int | numPackageFields = 10 |
| Number of additional JSON fields in this package. | |
Gateway Data Package for routing Internet requests through mesh.
This package enables mesh nodes to send data through a gateway node to the Internet. It provides a standardized format for:
The GatewayDataPackage structure has an estimated memory footprint of:
For ESP8266 with ~80KB RAM, keep payload under 1KB for safety. For ESP32 with ~320KB RAM, larger payloads are acceptable.
Use generateMessageId(nodeId) to create unique message IDs. The ID combines a per-node counter with the node ID to ensure uniqueness across the mesh network.
Example usage:
Type ID: 620 (GATEWAY_DATA) Base class: SinglePackage (routed to specific gateway node)
|
inline |
Default constructor.
Creates a GatewayDataPackage with type ID 620 (GATEWAY_DATA).
|
inline |
Construct from JSON object.
Deserializes a GatewayDataPackage from a JSON object. Compatible with ArduinoJson v6 and v7.
| jsonObj | JSON object containing package data |
|
inlinevirtual |
Serialize to JSON object.
Adds all package fields to the provided JSON object.
| jsonObj | JSON object to add fields to |
Implements painlessmesh::protocol::PackageInterface.
|
inlinestatic |
Generate a unique message ID.
Creates a unique message ID by combining a per-node counter with the node ID. This ensures uniqueness across the mesh even if multiple nodes generate IDs simultaneously.
The ID format is:
| nodeId | The ID of the node generating the message |
|
inlinevirtual |
Calculate JSON object size for ArduinoJson v6.
Used for buffer allocation when serializing.
Implements painlessmesh::protocol::PackageInterface.
| TSTRING painlessmesh::gateway::GatewayDataPackage::contentType = "application/json" |
MIME content type.
Describes the format of the payload. Common values:
| TSTRING painlessmesh::gateway::GatewayDataPackage::destination = "" |
Destination URL or endpoint.
The Internet destination for this data. Examples:
| uint32_t painlessmesh::gateway::GatewayDataPackage::messageId = 0 |
Unique message identifier.
Generated using generateMessageId() to ensure uniqueness across the mesh. Used for tracking, acknowledgment, and deduplication.
|
staticconstexpr |
Number of additional JSON fields in this package.
Used for jsonObjectSize() calculation in ArduinoJson v6. Count: msgId, origin, ts, prio, dest_url, payload, content, retry, ack, nonce = 10 fields
| uint32_t painlessmesh::gateway::GatewayDataPackage::originNode = 0 |
Node ID that originated this message.
The node that created the message, which may differ from the 'from' field during relay operations.
| TSTRING painlessmesh::gateway::GatewayDataPackage::payload = "" |
Application payload data.
The actual data to send to the destination. Format depends on contentType (JSON, binary, etc.).
| uint8_t painlessmesh::gateway::GatewayDataPackage::priority = static_cast<uint8_t>(GatewayPriority::PRIORITY_NORMAL) |
Message priority (0=CRITICAL, 1=HIGH, 2=NORMAL, 3=LOW)
Determines processing order at the gateway. Use GatewayPriority enum for type-safe values.
| uint32_t painlessmesh::gateway::GatewayDataPackage::requestNonce = 0 |
Random value drawn once per sendToInternet() call.
The same on every attempt at that call, and part of its X-Request-Id and Idempotency-Key (requestIdFor()). messageId alone repeats: its counter is 16 bits, so a node that sends more than 65,535 requests in one boot reissues old ids, and a service that remembers keys would drop the new request as a repeat. 0 from a node that predates the field. JSON key "nonce", omitted when 0.
| bool painlessmesh::gateway::GatewayDataPackage::requiresAck = false |
Whether acknowledgment is required.
When true, the gateway should send a response back confirming successful delivery to the Internet destination.
| uint8_t painlessmesh::gateway::GatewayDataPackage::retryCount = 0 |
Number of relay attempts.
Incremented each time the message is relayed. Can be used for hop counting and loop detection.
| uint32_t painlessmesh::gateway::GatewayDataPackage::timestamp = 0 |
Creation timestamp.
Mesh time when the message was created. Used for TTL calculations and ordering.