简体   繁体   English

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

[英]Unable to Configure MQTT Client ID using Adafruit MQTT Library

I am utilizing the MQTT library that Adafruit has created, located here , and the library itself works wonderfully - however I am finding myself unable to edit the Client ID or configure the PINGRESP. 我正在使用Adafruit创建的MQTT库,该库位于此处 ,并且库本身运行良好-但是我发现自己无法编辑客户端ID或配置PINGRESP。 The code that I am currently using can be seen below - 我当前正在使用的代码可以在下面看到-

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

When the client connects to the MQTT Broker the client ID turns into a random string of letters, numbers, and symbols, as seen below - 当客户端连接到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

After a duration of time has passed the client exceeds the time out and disconnects.. Any advice on overcoming this obstacle would be greatly appreciated 经过一段时间后,客户端超过了超时时间并断开连接。.克服此障碍的任何建议将不胜感激

Looking at the source for the library the implication is that you should pass the clientid in as an argument to the client constructor after the broker port. 查看该库的源代码意味着,您应该在client端口之后将clientid作为参数传递给客户端构造函数。

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

From here 这里

eg 例如

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

Also see this blog post from adafruit 另请参阅adafruit的博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM