Include ThingsBoard PubSubClient

PubSubClient hasn't been updated since 2020 and doesn't work.

However, ThingBoard have a fork that is being maintained: GitHub - thingsboard/pubsubclient: Fork of a client library for the Arduino that provides support for MQTT.

The Library Manager can install the ThingsBoard version which appears as TPPubSubClient and gets put at

libraries\TBPubSubClient\src

but

#include <PubSubClient.h>

uses the broken old version.

Both files are called PubSubClient.h.

How do you get a sketch to use the ThingsBoard version?

That is a very sweeping statement

What exactly "doesn't work"

Which version of PubSubClient are you using ?

Version 2.8 from 2020.
It can publish, but subscribe never receives anything.

The last time I tried it worked OK for me

Delete the version that you don't want from the sketchbook libraries folder or use the Library Manager to remove it

I would be interested in hearing the results of trying the TBPubSubClient version

Shh don't tell my computer, it is and has been using PubSubClient for a few years along with a few hundred other folks.

The Library manager doesn't have an option to remove PubSubClient.

Deleted the folder.

Still not receiving messages, so the ThingsBroard version is broken too.
I guess you get what you pay for.

Gut feeling is that it's something to do with timing and loop because if you spam the topic really fast then sometimes a message gets through.

A workaround is to run this on debian to read the topic and expose it to the network.

while true; do nc -l -p 1884 -q 1 -c "mosquitto_sub -h localhost -t \"foo/bar/buz\" -C 1 -F \"%p\"" ; done

and then read it in the Arduino like this

     // Try to get the new temp.
      wifi_client.connect("192.168.0.113", 1884);
      delay(500);
      bool waited = 0;
      for(int i=0; i < 12 && (!wifi_client.connected() || !wifi_client.available()); i++){
        Serial.print(i);
        Serial.print("... ");
        delay(500);
        waited = true;
      }
      if( waited ){ Serial.println(); }
      StaticJsonDocument<32> jDoc;
      if (wifi_client.available()) {
        deserializeJson(jDoc, wifi_client);
        foo = jDoc["foo"];
        Serial.print(current_foo);
        Serial.print(" -> ");
        Serial.println(foo);
        if(foo> 0 & current_foo == 0 ){ current_foo = foo; }
      }
      else {
        Serial.println("No data from 1884");
      }
      wifi_client.stop();

A problem with this is that you can only see the latest retained message on the topic in MQTT therefore the value must represent the desired state rather than an instruction to change state; comparing foo to the current_foo determines whether an action must be taken.

I am willing to bet that it isn't

Please post your full sketch that does not receiev data from MQTT

1 Like

The capability was added in Arduino IDE 2.x, but if you are still using Arduino IDE 1.x then indeed the Library Manager didn't provide an uninstall capability at that time and the only way to uninstall libraries is by manually deleting their installation folder as you did.

Which version of the IDE are you using ?

Are you calling PubSubClient::loop

in your loop, as shown in the examples?