thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

For general Flowcode discussion that does not belong in the other sections.
ayhan1
Posts: 44
http://meble-kuchenne.info.pl
Joined: Sun Mar 21, 2021 2:13 pm
Has thanked: 18 times
Been thanked: 1 time

thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

Post by ayhan1 »

Hello. I'm trying to learn MQTT. I found answers to my questions in the topic below. Thank you. Based on what I've learned I can use a number value (then a sensor value) on thingboard, hivemq etc. I can't send.

viewtopic.php?t=2949

1- The file I made is attached. ESP32 connects to the internet. But I cannot send any data.
2- I opened both a demo and a free account on Thingboard and hivemq and applied all the settings. I tried to connect in both ways, using or not using a username, but I could not succeed.
4- Can you review the examples and help me where I am doing wrong?
5-I tried all the possible settings one by one for 2 days, but I could not get any results.
Attachments
hivemq.PNG
hivemq.PNG (47.97 KiB) Viewed 3990 times
ESP-32-V1A-THING-X.fcfx
(17.77 KiB) Downloaded 24 times
ESP-32-V1A-HIVEQ-X1.fcfx
(18.15 KiB) Downloaded 18 times

mnfisher
Valued Contributor
Posts: 1411
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 129 times
Been thanked: 697 times

Re: thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

Post by mnfisher »

After much fiddling with this same issue - I;ve just managed to get a n esp32 writing and reading MQTT using ThingSpeak. Hopefully some of the techniques are transferable.
I couldn't get the IOT_Made_easy component to work.
The MQTT_Client component I could connect and publish - and the devil is in the detail.
For example to publish - to "channels/ID_Number/publish" - data is "field1=123&field2=67" for example.

Reading was an issue again - I could get the MQTT_Client to read (Subscribe then ??) - but managed to get NetworkComms to read as using http - and then stripped the json string out of the data returned.

I found chipfryer and MJU's examples and explanations helpful along the way - but really struggled to get the right data for both IOT_Made_Easy and MQTT_Client.

I also hit problems with stack overflow and wdt issues - which required some more tinkering.

Will upload my current code - bear in mind that it is a very rough example - it connects to my test ThingSpeak account. Note one thing that threw me is that although the fields seem to be 'named' - they are still referred to as field1, field2 etc....

Martin

ayhan1
Posts: 44
Joined: Sun Mar 21, 2021 2:13 pm
Has thanked: 18 times
Been thanked: 1 time

Re: thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

Post by ayhan1 »

mnfisher wrote:
Fri Jan 17, 2025 10:39 pm
After much fiddling with this same issue - I;ve just managed to get a n esp32 writing and reading MQTT using ThingSpeak. Hopefully some of the techniques are transferable.
I couldn't get the IOT_Made_easy component to work.
The MQTT_Client component I could connect and publish - and the devil is in the detail.
For example to publish - to "channels/ID_Number/publish" - data is "field1=123&field2=67" for example.

Reading was an issue again - I could get the MQTT_Client to read (Subscribe then ??) - but managed to get NetworkComms to read as using http - and then stripped the json string out of the data returned.

I found chipfryer and MJU's examples and explanations helpful along the way - but really struggled to get the right data for both IOT_Made_Easy and MQTT_Client.

I also hit problems with stack overflow and wdt issues - which required some more tinkering.

Will upload my current code - bear in mind that it is a very rough example - it connects to my test ThingSpeak account. Note one thing that threw me is that although the fields seem to be 'named' - they are still referred to as field1, field2 etc....

Martin
Thank you for your quick reply. I don't understand why it's so complicated. I implemented the example on the Flowcode wiki page exactly. I think flowcode team should make an application that works on this issue.

mnfisher
Valued Contributor
Posts: 1411
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 129 times
Been thanked: 697 times

Re: thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

Post by mnfisher »

This is my sample - I've left in my ThingSpeak credentials (so you should be able to post and read my test account)

You'll need to set the SSID and Password - I just use a hotspot on my phone at 2.4GHz

One issue might be stack size... We'll address that if it occurs (and changing topic / json to global rather than local data would be a fix)

Martin
Attachments
ThingSpeak2.fcfx
(28.73 KiB) Downloaded 23 times

mnfisher
Valued Contributor
Posts: 1411
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 129 times
Been thanked: 697 times

