Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TBPubSubClient.h conflicts with PubSubClient.h #165

Closed
J-rethinkmx opened this issue Nov 21, 2023 · 17 comments
Closed

TBPubSubClient.h conflicts with PubSubClient.h #165

J-rethinkmx opened this issue Nov 21, 2023 · 17 comments

Comments

@J-rethinkmx
Copy link

Any suggestions on how TBPubSubClient.h which defines the PubSubClient class and the original PubSubClient can coexist within a single project?

Having both libraries installed creates multiple instance linker errors, while changing includes around creates a bunch of maintenance and version/compatibility level issues.

Why wasn't the new new class just called TBPubSubClient?

Thanks
John

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Nov 21, 2023

It was done like this so there is no need to change any code for the users, but simply to include the TBPubSubClient library instead of the original PubSubClient. This was done because the TBPubSubClient can be interchangeable used as the PubSubClient.

The only difference is a small but important fix that wasn't merged into the main repository, because it is more or less dead.

So simply do not install the original PubSubClient and change your includes from #include <PubSubClient.h> to #include <TBPubSubClient.h> and all your code should still work perfectly, because the internal class name and the implementation is nearly the same.

@J-rethinkmx
Copy link
Author

I see that, however many and 4 libraries I'm using would need to be updated. Granted small changes. however any lib updates would need to have those updates made again.

I just created a PubSubClient.h which just includes TBPubSubClient.h and dropped this into the TBPubSubClient library directory. I then removed the original PubSubClient library. All seems to work okay. You may want to consider this in your next build as the impact is zero.

John

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Nov 22, 2023

I'll create a pull request for this change in the ThingBoard fork of the PubSubClient and update the internal library files and the examples accordingly. Will probably be included in the next release.

@sirapol
Copy link

sirapol commented Dec 1, 2023

This case is solve or not ?

I still found this issues.
I try to change
// #include <TBPubSubClient.h>
#include <PubSubClient.h>

in Arduino_MQTT_Client.h

It work!!!

Someone please fix it.
I newby for github.

@TPCQitek
Copy link

TPCQitek commented Dec 5, 2023

Hi, can I ask what versions of ThingsBoard are people using?
I have been using. 0.6.0 and using MQTT to send data, (in a large project, for some time)
In November I started to update MQTT and also use IDE 2.2 (general end year updates), I had noted the Ver of the main LIB etc and had backups. but things went downhill from there.

During the updates I used 11.1 Thingsboard, and tried 12.0 and earlier versions.

I started getting these Multiple redefinitions of the PubSubClient. and issues with MQTT. which appears to be a current topic. I cleaned up the library (default) folder and removed PubSubClient, but the compile fails still. (Redefinition and MQTT errors. )

I tried to "go back to the beginning" and recompile the current Examples. But also run into errors (much the same). MQTT not recognized etc, cannot compile.

So, what versions of ThingsBoard are the examples based on?

Is there any information or other specific Ver LIB I need to set?

thanks in Advance.

@MathewHDYT
Copy link
Contributor

The examples of the library are updated, according to the version so the current changes of the library are always shipped with the newest up to date working examples.

Additionally the library always ships with its examples so you can simply open the examples folder in your project and look at the examples in there, because those should compile.

Using the examples of this page however with older versions won't work, especially if there were breaking changes.

@TPCQitek
Copy link

TPCQitek commented Dec 6, 2023

MathewHDYT

thanks for the reply. (background: I have used this for some years now, and reasonably all ok, but recently (late Nov) I have this PubSubClient and other MQTT issues. It's quite a complex project and has really been working fine. up to now, I just simply can't compile the complete project, it's about 3mB BIN.) I have not ever had this much of a problem. It's been a few weeks, at least.

I have the LIB all updated, including the ThingsBoard12.0.

I have on the TBPubSubClient in the Library folder. See screen Shot attached) not PubSubClient.

Additionally, this test was the example: 0010-esp8266_esp32_rpc with only the SSID and KEY and TB / TOKEN
no other change.

Also Attached is the Error file from the compile. and the library screen shot.

