From 12fd24f3eb906929cbd248fbbb2251f348e1fd8a Mon Sep 17 00:00:00 2001 From: Piyush Shah Date: Wed, 7 Oct 2020 17:39:41 +0530 Subject: [PATCH] bugfix: Callback for persistent parameters wasn't getting invoked The RainMaker core has special handling for the "name" type of parameter and so, it does not call the application registered callback for this parameter. However, the internal check was erroneous and the callback was getting skipped even when the param type was NULL. The check has now been fixed. --- .../esp_rainmaker/src/core/esp_rmaker_device.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/components/esp_rainmaker/src/core/esp_rmaker_device.c b/components/esp_rainmaker/src/core/esp_rmaker_device.c index cfbc62d..729a30c 100644 --- a/components/esp_rainmaker/src/core/esp_rmaker_device.c +++ b/components/esp_rainmaker/src/core/esp_rmaker_device.c @@ -136,11 +136,19 @@ esp_err_t esp_rmaker_device_add_param(const esp_rmaker_device_t *device, const e } } _new_param->val = stored_val; - if (_device->write_cb && (_new_param->type && strcmp(_new_param->type, ESP_RMAKER_PARAM_NAME) != 0)) { - esp_rmaker_write_ctx_t ctx = { - .src = ESP_RMAKER_REQ_SRC_INIT, - }; - _device->write_cb(device, param, stored_val, _device->priv_data, &ctx); + /* The device callback should be invoked once with the stored value, so + * that applications can do initialisations as required. + */ + if (_device->write_cb) { + /* However, the callback should be invoked, only if the parameter is not + * of type ESP_RMAKER_PARAM_NAME, as it has special handling internally. + */ + if (!(_new_param->type && strcmp(_new_param->type, ESP_RMAKER_PARAM_NAME) == 0)) { + esp_rmaker_write_ctx_t ctx = { + .src = ESP_RMAKER_REQ_SRC_INIT, + }; + _device->write_cb(device, param, stored_val, _device->priv_data, &ctx); + } } } else { esp_rmaker_param_store_value(_new_param);