无法使用Adafruit MQTT库配置MQTT客户端ID

时间:2018-08-11 21:32:32

标签: arduino mqtt esp8266 adafruit

我正在使用Adafruit创建的MQTT库,该库位于here,并且库本身运行良好-但是我发现自己无法编辑客户端ID或配置PINGRESP。我当前使用的代码可以在下面看到-

WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, "10.116.10.191", 1883);

当客户端连接到MQTT Broker时,客户端ID变成由字母,数字和符号组成的随机字符串,如下所示-

1534023607: Client ]7llG5K6J4=^tPHJHqgTUFc<Ep^m3vJ`4vSL2oB<cO[^_chw[GBp]v3smagpOqWS has exceeded timeout, disconnecting.
1534023608: New connection from 10.116.7.21 on port 1883.
1534023608: New client connected from 10.116.7.21 as ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu (c1, k300).
1534023608: Sending CONNACK to ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu (0)
1534023608: Received SUBSCRIBE from ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu
1534023608:     quantity (QoS 0)
1534023608: ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu 0 quantity
1534023608: Sending SUBACK to ^k_aQq];7xigbIUD`htDex>IPfAoNX:4JiUkR9vY9WG[`m`GL[KqZJAk7RaEkkIu

经过一段时间后,客户超过了超时时间并断开了连接。对于克服此障碍的任何建议,我们将不胜感激

1 个答案:

答案 0 :(得分:0)

查看库的源代码意味着,您应该将clientid作为参数传递给代理端口之后的客户端构造函数。

 Adafruit_MQTT_Client(Client *client, const char *server, uint16_t port,
   const char *cid, const char *user, const char *pass):

来自here

例如

WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, "10.116.10.191", 1883, "clientfoo");

另请参阅adafruit的博客post