I had installed the IDE 2.2 as I have been using the 1.6 and then 1.8.18 IDE as that was fine for what I needed. But I uninstalled the 2.2 as the compile (end if Ping Time out) was taking 15 min or more, previously the compile was a minute or so, not significant. But now with the PubSub redefinition errors, it is taking also 5 min, which suggests a problem. See that attached file.

Arduino 1.8.18 (Windows 10), Board Error list 06Dec2023.txt

Library as of 05Dec2023

I would really appreciate some assistance; this has been going on a and is well past being fun.

thanks, TPC.

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Dec 6, 2023

Sorry for the inconveniences caused.

Your TBPubSubClient needs to be on the newest version, that should fix the aforementioned issue. Simply reinstall it from the Arduino libraries and additionally ensure to change the include from #include "TBPubSubClient.h" in Arduino_MQTT_Client.h to #include "PubSubClient.h".

This will be fixed as well once the pull request has been merged and the newest hotfix released as v0.12.1.

@TPCQitek
Copy link

TPCQitek commented Dec 6, 2023

MathewHDYT OK
that achieved a complete compile on Example 0010 type. tick..
I will progress work to compile the main system further.
thanks for that. Cheers.

@MathewHDYT
Copy link
Contributor

@imbeacon Can be closed because the most recent version fixes the aforementioned issue, because PubSubClient has been renamed. To not cause redefinition issues.

@kommando828
Copy link

I have had a problem building this Github

https://github.com/darrylb123/ESP32_SMA-Inverter-MQTT

which may be related to this release. Not a programmer so if someone wants to look at it and see if its the program or the library that is the issue. I fixed the build problem by renaming the ref TBPubSubClient.h to PubSubClient.h in the identified file from the error message.

Error message in VSCode Platformio and Gitpod running in Chrome

src/ESP32_SMA_Inverter_App.h:9:10: fatal error: TBPubSubClient.h: No such file or directory

Platformio.ini entry for libraries

lib_deps =
bblanchon/ArduinoJson@^6.21.3
#knolleary/PubSubClient@^2.8
https://github.com/MathewHDYT/pubsubclient
https://github.com/esp32m/logging.git

VSCode and Gitpod build output ref these libraries

Dependency Graph
|-- ArduinoJson @ 6.21.4
|-- TBPubSubClient @ 2.9.3+sha.5b3177f
|-- ESP32 logger @ 1.0.3+sha.f296e5d
|-- BluetoothSerial @ 2.0.0
|-- WebServer @ 2.0.0
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- LittleFS @ 2.0.0
|-- Preferences @ 2.0.0

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Dec 21, 2023

@kommando828 That is correct the #include <TBPubSubClient.h> has been renamed. I'm not sure the program ever compile tough, especially with the currently configured platformio.ini file.

Because currently it does not install the ThingsBoard fork of the PubSubClient which was changed, but instead my fork. In which the name of the file is still PubSubClient.h.

The fix is probably to simply use https://github.com/thingsboard/pubsubclient#v2.9.1 in the platformio.ini instead of the https://github.com/MathewHDYT/pubsubclient library. This would remove the need to adjust the #include to PubSubClient insead of TBPubSubClient

@kommando828
Copy link

kommando828 commented Dec 21, 2023

I will try the fix, but once I applied my fix it does compile and runs correctly sending out MQTT messages.

Applied your suggested change to the platformio.ini and the build was successful.

Thanks for clarifying the issue.

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Dec 21, 2023

Yeah sorry for the confusion. What I meant is the aforementioned fix should work as well. But of course you can also simply rename the #include to PubSubClient.

@TPCQitek
Copy link

kommando828
MathewHDYT

Mathew I can confirm my builds are ok now, I had edited the file, but assume the roll up to ver 12.02 has included that now and the compile is OK.

I am using the includes (and other unrelated)

#include <ThingsBoard.h>
#include <Arduino_MQTT_Client.h>

@TPCQitek
Copy link

TPCQitek commented Dec 21, 2023 via email

@MathewHDYT
Copy link
Contributor

@TPCQitek I am really confused what mean?

What do you mean with the roll up dates went pear shaped?

What do you mean with MQTTSend and what do you mean with reverting it into a JSON packet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants