Open rk-sTEk opened 1 month ago
@rk-sTEk thanks for reporting. Could you check the MQTT-Explorer settings? I did an inspection in the code and tested with a local mosquitto instance and the client id is correctly placed in the control messages.
Hi, thanks for your answer.
Here are two lines of my MQTT-Broker-Log:
1726687870: New client connected from 10.x.x.100:51935 as sTEkSensor1 (p5, c1, k120, u'xxxsTEk').
...
1726687870: Received PUBLISH from sTEkSensor1 (d0, q1, r1, m1, '/messwerte/temperatur', ... (21 bytes))
It's seems, that the broker gets only the topic from the ESP. My other MQTT-devices are sending themself in the 5th parameter, like:
1726689367: Received PUBLISH from shelly1 (d0, q1, r0, m801, 'shelly1/events/rpc', ... (523 bytes))
Here is a screenshot from the MQTT-Explorer.
I'v got the sending routine from the example:
static void MQTT_Sende_Werte() {
int msg_id;
//print_user_property(event->property->user_property);
esp_mqtt5_client_set_user_property(&publish_property.user_property, user_property_arr, USE_PROPERTY_ARR_SIZE);
esp_mqtt5_client_set_publish_property(client, &publish_property);
msg_id = esp_mqtt_client_publish(client, "/messwerte/temperatur", "{\"temperature\":15.34}", 0, 1, 1);
esp_mqtt5_client_delete_user_property(publish_property.user_property);
publish_property.user_property = NULL;
ESP_LOGI(TAG3, "sent publish successful, msg_id=%d", msg_id);
}
@rk-sTEk I'm not following exactly what you are missing, as I can see the client id stated in the connection log you show.
Could you explain further and add a more complete reproducer?
Ah...okay...let me specify my "problem". Like you wrote, my ESP-MQTT-client is connecting with the broker and the client ID is visible in the log. But, when the client publishes a message, the client id is missing in the "path" and so an empty "root" is shown in the explorer and so. The reason is visible in the log. Other clients insert their own id in the transmitted path - like in the example with a Shelly device (green). But my ESP-client doesn't do this and so the root in the path is empty (red).
Argh...I solved my issue - but I don't know why the MQTT-library isn't auto expand the "path". When I write the client id without preceded slash in the function _esp_mqtt_clientpublish() everything looks fine.
msg_id = esp_mqtt_client_publish(client, "sTEkSensor1/messwerte/temperatur", "{\"temperature\":15.34}", 0, 1, 1);
Is there a chance to get the value from "mqtt_state.connection.information.client_id" which is in client in the main app? Both case, client. and client->, end with an error.
Hi @rk-sTEk, the mqtt client is written to support all operations required by the specification. There are many possible ways of building a topic string. If we put the client id as a prefix, we would be imposing this decision to systems that don't require it. At this moment, we don't have a way to recover this information. A simple workaround is to pass it as a configuration and keep the information to build the topic string.
Checklist
How often does this bug occurs?
always
Expected behavior
I tried to make a MQTT5-client. Everything is fine, but the client_id isn't used by the esp-board. The MQTT-Explorer only shows an empty device/client ("blank field without a name) - the following topic is named like written in code. Here is my code:
Actual behavior (suspected bug)
Error logs or terminal output
No response
Steps to reproduce the behavior
normaly compiled
Project release version
espidf 5.3.1
System architecture
other (details in Additional context)
Operating system
Linux
Operating system version
Debian
Shell
Bash
Additional context
It seems that the
.credentials.client_id = "sTEkSensor1",
isn't used in connection creation.