与TCP(ESP-IDF)连接ESP-MQTT的问题

发布于 2025-01-26 06:19:09 字数 1059 浏览 4 评论 0原文

我有一个问题,即与移动热点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:

error codes on esp-idf monitor

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红焚 2025-02-02 06:19:09

错误意味着ESP无法与经纪人连接到机器。这可能是出于多种原因,

  1. 经纪人主机不在您给出的IP地址上,
  2. 您使用的WiFi访问点已设置为启用客户端分离,这意味着它不允许2个连接的客户端与彼此。
  3. 如果经纪人未连接到移动访问点,则可能需要使用网络的公共(静态或启用DYNDNS)地址,并启用了端口转发

The error means that the ESP could not connect to the machine with the broker. This could be for a number of reasons

  1. The broker host is not on the IP address you've given
  2. The WiFi Access point you are using is set up with client separation enabled, which means that it won't allow 2 connected client to talk to each other.
  3. If the Broker is not connected to the Mobile Access Point then you probably need to be using the public (static or have DynDNS enabled) address of your network and have Port forwarding enabled
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文