Page 1 of 1

MQTT problem

Posted: Fri Aug 27, 2021 10:35 am
by rooti92
Hello everyone,

I have a problem with the MQTT receiver. I'm sending a message using proto file like
"

TurnOn/ On j
2 <reply/ 24: 0A: C4: 40: D5: 7C / 9d3cc41f-0d35-4543-8521-1bdd63c59b99 "

But in the ESP32 code I got:

And (18713) Mqtt: DATA =

Switch / selector
2

Cuts out some information like "reply ...."

Re: MQTT problem

Posted: Sat Aug 28, 2021 1:51 am
by ESP_Sprite
Can you post the code that sends/receives this?

Re: MQTT problem

Posted: Sat Aug 28, 2021 5:13 pm
by rooti92
Hi,
I have only code for receiving information.
But If I use for example MQTT explorer like external APP I can see corect frame.

Code: Select all

esp_err_t Protocols::Mqtt::mqttEventHandlerCb(esp_mqtt_event_handle_t t_event)
{  
    std::string userContext = *((std::string*) t_event->user_context);
    switch (t_event->event_id) 
    {
        case MQTT_EVENT_CONNECTED:
            {
                
            }
            break;
            
        case MQTT_EVENT_DISCONNECTED:
            {
               

                ESP_LOGI(Protocols::Mqtt::TAG, "MQTT_EVENT_DISCONNECTED - client %s", userContext.c_str());
            }
            break;

        case MQTT_EVENT_SUBSCRIBED:
            ESP_LOGI(Protocols::Mqtt::TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", t_event->msg_id);
            break;

        case MQTT_EVENT_UNSUBSCRIBED:
            ESP_LOGI(Protocols::Mqtt::TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", t_event->msg_id);
            break;

        case MQTT_EVENT_PUBLISHED:
            ESP_LOGI(Protocols::Mqtt::TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", t_event->msg_id);
            break;

        case MQTT_EVENT_DATA:
            {
                ESP_LOGI(Protocols::Mqtt::TAG, "MQTT_EVENT_DATA");
                ESP_LOGD(Protocols::Mqtt::TAG,"TOPIC= %.*s", t_event->topic_len, t_event->topic);

            }
            break;

        case MQTT_EVENT_ERROR:
            ESP_LOGI(Protocols::Mqtt::TAG, "MQTT_EVENT_ERROR - client %s", userContext.c_str());
            break;

        default:
            break;
    }
    return ESP_OK;
}

Re: MQTT problem

Posted: Sat Aug 28, 2021 6:44 pm
by rooti92
This is probably caused by "�" inside the message. How we can avoid this problem?

Re: MQTT problem

Posted: Mon Aug 30, 2021 3:10 am
by ESP_Sprite
Not sure what that character is, but the issue may be that it's a NULL (ASCII value 0). In that case, ESP_LOG* (which is based on printf) will stop printing data there. Your data still is in the string, you may simply need to filter out that character for it to log correctly.