diff --git a/mqtt/include/mqtt.h b/mqtt/include/mqtt.h index a300c34..6a8a56d 100644 --- a/mqtt/include/mqtt.h +++ b/mqtt/include/mqtt.h @@ -100,6 +100,7 @@ typedef struct { MqttCallback connectedCb; MqttCallback disconnectedCb; MqttCallback publishedCb; + MqttCallback timeoutCb; MqttDataCallback dataCb; ETSTimer mqttTimer; uint32_t keepAliveTick; @@ -134,6 +135,7 @@ void ICACHE_FLASH_ATTR MQTT_InitLWT(MQTT_Client *mqttClient, uint8_t* will_topic void ICACHE_FLASH_ATTR MQTT_OnConnected(MQTT_Client *mqttClient, MqttCallback connectedCb); void ICACHE_FLASH_ATTR MQTT_OnDisconnected(MQTT_Client *mqttClient, MqttCallback disconnectedCb); void ICACHE_FLASH_ATTR MQTT_OnPublished(MQTT_Client *mqttClient, MqttCallback publishedCb); +void ICACHE_FLASH_ATTR MQTT_OnTimeout(MQTT_Client *mqttClient, MqttCallback timeoutCb); void ICACHE_FLASH_ATTR MQTT_OnData(MQTT_Client *mqttClient, MqttDataCallback dataCb); BOOL ICACHE_FLASH_ATTR MQTT_Subscribe(MQTT_Client *client, char* topic, uint8_t qos); void ICACHE_FLASH_ATTR MQTT_Connect(MQTT_Client *mqttClient); diff --git a/mqtt/mqtt.c b/mqtt/mqtt.c index 77cf72e..f218dec 100644 --- a/mqtt/mqtt.c +++ b/mqtt/mqtt.c @@ -385,6 +385,8 @@ void ICACHE_FLASH_ATTR mqtt_timer(void *arg) client->reconnectTick = 0; client->connState = TCP_RECONNECT; system_os_post(MQTT_TASK_PRIO, 0, (os_param_t)client); + if (client->timeoutCb) + client->timeoutCb((uint32_t*)client); } } if (client->sendTimeout > 0) @@ -809,3 +811,9 @@ MQTT_OnPublished(MQTT_Client *mqttClient, MqttCallback publishedCb) { mqttClient->publishedCb = publishedCb; } + +void ICACHE_FLASH_ATTR +MQTT_OnTimeout(MQTT_Client *mqttClient, MqttCallback timeoutCb) +{ + mqttClient->timeoutCb = timeoutCb; +} \ No newline at end of file