I am trying to communicate with VerneMQ using ESP32.
Problem:
Sometimes local devices with esp32 cannot receive any packets from VerneMQ broker. This happens rarely and once the local device can't receive packets, it won't be received after that.
However when I disconnect the devices session, it receives packets for a few seconds. To force a disconnection I am using the command sudo vmq-admin session disconnect | grep client_id='client_id. Unfortunately, 'the few seconds' the packet received is not constant, after that, devices cannot receive packets again.
terribly Debugging is difficult because there is no storage space on the local device.
Could it be something to do with the QOS settings? or vernemq configuration?
What I tried:
- repeat the cmd
sudo vmq-admin session disconnect | grep client_id='client_idabout 10~20 times. - use the cmd
sudo vmq-admin session disconnect | grep client_id='client_id, then send reset cmd to local device.
Result: I usually got same results. Local devices receive packets few seconds then seems blocked the packets again. Surprisingly, the packet is received again after a certain period of time.
Configuration
- esp32=client /Role: publish raw sensor data and subscribe control commands from broker
chip: esp32-wroom-32
ide: esp-idf v4.3.1
os: Windows
mqtt_cfg={
.host = CONFIG_MQTT_HOST,
.port = 8883,
.username = "username",
.password = "password",
.transport = MQTT_TRANSPORT_OVER_SSL, //.disable_clean_session = 1, //if disable_clean_session is true, resume communication with the client(after subscription, receive last message)
.client_cert_pem = (const char *)client_cert_pem_start,
.client_key_pem = (const char *)client_key_pem_start,
.cert_pem = (const char *)server_cert_pem_start,
.keepalive = 60,
.buffer_size = 2048,
.client_id = client_id
}
1-1) publish : QOS 0, retain false
1-2) subscribe : QOS 0, retain false
- VerneMQ
Except for certification-related settings, all are default values.
plugins.vmq_bridge = off so keepalive, timeout setting is default.
Example esp32 code:
void app_main(void)
{
ESP_LOGD(TAG, "[APP] Startup..");
ESP_LOGD(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
ESP_LOGD(TAG, "[APP] IDF version: %s", esp_get_idf_version());
esp_log_level_set("*", ESP_LOG_INFO);
esp_log_level_set("esp-tls", ESP_LOG_VERBOSE);
esp_log_level_set("MQTT_CLIENT", ESP_LOG_VERBOSE);
//esp_log_level_set("MODEL_Y0_ESP32", ESP_LOG_VERBOSE);
esp_log_level_set("TRANSPORT_BASE", ESP_LOG_VERBOSE);
esp_log_level_set("TRANSPORT", ESP_LOG_VERBOSE);
esp_log_level_set("OUTBOX", ESP_LOG_VERBOSE);
initialise_wifi();
s_mqtt_event_group = xEventGroupCreate(); //Create EventGroup for MQTT START after first WiFI Connection
}
static void sendMQTT(uint8_t *pBuffer, uint8_t size)
{
if (esp_mqtt_client_publish(mqtt_client, mqtt_topic, (const char *)pBuffer, size, 0, 0); != -1)
{
ESP_LOGD(TAG, "pub success");
}
else
{
ESP_LOGE(TAG, "pub failed");
}
}
I deleted part of code
sendmqtt function is executed in a different thread after raw data sampling
You can trace that session on the command line like this:
sudo vmq-admin trace client client-id=client_idThis will give you all the events for that session but from the perspective of the broker. If you see an
MQTT SEND, it'll be a message published from the broker to your consumer. This should determine whether the message goes out, at least.Also: Does your client implement re-connect logic. Are you sure it re-subscribes to topics?