diff -r 1599e696d947 -r 12506716211c main/task_mqtt.c --- a/main/task_mqtt.c Thu Apr 06 13:22:03 2023 +0200 +++ b/main/task_mqtt.c Thu Apr 06 20:49:52 2023 +0200 @@ -243,7 +243,6 @@ static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event) { char *topic = NULL; - nvs_handle_t my_handle; switch (event->event_id) { @@ -287,7 +286,6 @@ case MQTT_EVENT_DATA: ESP_LOGI(TAG, "MQTT_EVENT_DATA len=%d", event->data_len); bool gotit = false; - esp_err_t err; char data[65]; if (event->data_len < 65) snprintf(data, 64, "%.*s", event->data_len, event->data); @@ -299,15 +297,8 @@ if (strncmp(topic, event->topic, event->topic_len) == 0) { ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); gotit = true; - if ((uint8_t)atoi(data) != Relay1) { - Relay1 = (uint8_t)atoi(data); - err = nvs_open("balkon", NVS_READWRITE, &my_handle); - if (err == ESP_OK) { - nvs_set_u8(my_handle, (char *)"out1", Relay1); - nvs_commit(my_handle); - nvs_close(my_handle); - } - } + Relay1 = (uint8_t)atoi(data); + nvsio_write_u8((char *)"out1", Relay1); } free(topic); topic = NULL; @@ -317,15 +308,8 @@ if (strncmp(topic, event->topic, event->topic_len) == 0) { ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); gotit = true; - if ((uint8_t)atoi(data) != Relay2) { - Relay2 = (uint8_t)atoi(data); - err = nvs_open("balkon", NVS_READWRITE, &my_handle); - if (err == ESP_OK) { - nvs_set_u8(my_handle, (char *)"out2", Relay2); - nvs_commit(my_handle); - nvs_close(my_handle); - } - } + Relay2 = (uint8_t)atoi(data); + nvsio_write_u8((char *)"out2", Relay2); } free(topic); topic = NULL; @@ -335,15 +319,8 @@ if (strncmp(topic, event->topic, event->topic_len) == 0) { ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); gotit = true; - if ((uint8_t)atoi(data) != Dimmer3) { - Dimmer3 = (uint8_t)atoi(data); - err = nvs_open("balkon", NVS_READWRITE, &my_handle); - if (err == ESP_OK) { - nvs_set_u8(my_handle, (char *)"out3", Dimmer3); - nvs_commit(my_handle); - nvs_close(my_handle); - } - } + Dimmer3 = (uint8_t)atoi(data); + nvsio_write_u8((char *)"out3", Dimmer3); } free(topic); topic = NULL; @@ -353,15 +330,8 @@ if (strncmp(topic, event->topic, event->topic_len) == 0) { ESP_LOGI(TAG, "Got %s `%s' %d", topic, data, atoi(data)); gotit = true; - if ((uint8_t)atoi(data) != Dimmer4) { - Dimmer4 = (uint8_t)atoi(data); - err = nvs_open("balkon", NVS_READWRITE, &my_handle); - if (err == ESP_OK) { - nvs_set_u8(my_handle, (char *)"out4", Dimmer4); - nvs_commit(my_handle); - nvs_close(my_handle); - } - } + Dimmer4 = (uint8_t)atoi(data); + nvsio_write_u8((char *)"out4", Dimmer4); } free(topic); topic = NULL;