I am having trouble running MQTT on my ESP-SOLO-1. It worked before, but not now. Can anyone suggest why?
What I got:
Code: Select all
D (4056) MQTT_CLIENT: MQTT client_id=ESP32_a89628
D (4056) event: created event loop 0x3ffbdaf0
D (4066) MQTT_CLIENT: Core selection disabled
I (4066) mqtt_event: Other event id:7
D (4266) TRANS_TCP: [sock=54],connecting to server IP:34.214.82.240,Port:8083...
D (4576) MQTT_CLIENT: Transport connected to mqtt://broker.emqx.io:8083
D (4586) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
E (9896) MQTT_CLIENT: mqtt_message_receive: transport_read() error: errno=128
I (9896) mqtt_event: Other event id:0
E (9896) MQTT_CLIENT: esp_mqtt_connect: mqtt_message_receive() returned -1
E (9906) MQTT_CLIENT: MQTT connect failed
D (9916) MQTT_CLIENT: Reconnect after 10000 ms
I (9916) mqtt_event: MQTT_EVENT_DISCONNECTED
D (19926) MQTT_CLIENT: Reconnecting...
I (19926) mqtt_event: Other event id:7
D (19926) TRANS_TCP: [sock=54],connecting to server IP:34.214.82.240,Port:8083...
D (20246) MQTT_CLIENT: Transport connected to mqtt://broker.emqx.io:8083
D (20246) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
E (25566) MQTT_CLIENT: mqtt_message_receive: transport_read() error: errno=128
I (25566) mqtt_event: Other event id:0
E (25566) MQTT_CLIENT: esp_mqtt_connect: mqtt_message_receive() returned -1
E (25576) MQTT_CLIENT: MQTT connect failed
D (25576) MQTT_CLIENT: Reconnect after 10000 ms
I (25586) mqtt_event: MQTT_EVENT_DISCONNECTED
D (35586) MQTT_CLIENT: Reconnecting...
I (35586) mqtt_event: Other event id:7
D (35586) TRANS_TCP: [sock=54],connecting to server IP:34.214.82.240,Port:8083...
D (35916) MQTT_CLIENT: Transport connected to mqtt://broker.emqx.io:8083
D (35916) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
E (41236) MQTT_CLIENT: mqtt_message_receive: transport_read() error: errno=128
I (41236) mqtt_event: Other event id:0
E (41236) MQTT_CLIENT: esp_mqtt_connect: mqtt_message_receive() returned -1
E (41246) MQTT_CLIENT: MQTT connect failed
D (41246) MQTT_CLIENT: Reconnect after 10000 ms
I (41246) mqtt_event: MQTT_EVENT_DISCONNECTED
Code: Select all
#include <stdio.h>
#include "esp_spi_flash.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "mqtt_client.h"
#include "esp_wifi.h"
#include "nvs_flash.h"
#include "esp_netif.h"
#include "esp_log.h"
#include "protocol_examples_common.h"
static EventGroupHandle_t mqtt_event_group;
const static int CONNECTED_BIT = BIT5;
static bool mqtt_connected = false;
static esp_mqtt_client_handle_t global_client;
static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
{
static const char *TAG = "mqtt_event";
switch (event->event_id)
{
case MQTT_EVENT_CONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
xEventGroupSetBits(mqtt_event_group, CONNECTED_BIT);
mqtt_connected = true;
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
mqtt_connected = false;
break;
case MQTT_EVENT_SUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_UNSUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
printf("TOPIC=%d , %.*s\r\n", event->topic_len, event->topic_len, event->topic);
printf("DATA=%d , %.*s\r\n", event->data_len, event->data_len, event->data);
break;
default:
ESP_LOGI(TAG, "Other event id:%d", event->event_id);
break;
}
return ESP_OK;
}
void mqtt_server_login()
{
esp_mqtt_client_config_t mqtt_cfg = { };
mqtt_cfg.uri = "mqtt://broker.emqx.io";
mqtt_cfg.port = 8083;
mqtt_cfg.event_handle= mqtt_event_handler;
global_client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_start(global_client);
}
void app_main(void)
{
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(example_connect());
mqtt_server_login();
xEventGroupWaitBits(mqtt_event_group, CONNECTED_BIT, false, true, portMAX_DELAY);
while (1)
{
if(mqtt_connected == true)
esp_mqtt_client_publish(global_client, "/test", "s", 1, 0, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}