From 9b21c54fc5ef8f111f2521672ba142146ffffb9a Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Sat, 28 May 2016 16:21:53 +1000 Subject: [PATCH] MQTTClient select timeout cleanup (closes #123) Also sets example task priorities to maximum 2, as higher priorities seem to mess with the network stack. --- examples/mqtt_client/mqtt_client.c | 4 ++-- extras/paho_mqtt_c/MQTTESP8266.c | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/mqtt_client/mqtt_client.c b/examples/mqtt_client/mqtt_client.c index fdf86c3..c725565 100644 --- a/examples/mqtt_client/mqtt_client.c +++ b/examples/mqtt_client/mqtt_client.c @@ -216,6 +216,6 @@ void user_init(void) vSemaphoreCreateBinary(wifi_alive); publish_queue = xQueueCreate(3, PUB_MSG_LEN); xTaskCreate(&wifi_task, (int8_t *)"wifi_task", 256, NULL, 2, NULL); - xTaskCreate(&beat_task, (int8_t *)"beat_task", 256, NULL, 3, NULL); - xTaskCreate(&mqtt_task, (int8_t *)"mqtt_task", 1024, NULL, 4, NULL); + xTaskCreate(&beat_task, (int8_t *)"beat_task", 256, NULL, 2, NULL); + xTaskCreate(&mqtt_task, (int8_t *)"mqtt_task", 1024, NULL, 2, NULL); } diff --git a/extras/paho_mqtt_c/MQTTESP8266.c b/extras/paho_mqtt_c/MQTTESP8266.c index 09e645b..dc2eb18 100644 --- a/extras/paho_mqtt_c/MQTTESP8266.c +++ b/extras/paho_mqtt_c/MQTTESP8266.c @@ -72,9 +72,8 @@ int mqtt_esp_read(Network* n, unsigned char* buffer, int len, int timeout_ms) int rcvd = 0; FD_ZERO(&fdset); FD_SET(n->my_socket, &fdset); - // It seems tv_sec actually means FreeRTOS tick - tv.tv_sec = timeout_ms / portTICK_RATE_MS; - tv.tv_usec = 0; + tv.tv_sec = timeout_ms / 1000; + tv.tv_usec = (timeout_ms % 1000) * 1000; rc = select(n->my_socket + 1, &fdset, 0, 0, &tv); if ((rc > 0) && (FD_ISSET(n->my_socket, &fdset))) { @@ -97,9 +96,8 @@ int mqtt_esp_write(Network* n, unsigned char* buffer, int len, int timeout_ms) FD_ZERO(&fdset); FD_SET(n->my_socket, &fdset); - // It seems tv_sec actually means FreeRTOS tick - tv.tv_sec = timeout_ms / portTICK_RATE_MS; - tv.tv_usec = 0; + tv.tv_sec = timeout_ms / 1000; + tv.tv_usec = (timeout_ms % 1000) * 1000; rc = select(n->my_socket + 1, 0, &fdset, 0, &tv); if ((rc > 0) && (FD_ISSET(n->my_socket, &fdset))) {