diff -r e33f2d325d15 -r 7dc9003f86a8 main/task_mqtt.c --- a/main/task_mqtt.c Sun Oct 13 12:24:14 2019 +0200 +++ b/main/task_mqtt.c Sun Oct 13 19:27:12 2019 +0200 @@ -86,18 +86,21 @@ void publisher(char *topic, char *payload) { - // publish the data + /* + * First count, then sent the data. + */ + if (xSemaphoreTake(xSemaphorePcounter, 10) == pdTRUE) { + count_pub++; +printf(" up %d\n", count_pub); + xSemaphoreGive(xSemaphorePcounter); + } else { + ESP_LOGE(TAG, "Missed lock 1"); + } + if (payload) esp_mqtt_client_publish(client, topic, payload, strlen(payload), 1, 0); else esp_mqtt_client_publish(client, topic, NULL, 0, 1, 0); - if (xSemaphoreTake(xSemaphorePcounter, 10) == pdTRUE) { - count_pub++; -printf(" up %d\n", count_pub); - xSemaphoreGive(xSemaphorePcounter); - } else { - ESP_LOGE(TAG, "Missed lock 1"); - } }