Re: thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

Post by mnfisher »

See also viewtopic.php?p=15818#p15818 for details of posting using NetworkComms instead of MQTT_Client.

Note in the above sample the 'publish' is commented out.... And I removed the code to initialise and connect MQTT_Client - things weren't going well at the time!

Martin

ayhan1
Posts: 44
Joined: Sun Mar 21, 2021 2:13 pm
Has thanked: 18 times
Been thanked: 1 time

Re: thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

Post by ayhan1 »

mnfisher wrote:
Fri Jan 17, 2025 11:00 pm
This is my sample - I've left in my ThingSpeak credentials (so you should be able to post and read my test account)

You'll need to set the SSID and Password - I just use a hotspot on my phone at 2.4GHz

One issue might be stack size... We'll address that if it occurs (and changing topic / json to global rather than local data would be a fix)

Martin
Thank you very much for your help. I have studied your example. But it is quite complicated for a novice like me. I still do not understand why the mqtt example is so complicated. Because on the flowcode wiki page it is shown that it can be done easily using mttt client-Network comms-ESP32 WLAN components. But even though I did the same, I could not send a single data for two days.

mnfisher
Valued Contributor
Posts: 1411
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 129 times
Been thanked: 697 times

Re: thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

Post by mnfisher »

This is the ConnectToMQTT macro...

Martin
Attachments
ConnectToMQTT.fcm
(2.27 KiB) Downloaded 19 times

mnfisher
Valued Contributor
Posts: 1411
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 129 times
Been thanked: 697 times

Re: thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

Post by mnfisher »

I agree - MQTT is supposed to be a simple communications protocol - but I've certainly found it anything but!

Which bits do you not follow - did you manage to compile / run (or in simulation) - I can try and explain the reasoning.

Tomorrow though - time for bed here....

Martin

chipfryer27
Valued Contributor
Posts: 1474
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 347 times
Been thanked: 514 times

Re: thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

Post by chipfryer27 »

Hi
I think flowcode team should make an application that works on this issue.
I think the above is a little unfair as the forum has posts on successfully using MQTT.

I'm a little confused as initially the conversation is regarding Thingsboard / Hive but changes to ThingSpeak.

Numerous posts (some by me) on posting to ThingSpeak, and I really don't believe there is any real issue in using the ESP8266, ESP32, RPi target/component to do so (nor to fetch data from websites using JSON). I can't remember offhand but I am pretty certain I also connected to ThingSpeak using MQTT. I'm sure a search in both this and the old forum will throw up examples.

You can usually use a browser to verify / observe your request to help ensure your credentials are correct. Have you tried that?

I did have issues using ThingsBoard and personally wasn't that impressed with their documentation. It was a few years ago though so it may be better now.

Regards

ayhan1
Posts: 44
Joined: Sun Mar 21, 2021 2:13 pm
Has thanked: 18 times
Been thanked: 1 time

Re: thingsboard, hivemq etc. using ESP32 or ESP8266 MQTT. I failed to send data. What am I doing wrong?

Post by ayhan1 »

chipfryer27 wrote:
Sat Jan 18, 2025 9:12 am
Hi
I think flowcode team should make an application that works on this issue.
I think the above is a little unfair as the forum has posts on successfully using MQTT.

I'm a little confused as initially the conversation is regarding Thingsboard / Hive but changes to ThingSpeak.

Numerous posts (some by me) on posting to ThingSpeak, and I really don't believe there is any real issue in using the ESP8266, ESP32, RPi target/component to do so (nor to fetch data from websites using JSON). I can't remember offhand but I am pretty certain I also connected to ThingSpeak using MQTT. I'm sure a search in both this and the old forum will throw up examples.

You can usually use a browser to verify / observe your request to help ensure your credentials are correct. Have you tried that?

I did have issues using ThingsBoard and personally wasn't that impressed with their documentation. It was a few years ago though so it may be better now.

Regards
I don't think I'm being unfair. I'm wondering why my program isn't working even though I did exactly the same example as on the flow code wiki page. All I want is for the flowcode team to review the programs I added here and tell me where I made a mistake. It would be good for all flowcode users if the Flowcode team created and released a working example for an mqtt broker like hivemq. Best regards.

Post Reply