如何解决ESP32 MQTT多代理设置
我试图使用ESP-IDF同时连接到2个MQTT代理。 一个在TLS端口8883上,另一个在1883端口上不安全。
我已经声明了2个客户端实例,但是以某种方式我无法使它们连接到代理。
源代码:
// Device manager configuration
esp_mqtt_client_config_t mqtt_device_manager_cfg = {
.uri = MQTT_DEVICE_MANAGER_URI,.port = MQTT_DEVICE_MANAGER_PORT,.username = (const char*) device_UUID,.password = MQTT_DEVICE_MANAGER_PASSWORD,.client_id = (const char*) device_UUID,.disable_clean_session = 1,.cert_pem = client_cert_pem,.transport = MQTT_TRANSPORT_OVER_SSL
};
device_manager_mqtt_client = esp_mqtt_client_init(&mqtt_device_manager_cfg);
esp_mqtt_client_register_event(device_manager_mqtt_client,ESP_EVENT_ANY_ID,mqtt_device_manager_event_handler,NULL);
esp_mqtt_client_start(device_manager_mqtt_client);
// MQTT configuration
esp_mqtt_client_config_t mqtt_cfg = {
.uri = MQTT_URI,.port = MQTT_PORT,.username = MQTT_USERNAME,.password = MQTT_PASSWORD,.transport = MQTT_TRANSPORT_OVER_TCP
};
mqtt_client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_register_event(mqtt_client,mqtt_event_handler,NULL);
esp_mqtt_client_start(mqtt_client);
错误:
E (5078) esp-tls: mbedtls_ssl_handshake returned -0x2700
I (5078) wifi:I (5078) esp-tls: Failed to verify peer certificate!
int: state=0 i=0
I (5078) esp-tls: verification info: ! The certificate is not correctly signed by the trusted CA
E (5088) esp-tls: Failed to open new connection
E (5098) TRANS_SSL: Failed to open a new connection
E (5098) MQTT_CLIENT: Error transport connect
以某种方式看来,不安全的客户端认为它是安全的,并试图使用证书,但不应这样做。
我在做什么错了?
解决方法
如果我删除.cert_pem值,则可以正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。