System Service
System service is meant for operations like reboot, Wi-Fi reset and Factory reset from phone apps. The service can be added using code like this before esp_rmaker_start()
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 these values in system_serv_config:
- flags: The params to be included are chosen using OR of flag values
SYSTEM_SERV_FLAG_REBOOT
,SYSTEM_SERV_FLAG_FACTORY_RESET
andSYSTEM_SERV_FLAG_WIFI_RESET
.SYSTEM_SERV_FLAGS_ALL
will include all params. - reboot_seconds: Time in seconds after which the device should reboot. Value of zero would trigger an immediate reboot if a write is received for the Reboot parameter. Recommended value: 2.
- reset_seconds: Time in seconds after which the device should reset (Wi-Fi or factory). Value of zero would trigger an immediate action if a write 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. Value of zero would mean that there won't be any reboot after the reset. Recommended value: 2.
With the above call, the following service gets added to the node configuration:
{
"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"]
}]
}
The params show up like this
{
"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.
Eg. {"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.