System Service Usage Guide
Firmware Usage Guide
System service is designed for operations like reboot, Wi-Fi reset, and factory reset via phone apps.
To know more about this feature, please click here.
Usage Guide
The service can be added using the following snippet before the esp_rmaker_start()
function:
esp_rmaker_system_serv_config_t system_serv_config = {
.flags = SYSTEM_SERV_FLAGS_ALL,
.reboot_seconds = 2,
.reset_seconds = 2,
.reset_reboot_seconds = 2
};
esp_rmaker_system_service_enable(&system_serv_config);
Configuring System Service
The system service can be configured by setting the following values in system_serv_config
:
flags
- The parameters to be included are chosen using OR of flag values:
SYSTEM_SERV_FLAG_REBOOT
,SYSTEM_SERV_FLAG_FACTORY_RESET
, andSYSTEM_SERV_FLAG_WIFI_RESET
.
reboot_seconds
- Time in seconds after which the device should reboot. A value of zero would trigger an immediate reboot if a write operation is received for the Reboot parameter.
Recommended value: 2.
reset_seconds
- Time in seconds after which the device should reset (Wi-Fi or factory). A value of zero would trigger an immediate action if a write operation is received for the Wi-Fi reset or factory reset parameter.
Recommended value: 2
reset_reboot_seconds
- Time in seconds after which the device should reboot after it has been reset. A value of zero would mean that there will not be any reboot after the reset.
Recommended value: 2
With the above calls, the following service gets added to the node configuration as follows:
JSON Payload (Click to view)
{
"name": "System",
"type": "esp.service.system",
"params": [{
"name": "Reboot",
"type": "esp.param.reboot",
"data_type": "bool",
"properties": ["read", "write"]
}, {
"name": "Factory-Reset",
"type": "esp.param.factory-reset",
"data_type": "bool",
"properties": ["read", "write"]
}, {
"name": "Wi-Fi-Reset",
"type": "esp.param.wifi-reset",
"data_type": "bool",
"properties": ["read", "write"]
}]
}
These parameters will show up on the client side as following:
JSON Payload (Click to view)
{
"System": {
"Reboot": false,
"Factory-Reset": false,
"Wi-Fi-Reset": false
}
}
Using System Service from Clients
Writing true to any of these would trigger the corresponding action. For example, {"System":{"Factory-Reset":true}}
will trigger a factory reset.
Events
Whenever any of the reboot/reset is triggered, event notifications are generated to indicate the application code about the operation. Here are the various events generated:
RMAKER_EVENT_REBOOT
Node reboot has been triggered. The associated event data is the time in seconds (type: uint8_t) after which the node will reboot. Note that this time may not be accurate as the events are received asynchronously.
RMAKER_EVENT_WIFI_RESET
Wi-Fi credentials reset. Triggered after calling esp_rmaker_wifi_reset()
or the corresponding system service call.
RMAKER_EVENT_FACTORY_RESET
Node reset to factory defaults. Triggered after calling esp_rmaker_factory_reset()
or the corresponding system service call.