Need help with node configuration

vdj699999
Posts: 1
Joined: Mon Mar 15, 2021 4:05 pm

Need help with node configuration

Postby vdj699999 » Mon Mar 15, 2021 4:18 pm

I have read the node config document(https://rainmaker.espressif.com/docs/no ... -comm.html) but not get much clarity, please help:
1. Where the Node Configuration is created(Esp/server/app)?
2. Where the Node Configuration is stored(Esp/server/app)?
3. Who creates the Node Configuration(Esp/server/app)?
4. How it's used it's used Esp, server, and app?

ESP_Piyush
Posts: 259
Joined: Wed Feb 20, 2019 7:02 am

Re: Need help with node configuration

Postby ESP_Piyush » Tue Mar 16, 2021 5:41 am

1. Node configuration is created on the ESP device side. It uses the database that is created using the various APIs like esp_rmaker_node_init(), esp_rmaker_device_create(), esp_rmaker_node_add_device(), etc. and converts it to JSON before sending to the cloud service on the node/<node_id>/config MQTT topic. For example, if you just call esp_rmaker_node_init(), it will create node config like this:

Code: Select all

{
    "node_id": "xxxxxxxxxx",
    "config_version": "2020-03-20",
    "info": {
        "fw_version": "1.0",
        "model": "switch",
        "name": "ESP RainMaker Device",
        "type": "Switch"
    }
}
If you add a standard switch device to it, it will change to

Code: Select all

{
    "node_id": "xxxxxxxxxx",
    "config_version": "2020-03-20",
    "info": {
        "fw_version": "1.0",
        "model": "switch",
        "name": "ESP RainMaker Device",
        "type": "Switch"
    },
    "devices": [
        {
            "name": "Switch",
            "params": [
                {
                    "data_type": "string",
                    "name": "Name",
                    "properties": [
                        "read",
                        "write"
                    ],
                    "type": "esp.param.name"
                },
                {
                    "data_type": "bool",
                    "name": "Power",
                    "properties": [
                        "read",
                        "write"
                    ],
                    "type": "esp.param.power",
                    "ui_type": "esp.ui.toggle"
                }
            ],
            "primary": "Power",
            "type": "esp.device.switch"
        }
    ]
}
2. When the node configuration is reported to the cloud, the cloud backend maintains a copy of it in database. The phone apps can then fetch this via the REST APIs /user/nodes?node_details=true or /user/nodes/config API. They normally fetch this every time you visit the home page. Note that node configuration is read-only. The actual transient values are get/set via other topics and REST APIs.

3. As explained in point 1, the node database is created by a user using the C APIs, which is then converted to JSON by the RainMaker core component and then sent to the cloud over MQTT.

4. The node uses the configuration to tell the clients (phone apps) about its capabilities, the devices and services it has and various parameters and metadata associated with them. The cloud backend does not do much with this data, apart from storing it. It does however record the values passed in the "info" object and makes it available to admin users on the dashboard.

The phone apps are the primary consumers of this node config and use that to render the UI associated with the node. Along with the node config, they also use the actual transient values of node params, a sample for which is as below:

Code: Select all

{
   "Switch": {
        "Name": "AC Switch",
        "Power": true
    }
}
For the switch example above, the phone app will show one Switch device on the home screen, with the name as "AC Switch", and the value of "Power" shown on the tile since it is reported as the primary parameter. Once you click on the tile, it will show the params control screen which will have the 2 parameters, Name and Power, one being an editable text and another being a boolean toggle button, as described in the node config.

I hope this makes it clear enough.

Who is online

Users browsing this forum: No registered users and 39 guests