EC200U MQTTX esp32

ERROR

+QMTSTAT: 0,1 I have facing this issue and my log output is given below

I (48181) EC200U: Sending data: Temperature=30.0, Humidity=66.0
I (48181) EC200U: Sent: AT
I (49281) EC200U: Response: AT
OK

I (49281) EC200U: Sent: AT+CFUN=1
I (50381) EC200U: Response: AT+CFUN=1
OK

I (50381) EC200U: Sent: AT+CSQ
I (51481) EC200U: Response: AT+CSQ
+CSQ: 13,99

OK

I (51481) EC200U: Sent: AT+CREG?
I (52581) EC200U: Response: AT+CREG?
+CREG: 0,5

OK

I (52581) EC200U: Sent: AT+QIDEACT=1
I (53681) EC200U: Response: AT+QIDEACT=1
OK

I (53681) EC200U: Sent: AT+CGATT=1
I (54781) EC200U: Response: AT+CGATT=1
OK

I (54781) EC200U: Sent: AT+QICSGP=1,1,“jionet”,“”,“”,1
I (55881) EC200U: Response: AT+QICSGP=1,1,“jionet”,“”,“”,1
OK

I (55881) EC200U: Sent: AT+QIACT=1
I (56981) EC200U: Response: AT+QIACT=1
OK

I (56981) EC200U: Sent: AT+QMTCFG=?
I (57981) EC200U: Response: AT+QMTCFG=?
+QMTCFG: “version”,(0-5),(3,4)
+QMTCFG: “pdpcid”,(0-5),(1-7)
+QMTCFG: “ssl”,(0-5),(0,1),(0-5)
+QMTCFG: “keepalive”,(0-5),(0-3600)
+QMTCFG: “session”,(0-5),(0,1)
+QMTCFG: “timeout”,(0-5),(1-60),(1-10),(0,1)
+QMTCFG: “will”,(0-5),(0,1),(0-2),(0,1),“willtopic”,“willmessage”
+QMTCFG: “willex”,(0-5),(0,1),(0-2),(0,1),“willtopic”,(0-256)
+QMTCFG: “recv/mode”,(0-5),(0,1),(0,1)
+QMTCFG: “send/mode”,(0-5),(0,1)
+QMTCFG: “aliauth”,(0-5),“product key”,“device name”,“device secret”
+QMTCFG: “on
I (58111) EC200U: Response: enet”,(0-5),“product id”,“access key”
+QMTCFG: “dataformat”,(0-5),(0,1),(0,1)
+QMTCFG: “view/mode”,(0-5),(0,1)
+QMTCFG: “qmtping”,(0-5),(5-60)
+QMTCFG: “edit/timeout”,(0-5),(0,1),(1-180)

OK

I (58121) EC200U: Sent: AT+QMTOPEN=?
I (59221) EC200U: Response: AT+QMTOPEN=?
+QMTOPEN: (0-5),“hostname”,(1-65535)

OK

I (59221) EC200U: Sent: AT+QMTOPEN=0,“test.mosquitto.org”,1883
I (60321) EC200U: Response: AT+QMTOPEN=0,“test.mosquitto.org”,1883
OK

+QMTOPEN: 0,0

I (60321) EC200U: Sent: AT+QMTCONN?
I (61421) EC200U: Response: AT+QMTCONN?
+QMTCONN: 0,1

OK

I (61421) EC200U: Sent: AT+QMTCONN=0,“mqttx_69bb68af”,120
I (62521) EC200U: Response: AT+QMTCONN=0,“mqttx_69bb68af”,120
OK

+QMTCONN: 0,0,0

I (62521) EC200U: Sent: AT+QMTSUB=?
I (63621) EC200U: Response: AT+QMTSUB=?
+QMTSUB: (0-5),,list of [“topic”,qos]

OK

I (63621) EC200U: Sent: AT+QMTSUB=0,1,“auto”,0
I (64721) EC200U: Response: AT+QMTSUB=0,1,“auto”,0
OK

