MQTT problem

rooti92
Posts: 4
Joined: Fri Aug 27, 2021 10:20 am

MQTT problem

Postby rooti92 » Fri Aug 27, 2021 10:35 am

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 ...."

ESP_Sprite
Posts: 9724
Joined: Thu Nov 26, 2015 4:08 am

Re: MQTT problem

Postby ESP_Sprite » Sat Aug 28, 2021 1:51 am

Can you post the code that sends/receives this?

rooti92
Posts: 4
Joined: Fri Aug 27, 2021 10:20 am

Re: MQTT problem

Postby rooti92 » Sat Aug 28, 2021 5:13 pm

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;
}

rooti92
Posts: 4
Joined: Fri Aug 27, 2021 10:20 am

Re: MQTT problem

Postby rooti92 » Sat Aug 28, 2021 6:44 pm

This is probably caused by "�" inside the message. How we can avoid this problem?

ESP_Sprite
Posts: 9724
Joined: Thu Nov 26, 2015 4:08 am

Re: MQTT problem

Postby ESP_Sprite » Mon Aug 30, 2021 3:10 am

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.

Who is online

Users browsing this forum: No registered users and 241 guests