mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-08-03 12:45:34 +02:00
added termination flag to stop mqtt client
This commit is contained in:
10
mqtt.c
10
mqtt.c
@@ -19,6 +19,7 @@
|
|||||||
static TaskHandle_t xMqttTask = NULL;
|
static TaskHandle_t xMqttTask = NULL;
|
||||||
static TaskHandle_t xMqttSendingTask = NULL;
|
static TaskHandle_t xMqttSendingTask = NULL;
|
||||||
|
|
||||||
|
static bool terminate_mqtt = false;
|
||||||
|
|
||||||
static int resolve_dns(const char *host, struct sockaddr_in *ip) {
|
static int resolve_dns(const char *host, struct sockaddr_in *ip) {
|
||||||
struct hostent *he;
|
struct hostent *he;
|
||||||
@@ -397,6 +398,8 @@ void mqtt_start_receive_schedule(mqtt_client *client)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
|
if (terminate_mqtt) break;
|
||||||
|
|
||||||
read_len = client->settings->read_cb(client, client->mqtt_state.in_buffer, CONFIG_MQTT_BUFFER_SIZE_BYTE, 0);
|
read_len = client->settings->read_cb(client, client->mqtt_state.in_buffer, CONFIG_MQTT_BUFFER_SIZE_BYTE, 0);
|
||||||
|
|
||||||
mqtt_info("Read len %d", read_len);
|
mqtt_info("Read len %d", read_len);
|
||||||
@@ -408,7 +411,6 @@ void mqtt_start_receive_schedule(mqtt_client *client)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
msg_type = mqtt_get_type(client->mqtt_state.in_buffer);
|
msg_type = mqtt_get_type(client->mqtt_state.in_buffer);
|
||||||
msg_qos = mqtt_get_qos(client->mqtt_state.in_buffer);
|
msg_qos = mqtt_get_qos(client->mqtt_state.in_buffer);
|
||||||
msg_id = mqtt_get_id(client->mqtt_state.in_buffer, client->mqtt_state.in_buffer_length);
|
msg_id = mqtt_get_id(client->mqtt_state.in_buffer, client->mqtt_state.in_buffer_length);
|
||||||
@@ -493,6 +495,8 @@ void mqtt_task(void *pvParameters)
|
|||||||
mqtt_client *client = (mqtt_client *)pvParameters;
|
mqtt_client *client = (mqtt_client *)pvParameters;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
if (terminate_mqtt) break;
|
||||||
|
|
||||||
client->settings->connect_cb(client);
|
client->settings->connect_cb(client);
|
||||||
|
|
||||||
mqtt_info("Connected to server %s:%d", client->settings->host, client->settings->port);
|
mqtt_info("Connected to server %s:%d", client->settings->host, client->settings->port);
|
||||||
@@ -536,6 +540,8 @@ void mqtt_task(void *pvParameters)
|
|||||||
|
|
||||||
mqtt_client *mqtt_start(mqtt_settings *settings)
|
mqtt_client *mqtt_start(mqtt_settings *settings)
|
||||||
{
|
{
|
||||||
|
terminate_mqtt = false;
|
||||||
|
|
||||||
int stackSize = 2048;
|
int stackSize = 2048;
|
||||||
|
|
||||||
uint8_t *rb_buf;
|
uint8_t *rb_buf;
|
||||||
@@ -645,6 +651,6 @@ void mqtt_publish(mqtt_client* client, const char *topic, const char *data, int
|
|||||||
|
|
||||||
void mqtt_stop()
|
void mqtt_stop()
|
||||||
{
|
{
|
||||||
|
terminate_mqtt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user