+QMTSUB: 0,1,0,0

I (64721) EC200U: Successfully subscribed to topic: auto
I (64721) EC200U: Sent: AT+QMTPUBEX=0,0,0,0,“auto”,45
I (67721) EC200U: Response: AT+QMTPUBEX=0,0,0,0,“auto”,45

I (67721) EC200U: Sent: { “temperature”: “30.0”, “humidity”: “66.0” }
I (68821) EC200U: Response: { “temperature”: “30.0”, “humidity”: “66.0” }
ERROR

+QMTSTAT: 0,1

I (68921) EC200U: Response:
I (69021) EC200U: Response:
I (69121) EC200U: Response:
I (69221) EC200U: Response:
I (69321) EC200U: Response:
I (69421) EC200U: Response:
I (69521) EC200U: Response:
I (69621) EC200U: Response:
I (69721) EC200U: Response:
I (69821) EC200U: Response:
I (69921) EC200U: Response:
I (70021) EC200U: Response:
I (70121) EC200U: Response:
I (70221) EC200U: Response:
I (70321) EC200U: Response:
I (70421) EC200U: Response:
I (70521) EC200U: Response:
I (70621) EC200U: Response:
I (70721) EC200U: Response:
I (70821) EC200U: Response:
I (70921) EC200U: Response:
I (71021) EC200U: Response:
I (71121) EC200U: Response:
I (71221) EC200U: Response:
I (71321) EC200U: Response:
I (71421) EC200U: Response:
I (71521) EC200U: Response:
I (71621) EC200U: Response:
I (71721) EC200U: Response:
I (71821) EC200U: Response:
I (71921) EC200U: Response:
I (72021) EC200U: Response:
I (72121) EC200U: Response:
I (72221) EC200U: Response:
I (72321) EC200U: Response:
I (72421) EC200U: Response:
I (72521) EC200U: Response:
I (72621) EC200U: Response:
I (72721) EC200U: Response:
I (72821) EC200U: Response:
I (72921) EC200U: Response:
I (73021) EC200U: Response:
I (73121) EC200U: Response:
I (73221) EC200U: Response:
I (73321) EC200U: Response:
I (73421) EC200U: Response:
I (73521) EC200U: Response:
I (73621) EC200U: Response:
I (73721) EC200U: Response:
E (73721) EC200U: MQTT publish failed, retrying…

for %v in (30 45 60) do mosquitto_pub -h broker.emqx.io -t “Sample” -m “{ "value": "%v" }”

After you load the data, you need to add the HEX(1A) to equal ctrl+z

HI,

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include “driver/uart.h”
#include “esp_log.h”
#include “freertos/FreeRTOS.h”
#include “freertos/task.h”

#define TXD_PIN (4) // EC200U TX pin connected to ESP32 GPIO 4
#define RXD_PIN (5) // EC200U RX pin connected to ESP32 GPIO 5
#define UART_NUM UART_NUM_1

static const char *TAG = “EC200U”;

void uart_init(void) {
const uart_config_t uart_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
};
uart_param_config(UART_NUM, &uart_config);
uart_set_pin(UART_NUM, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART_NUM, 1024 * 2, 0, 0, NULL, 0);
}

void uart_send_command(const char *cmd) {
uart_write_bytes(UART_NUM, cmd, strlen(cmd));
uart_write_bytes(UART_NUM, “\r\n”, 2);
ESP_LOGI(TAG, “Sent: %s”, cmd);
vTaskDelay(pdMS_TO_TICKS(1000));
}

void uart_read_response(char *response, int max_len, int timeout_ms) {
int len = 0, total_len = 0;
while (timeout_ms > 0) {
len = uart_read_bytes(UART_NUM, (uint8_t *)response + total_len, max_len - total_len, 20 / portTICK_PERIOD_MS);
if (len > 0) {
total_len += len;
}
timeout_ms -= 20;
if (total_len >= max_len - 1) {
break;
}
}
response[total_len] = ‘\0’;
ESP_LOGI(TAG, “Response: %s”, response);
}

