From d229e35b423d1c3bc7f0e2b2954b64197ea8b03a Mon Sep 17 00:00:00 2001 From: Piyush Shah Date: Thu, 17 Feb 2022 14:34:46 +0530 Subject: [PATCH] esp_rmaker_core: Expose esp_rmaker_param_update() API to assist in multi param updates --- .../esp_rainmaker/include/esp_rmaker_core.h | 24 +++++++++++++++++++ .../esp_rainmaker/src/core/esp_rmaker_param.c | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/components/esp_rainmaker/include/esp_rmaker_core.h b/components/esp_rainmaker/include/esp_rmaker_core.h index 45b462e..6ddb0fb 100644 --- a/components/esp_rainmaker/include/esp_rmaker_core.h +++ b/components/esp_rainmaker/include/esp_rmaker_core.h @@ -731,6 +731,30 @@ esp_err_t esp_rmaker_param_add_valid_str_list(const esp_rmaker_param_t *param, c */ esp_err_t esp_rmaker_param_add_array_max_count(const esp_rmaker_param_t *param, int count); + +/* Update a parameter + * + * This will just update the value of a parameter with esp rainmaker core, without actually reporting + * it. This can be used when multiple parameters need to be reported together. + * Eg. If x parameters are to be reported, this API can be used for the first x -1 parameters + * and the last one can be updated using esp_rmaker_param_update_and_report(). + * This will report all parameters which were updated prior to this call. + * + * Sample: + * + * esp_rmaker_param_update(param1, esp_rmaker_float(10.2)); + * esp_rmaker_param_update(param2, esp_rmaker_int(55)); + * esp_rmaker_param_update(param3, esp_rmaker_int(95)); + * esp_rmaker_param_update_and_report(param1, esp_rmaker_bool(true)); + * + * @param[in] param Parameter handle. + * @param[in] val New value of the parameter. + * + * @return ESP_OK if the parameter was updated successfully. + * @return error in case of failure. + */ +esp_err_t esp_rmaker_param_update(const esp_rmaker_param_t *param, esp_rmaker_param_val_t val); + /** Update and report a parameter * * Calling this API will update the parameter and report it to ESP RainMaker cloud. diff --git a/components/esp_rainmaker/src/core/esp_rmaker_param.c b/components/esp_rainmaker/src/core/esp_rmaker_param.c index 0ffcfa6..d7991e6 100644 --- a/components/esp_rainmaker/src/core/esp_rmaker_param.c +++ b/components/esp_rainmaker/src/core/esp_rmaker_param.c @@ -701,6 +701,7 @@ esp_err_t esp_rmaker_param_update(const esp_rmaker_param_t *param, esp_rmaker_pa default: return ESP_ERR_INVALID_ARG; } + _param->flags |= RMAKER_PARAM_FLAG_VALUE_CHANGE; if (_param->prop_flags & PROP_FLAG_PERSIST) { esp_rmaker_param_store_value(_param); } @@ -713,7 +714,6 @@ esp_err_t esp_rmaker_param_report(const esp_rmaker_param_t *param) ESP_LOGE(TAG, "Param handle cannot be NULL."); return ESP_ERR_INVALID_ARG; } - ((_esp_rmaker_param_t *)param)->flags |= RMAKER_PARAM_FLAG_VALUE_CHANGE; return esp_rmaker_report_param_internal(RMAKER_PARAM_FLAG_VALUE_CHANGE); }