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. The code that I am currently using can be seen below -

WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, "", 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 -

1534023607: Client ]7llG5K6J4=^tPHJHqgTUFc<Ep^m3vJ`4vSL2oB<cO[^_chw[GBp]v3smagpOqWS has exceeded timeout, disconnecting.
1534023608: New connection from on port 1883.
1534023608: New client connected from 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. I've tried the following for changing the ClientID, per the client constructor to the MQTT broker -

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

WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, "", 1883, "Rear-Controller");

This was the result of adding the clientID, ("Rear-Controller"), after the MQTT Broker port # -

 New client connected from as GFONMktFXFSG1rARE@JWCRv@P^XwLifdo<rCg]YFs4Ndf_>2_XIsjFsAtS08Cf\: (c1, k300, uRear-Controller)

1 Answer 1


The Client ID is expected to be stored in flash memory (it is read using pgm_read_byte). However, on the Arduino, unless told otherwise it first copies the string literal into RAM. That means that the function is getting the address of the string in RAM, not in flash, and using it as if it were the address in flash, and that gets gibberish.

You need to force it to be in flash by creating a PROGMEM string:

const char clientid[] PROGMEM = "clientfoo";
Adafruit_MQTT_Client mqtt(&client, "", 1883, clientid);
  • I was met with this error: No matching function for call to 'Adafruit_MQTT_Client::Adafruit_MQTT_Client(WiFiClient*, const char [14], int, const __FlashStringHelper*)'
    – HobarGJ
    Aug 12, 2018 at 22:10
  • Not having your code to test I did wonder if that may happen. You may need to cast it to a const char * as well. Or have it separate as PROGMEM.
    – Majenko
    Aug 12, 2018 at 22:20
  • I converted it to a const char and it successfully compiled, however it still had the gibberish.. That only seems to effect - "(c1, k300, uRear-Controller)"
    – HobarGJ
    Aug 12, 2018 at 22:31
  • @HobarGJ See my edit. That should work.
    – Majenko
    Aug 13, 2018 at 0:03
  • While that did successfully compile, I am still getting the string of gibberish when connecting to the MQTT Broker. The end, "(c1, k300, uRear-Controller)", is correct and reflects the changes though. Would uploading more of my code be any easier for you?
    – HobarGJ
    Aug 14, 2018 at 2:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.