bool wait_for_ok(int timeout_ms) {
char response[512];
while (timeout_ms > 0) {
uart_read_response(response, sizeof(response), 100);
if (strstr(response, “OK”) != NULL) {
return true;
}
timeout_ms -= 100;
}
return false;
}

bool wait_for_mqtt_response(const char *expected, int timeout_ms) {
char response[512];
while (timeout_ms > 0) {
uart_read_response(response, sizeof(response), 100);
if (strstr(response, expected) != NULL) {
return true;
}
timeout_ms -= 100;
}
return false;
}

void send_to_mqtt(float temperature, float humidity) {
char command[256], payload[128];

uart_send_command("AT");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+CFUN=1");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+CSQ");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+CREG?");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+QIDEACT=1");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+CGATT=1");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+QICSGP=1,1,\"jionet\",\"\",\"\",1");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+QIACT=1");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+QMTCFG=\"send/mode\",0,0");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+QMTCFG=\"version\",0,4");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+QMTCFG=\"pdpcid\",0,1");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+QMTCFG=\"keepalive\",0,120");
if (!wait_for_ok(2000)) return;

uart_send_command("AT+QMTOPEN=0,\"broker.emqx.io\",1883");
if (!wait_for_mqtt_response("+QMTOPEN: 0,0", 10000)) {
    ESP_LOGE(TAG, "MQTT open failed, retrying...");
    vTaskDelay(pdMS_TO_TICKS(5000));
    return;
}

uart_send_command("AT+QMTCONN=0,\"mqttx_5ed4df46\"");
if (!wait_for_mqtt_response("+QMTCONN: 0,0", 5000)) {
    ESP_LOGE(TAG, "MQTT connection failed, retrying...");
    vTaskDelay(pdMS_TO_TICKS(5000));
    return;
}

uart_send_command("AT+QMTSUB=0,1,\"Sample\",0");
if (!wait_for_mqtt_response("+QMTSUB: 0,1,0,0", 5000)) {
    ESP_LOGE(TAG, "MQTT subscription failed!");
    return;
}

ESP_LOGI(TAG, "Successfully subscribed to topic: Sample");

snprintf(payload, sizeof(payload), "%.1f,%.1f", temperature, humidity);

snprintf(command, sizeof(command), "AT+QMTPUBEX=0,0,0,0,\"auto\",%d", (int)strlen(payload));
uart_send_command(command);

char response[512];
uart_read_response(response, sizeof(response), 2000);
if (strstr(response, ">") == NULL) {
    ESP_LOGE(TAG, "No `>` prompt received, retrying...");
    vTaskDelay(pdMS_TO_TICKS(5000));
    return;
}

uart_send_command(payload);
if (!wait_for_mqtt_response("+QMTPUBEX: 0,0,0", 5000)) {
    ESP_LOGE(TAG, "MQTT publish failed, retrying...");
    vTaskDelay(pdMS_TO_TICKS(5000));
    return;
}

uart_send_command("AT+QMTDISC=0");
if (!wait_for_mqtt_response("+QMTDISC: 0,0", 5000)) {
    ESP_LOGE(TAG, "MQTT disconnection failed!");
    return;
}

ESP_LOGI(TAG, "MQTT client disconnected successfully.");

}
This is my code for this I am getting output yesterday I updated log which you have seen
is the AT commands in my code is proper or need some changes can you please guide me.

thanks,
saravanan

void app_main(void) {
uart_init();
while (true) {
float temperature = 30.0;
float humidity = 66.0;
ESP_LOGI(TAG, “Sending data: Temperature=%.1f, Humidity=%.1f”, temperature, humidity);
send_to_mqtt(temperature, humidity);
vTaskDelay(pdMS_TO_TICKS(15000));
}
}

Sorry, I’m not good AT code, I suggest you output txd/rxd AT log

can you give me the AT command sequence

I recommend that you first use COM tools for manual debugging and trying