Skip to content

Commit

Permalink
Merge branch 'bugfix/cmd-resp' into 'master'
Browse files Browse the repository at this point in the history
Bugfix: Command-Response topic subscription was happening multiple times

See merge request app-frameworks/esp-rainmaker!487
  • Loading branch information
shahpiyushv committed Oct 28, 2024
2 parents f98cf1e + e05a72d commit b3357fe
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion components/esp_rainmaker/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## IDF Component Manager Manifest File
version: "1.5.0"
version: "1.5.1"
description: ESP RainMaker firmware agent
url: https://github.com/espressif/esp-rainmaker/tree/master/components/esp_rainmaker
repository: https://github.com/espressif/esp-rainmaker.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ extern "C"
*/
esp_rmaker_device_t *esp_rmaker_ota_service_create(const char *serv_name, void *priv_data);

/** Create a standard OTA service
/** Create a standard Time service
*
* This creates an OTA service with the mandatory parameters. The default parameter names will be used.
* This creates a Time service with the mandatory parameters. The default parameter names will be used.
* Refer \ref esp_rmaker_standard_params.h for default names.
*
* @param[in] serv_name The unique service name
Expand Down
18 changes: 13 additions & 5 deletions components/esp_rainmaker/src/core/esp_rmaker_cmd_resp_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,24 @@ static void esp_rmaker_cmd_callback(const char *topic, void *payload, size_t pay
}
}

/* Keeping the variable outside the function as there would subsequently also be a function
* to disable command response.
*/
static bool cmd_resp_topic_subscribed = false;
static esp_err_t esp_rmaker_cmd_resp_check_pending(void)
{
ESP_LOGI(TAG, "Checking for pending commands.");
char subscribe_topic[100];
snprintf(subscribe_topic, sizeof(subscribe_topic), "node/%s/%s",
esp_rmaker_get_node_id(), TO_NODE_TOPIC_SUFFIX);
esp_err_t err = esp_rmaker_mqtt_subscribe(subscribe_topic, esp_rmaker_cmd_callback, RMAKER_MQTT_QOS1, NULL);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to subscribe to %s. Error %d", subscribe_topic, err);
return ESP_FAIL;
esp_rmaker_get_node_id(), TO_NODE_TOPIC_SUFFIX);
if (!cmd_resp_topic_subscribed) {
/* Subscribing just once because any subsequent reconnect will automatically subscribe to the topic */
esp_err_t err = esp_rmaker_mqtt_subscribe(subscribe_topic, esp_rmaker_cmd_callback, RMAKER_MQTT_QOS1, NULL);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to subscribe to %s. Error %d", subscribe_topic, err);
return ESP_FAIL;
}
cmd_resp_topic_subscribed = true;
}
void *output = NULL;
size_t output_len = 0;
Expand Down
2 changes: 1 addition & 1 deletion components/esp_rainmaker/src/mqtt/esp_rmaker_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ esp_err_t esp_rmaker_mqtt_init(esp_rmaker_mqtt_conn_params_t *conn_params)
esp_err_t err = g_mqtt_config.init(conn_params);
if (err == ESP_OK) {
if (esp_rmaker_mqtt_budgeting_init() != ESP_OK) {
ESP_LOGE(TAG, "Failied to initialise MQTT Budgeting.");
ESP_LOGE(TAG, "Failed to initialise MQTT Budgeting.");
}
}
return err;
Expand Down
2 changes: 1 addition & 1 deletion components/esp_rainmaker/src/mqtt/esp_rmaker_mqtt_budget.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ esp_err_t esp_rmaker_mqtt_budgeting_init(void)
* to be invoked since it is called from MQTT init. Else, MQTT itself is going to fail.
*/
ESP_LOGW(TAG, "MQTT Budgeting is not enabled.");
return ESP_FAIL;
return ESP_OK;
}

esp_err_t esp_rmaker_mqtt_budgeting_deinit(void)
Expand Down
2 changes: 1 addition & 1 deletion examples/common/app_network/app_wifi_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#endif

#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI
static const char* TAG = "app_thread";
static const char* TAG = "app_wifi";
/* Event handler for catching system events */
static void event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
Expand Down

0 comments on commit b3357fe

Please sign in to comment.