MQTT进行publish的时候好像比较容易出现问题,这样改似乎有改善,仅供参考。
ESP8266_RTOS_SDK/third_party/mqtt/library/MQTTClient.c
ESP8266_RTOS_SDK/third_party/mqtt/platform/MQTTFreeRTOS.c
diff --git a/ESP8266_RTOS_SDK/third_party/mqtt/library/MQTTClient.c b/ESP8266_RTOS_SDK/third_party/mqtt/library/MQTTClient.c
index e21af51..937beba 100755
--- a/ESP8266_RTOS_SDK/third_party/mqtt/library/MQTTClient.c
+++ b/ESP8266_RTOS_SDK/third_party/mqtt/library/MQTTClient.c
@@ -251,6 +251,8 @@ void MQTTCloseSession(MQTTClient* c)
c->isconnected = 0;
if (c->cleansession)
MQTTCleanSession(c);
+
+ c->ipstack->disconnect(c->ipstack);
}
@@ -345,7 +347,7 @@ int MQTTYield(MQTTClient* c, int timeout_ms)
TimerInit(&timer);
TimerCountdownMS(&timer, timeout_ms);
-
+#if 0
do
{
if (cycle(c, &timer) < 0)
@@ -354,6 +356,20 @@ int MQTTYield(MQTTClient* c, int timeout_ms)
break;
}
} while (!TimerIsExpired(&timer));
+#else
+#if defined(MQTT_TASK)
+ MutexLock(&c->mutex);
+#endif
+
+ if (cycle(c, &timer) < 0)
+ {
+ rc = FAILURE;
+ }
+
+#if defined(MQTT_TASK)
+ MutexUnlock(&c->mutex);
+#endif
+#endif
return rc;
}
diff --git a/ESP8266_RTOS_SDK/third_party/mqtt/platform/MQTTFreeRTOS.c b/ESP8266_RTOS_SDK/third_party/mqtt/platform/MQTTFreeRTOS.c
index 1cd3999..ee5ad92 100755
--- a/ESP8266_RTOS_SDK/third_party/mqtt/platform/MQTTFreeRTOS.c
+++ b/ESP8266_RTOS_SDK/third_party/mqtt/platform/MQTTFreeRTOS.c
@@ -38,19 +38,22 @@ int ThreadStart(Thread* thread, void (*fn)(void*), void* arg)
void MutexInit(Mutex* mutex)
{
- mutex->sem = xSemaphoreCreateMutex();
+ //mutex->sem = xSemaphoreCreateMutex();
+ mutex->sem = xSemaphoreCreateRecursiveMutex();
}
int MutexLock(Mutex* mutex)
{
- return xSemaphoreTake(mutex->sem, portMAX_DELAY);
+ //return xSemaphoreTake(mutex->sem, portMAX_DELAY);
+ return xSemaphoreTakeRecursive(mutex->sem, portMAX_DELAY);
}
int MutexUnlock(Mutex* mutex)
{
- return xSemaphoreGive(mutex->sem);
+ //return xSemaphoreGive(mutex->sem);
+ return xSemaphoreGiveRecursive(mutex->sem);
}
void TimerCountdownMS(Timer* timer, unsigned int timeout_ms)
网友评论