Node to Cloud Communication
This page outlines how nodes securely interact with the cloud using MQTT over TLS. Each node possesses a unique identifier and credentials established during the claiming process, ensuring secure, authenticated communication. The node configuration, detailing attributes like devices and parameters, is sent to the cloud upon startup, enabling clients such as mobile apps to interpret and utilize this data. Understanding this communication framework is essential for developers to effectively integrate and manage IoT devices within the ESP RainMaker ecosystem.
All communication between the node and cloud occurs over secure MQTT.
How Does a Node Ensure Secure Communication With the Cloud?
A node ensures secure communication with the cloud by providing:
- Transport Layer Security (TLS)
- MQTT Policies
TLS
The communication between a node and the cloud is secured using TLS encryption with X.509 certificate-based mutual authentication, ensuring only trusted devices can connect.
A generic workflow to establish secure communication:
- The node first generates its own private key and then creates a Certificate Signing Request (CSR), which is like applying for an official ID.
- This request is sent to a Certification Authority (CA), which verifies it, signs it, and returns a client certificate—essentially an authenticated ID badge.
- During the Claiming process, the node receives this certificate, allowing it to establish a secure, encrypted connection with the cloud.
- Before any data exchange, both the node and the cloud verify each other's certificates to confirm they are communicating with the correct entity.
- This ensures privacy, security, and protection against unauthorized access, preventing fake or malicious devices from infiltrating the system.
- Ensures that only trusted nodes can connect to the cloud.
- Prevents hackers or fake devices from impersonating real nodes.
- Keeps all communication private and secure.
MQTT Policies
The MQTT policy ensures that a node can only connect to the cloud if its client ID matches its node ID, preventing unauthorized access. Additionally, the node is restricted to publishing and subscribing only to topics that start with node/<node_id>/
, meaning it cannot access topics from other nodes.
For example, if a node has an ID of 1234, it can only interact with topics like node/1234/status
or node/1234/command
, but it cannot subscribe to node/5678/status
.
This policy acts as a security mechanism to keep each node's communication isolated and protected, ensuring that data remains private and that nodes cannot interfere with each other.
Summary
Security Aspect | Description |
---|---|
TLS | Secures the communication channel so that no one can eavesdrop or tamper with messages. |
MQTT Policies | Defines rules on what a node is allowed to communicate within the secured channel. |
MQTT Topics What Is an MQTT Topic?
In ESP RainMaker, an MQTT topic acts as a communication path where a node publishes (sends) updates and subscribes (receives) commands or configurations. Here are the different types of MQTT topics in ESP RainMaker.
- Node Configuration
- Node Parameters
- User-Node Mapping
- Time-Series
- Alert and Notify
- Command Response
- OTA
Node Configuration
In ESP RainMaker, node configuration is a collection of all the information about a node (e.g., ESP32-S3). When the node starts up, it sends this configuration to the ESP RainMaker Cloud and also reports it to clients, such as mobile apps and command-line interfaces (CLI). This configuration contains everything needed to define the node's identity, features, and capabilities.
Below is the node configuration layout that ESP RainMaker firmware and phone apps currently use in the order from top to bottom.
Node Configuration Layout (Toggle View)
- Boxes in RED are mandatory entries in a node configuration.
- Boxes in GREEN are mandatory parameters of an entry.
- The strings below each entry indicate the corresponding key (JSON representation, Data type).
1. Node ID
2. Config Version
2. Information
3. Node Attributes
4. Devices & Params
MQTT
- Topic:
node/<node_id>/config
- Operation:
PUBLISH
- Data:
Node configuration JSON object described below
JSON Payload (Toggle View)
{
"node_id": "5d898491-a498-48ec-9476-a4e23519fe31",
"config_version": "2019-02-27",
"info": {
"name": "My_Bridge",
"fw_version": "1.0",
"type": "Bridge"
},
"attributes": [{
"name": "serial_num",
"value": "123abc"
}, {
"name": "model",
"value": "myBridge-2019"
}],
"devices": [{
"name": "Switch",
"primary": "power",
"params": [{
"name": "name",
"type": "esp.param.name",
"data_type": "string",
"properties": ["read", "write"]
}, {
"name": "power",
"data_type": "bool",
"properties": ["read", "write", "time_series"],
"ui_type": "esp.ui.toggle"
}]
}, {
"name": "Light",
"type": "esp.device.lightbulb",
"attributes": [{
"name": "serial_number",
"value": "012345"
}, {
"name": "mac",
"value": "xx:yy:zz:aa:bb:cc"
}],
"primary": "power",
"params": [{
"name": "name",
"type": "esp.param.name",
"data_type": "string",
"properties": ["read", "write"]
}, {
"name": "power",
"data_type": "bool",
"properties": ["read", "write", "time_series"],
"ui_type": "esp.ui.toggle"
}, {
"name": "brightness",
"data_type": "int",
"properties": ["read", "write"],
"bounds": {
"min": 0,
"max": 100
},
"ui_type": "esp.ui.slider"
}]
}]
}
By default, the device reports once after powering on and connecting to the cloud. It will also report when esp_rmaker_report_node_details
is called.
Firmware API: esp_rmaker_report_node_details()
Node Parameters
All parameter changes are managed through specific node parameter topics.
Initial Reporting
Initial reporting is done every time the node boots up. Values of all the parameters of all the devices are reported in this.
MQTT
- Topic:
node/<node_id>/params/local/init
- Operation:
PUBLISH
- Data:
{"<device-name">:{"<param-name>":<value>,...},...}
JSON Payload (Toggle View)
{
"Lightbulb": {
"name": "Bedroom Light",
"power": true,
"brightness": 55
}
}
When the node powers on for the first time and connects to the cloud, it will report the current values of all parameters.
The node can also call the esp_rmaker_report_node_state
API to report all parameter values.
Firmware API: esp_rmaker_report_node_state()