与TCP(ESP-IDF)连接ESP-MQTT的问题
我有一个问题,即与移动热点wifi有正确的连接,但是当我尝试将MQTT连接到PC IP上将某些传感器数据上传到我的PC IP时(我使用蚊子经纪人做到了)时,我总是有同样的问题。
esp_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtt://192.168.166.66:1883",
//.host = "192.168.166.66",
//.port = 1883,
.buffer_size = 1024,
.client_id = "ESP-TFG-FRAN",
.lwt_qos = 1,
//.transport = MQTT_TRANSPORT_OVER_TCP,
.protocol_ver = MQTT_PROTOCOL_V_3_1_1,
};
client = esp_mqtt_client_init(&mqtt_cfg);
vTaskDelay(100/portTICK_RATE_MS);
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client);
ret = esp_mqtt_client_start(client);
if(ret != ESP_OK) {
printf("ERROR in first connecting of MQTT: %x\n", ret);
esp_mqtt_client_reconnect(client);
}
有人可以帮我解决吗?
这是我始终拥有的错误代码:
我可能会认为这可能是一个问题SDK和idf.py menuconfig
或TCP/IP协议...但是我可以解决问题的解决方案...
I have a problema that I have a correctly connection to my mobile hotspot wifi, but when I try to connect MQTT to upload some sensor data to my PC ip (I did it with mosquitto broker), I always have the same problem.
esp_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtt://192.168.166.66:1883",
//.host = "192.168.166.66",
//.port = 1883,
.buffer_size = 1024,
.client_id = "ESP-TFG-FRAN",
.lwt_qos = 1,
//.transport = MQTT_TRANSPORT_OVER_TCP,
.protocol_ver = MQTT_PROTOCOL_V_3_1_1,
};
client = esp_mqtt_client_init(&mqtt_cfg);
vTaskDelay(100/portTICK_RATE_MS);
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client);
ret = esp_mqtt_client_start(client);
if(ret != ESP_OK) {
printf("ERROR in first connecting of MQTT: %x\n", ret);
esp_mqtt_client_reconnect(client);
}
Could someone help me to solve it?
This is my error code that I always have:
I will think it is probably a problem with the sdk and the idf.py menuconfig
or the TCP/IP protocol... but I can`t fine the solution of the problem...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误意味着ESP无法与经纪人连接到机器。这可能是出于多种原因,
The error means that the ESP could not connect to the machine with the broker. This could be for a number of reasons