Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mqtt set uri function doesn't set transport to ssl with uri being 'mqtts://' (IDFGH-523) #2870

Closed
AadiMehta opened this issue Dec 23, 2018 · 1 comment

Comments

@AadiMehta
Copy link

Problem Description

esp_mqtt_client_set_uri function doesn't work when uri is mqtts://

Following example doesn't work:

static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event) {
}

const esp_mqtt_client_config_t mqtt_cfg = {
        .event_handle = mqtt_event_handler,
        .transport = MQTT_TRANSPORT_OVER_SSL,
	.username = "username",
	.password = "password",
};

void main() {
    char mqtt_url[] = "mqtts://iot.eclipse.org:8883"
    esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_cfg);
    esp_mqtt_client_set_uri(mqtt_client, mqtt_url);
    esp_mqtt_client_start(mqtt_client);
}

Above example only works if ".transport = MQTT_TRANSPORT_OVER_SSL," is added over mqtt_cfg.

@Alvin1Zhang Alvin1Zhang changed the title Mqtt set uri function doesn't set transport to ssl with uri being 'mqtts://' [TW#28040] Mqtt set uri function doesn't set transport to ssl with uri being 'mqtts://' Dec 23, 2018
@david-cermak
Copy link
Collaborator

Hi @AadiMehta

Thanks for reporting this issue.

The issue is that if transport is not (statically) selected upon esp_mqtt_client_init, mqtt library sets "mqtt" (over tcp) as default scheme and it is used in further library use.
This can be easily fixed by removing the below lines in function esp_mqtt_client_init(..) in module mqtt_client.c:

    if (client->config->scheme == NULL) {
        client->config->scheme = create_string("mqtt", 4);
        ESP_MEM_CHECK(TAG, client->config->scheme, goto _mqtt_init_failed);
    }

We will check if this change does not break anything else and go ahead with the fix.

david-cermak added a commit to espressif/esp-mqtt that referenced this issue Feb 15, 2019
@projectgus projectgus changed the title [TW#28040] Mqtt set uri function doesn't set transport to ssl with uri being 'mqtts://' Mqtt set uri function doesn't set transport to ssl with uri being 'mqtts://' (IDFGH-523) Mar 12, 2019
@igrr igrr closed this as completed in 1465f53 Mar 27, 2019
david-cermak added a commit to espressif/esp-mqtt that referenced this issue Dec 16, 2022
…ng/receiving different data and references esp-mqtt commits to pass these tests

testing conditions:
transports (tcp, ssl, ws..)
qos (0, 1, 2)
short repeated messages (packed packets)
oversized messages (fragmented packets)
publish from a different thread

Closes espressif/esp-idf#2870 by means of including commit 815623d from esp-mqtt
Closes espressif/esp-idf#2975 by means of including commit 752953d from esp-mqtt
Closes espressif/esp-idf#2850 by means of including commits df455d2 17fd713 from esp-mqtt
egnor pushed a commit to egnor/esp-mqtt that referenced this issue Dec 23, 2022
…ng/receiving different data and references esp-mqtt commits to pass these tests

testing conditions:
transports (tcp, ssl, ws..)
qos (0, 1, 2)
short repeated messages (packed packets)
oversized messages (fragmented packets)
publish from a different thread

Closes espressif/esp-idf#2870 by means of including commit 815623d from esp-mqtt
Closes espressif/esp-idf#2975 by means of including commit 752953d from esp-mqtt
Closes espressif/esp-idf#2850 by means of including commits df455d2 17fd713 from esp-mqtt
egnor pushed a commit to egnor/esp-mqtt that referenced this issue Dec 23, 2022
…ng/receiving different data and references esp-mqtt commits to pass these tests

testing conditions:
transports (tcp, ssl, ws..)
qos (0, 1, 2)
short repeated messages (packed packets)
oversized messages (fragmented packets)
publish from a different thread

Closes espressif/esp-idf#2870 by means of including commit 815623d from esp-mqtt
Closes espressif/esp-idf#2975 by means of including commit 752953d from esp-mqtt
Closes espressif/esp-idf#2850 by means of including commits df455d2 17fd713 from esp-mqtt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants