Page 3 of 4

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

Posted: Tue Jan 21, 2025 12:18 am
by chipfryer27
Thank you for your help. But I don't understand why this process has to be so complicated.
I don't think it is.

If you take the time to examine the requirements for each of the various vendors you mention you would see differences.

Once you understand the requirements you can use the components.

ThingSpeak is in my opinion very, very user friendly.

Have you created an account? If so have you used a browser to update fields and to read fields? Have you read their documentation on how to connect/publish/subscribe using API Keys and MQTT? If you haven't done that to understand how it works, you can't really expect much success.

There isn't anything difficult and the WiKi example(s) work fine if you use them correctly. Indeed I just modified the "Subscribe using ESP8266 example" to subscribe and fetch TS data. It sits there apparently doing nothing until data gets posted then if by magic the value appears on the display. That took about ten minutes to modify and get a reading returned, mainly as I did not have my credentials to hand and I wanted a specific pair returned. Using my browser I can update my TS channels and as FC allows me to simulate, the chart then prints the value of interest.

Screenshot 2025-01-21 000310.jpg
Screenshot 2025-01-21 000310.jpg (138.08 KiB) Viewed 3534 times

I haven't included a chart as it is essentially the same as the WiKi, except with my specific credentials and a modified "print" statement.

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

Posted: Wed Jan 22, 2025 8:58 pm
by mnfisher
Just to confirm that Thingsboard works well with the FC MQTT Client.

You'll need to create a device - and get it's credentials. Set the client identifier, name and password in MQTTClient properties. On 'Connect' it should change from Inactive to Active. As Iain said - that isn't so bad....

Posting data needs "v1/devices/me/telemetry" as the topic and a json value as the payload..
For example - "{\"Temperature\": 12}"

Set a panel on a dashboard and all is good..

Thanks to Iain (and MJU) for the excellent examples...

Martin

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

Posted: Wed Jan 22, 2025 9:25 pm
by chipfryer27
Hi

Thanks for the ThingsBoard update. I'd kind of lost interest in it as ThingSpeak is so easy to implement.

When I get time I might revisit, espesially as I can host my own version on a RPi and move forward with my half-bake-idea-ry RPi projects :) In saying that the WiKi RPi mqtt server does look quite light, so may be better. I'll update if/when I implement.

Regards

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

Posted: Sun Feb 02, 2025 3:26 pm
by ayhan1
Hello again. It's me again :)
I was able to connect to public (free) hivemq and emqx mqtt brokers with flowcode and I can send data (For example broker.emqx.io port:1883). But I can't connect as private mqtt, password etc. everything is correct (For example my broker address is y131ffc0.ala.eu-central-1.emqxsl.com port:8883)
I researched a lot why this is happening and examined their own sample codes. At first I couldn't connect with their own samples either. But then I found the solution. There is a certificate code in the code (in the name of the ca certificate). When I changed that code to my own ca certificate code, the connection was established.

Now I think the problem is caused by this certificate code.
How can I add this ca certificate code in FLOWCODE?

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

Posted: Tue Feb 04, 2025 10:12 am
by Steve-Matrix
Thanks for the question.

Flowcode does not currently support client-side certification for MQTT applications, but we are looking into this.

There may be settings in the MQTT server (broker) that you use that allow 1-way TLS certification (i.e. server-side certification) which may provide a partial solution.

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

Posted: Mon Feb 17, 2025 9:53 am
by mnfisher
On the esp32 - there is a MQTT library. It would be fairly easy to use that - and it supports extra features such as certification, Last Will and Testament messages etc...

Martin

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

Posted: Mon Feb 17, 2025 5:31 pm
by ayhan1
mnfisher wrote:
Mon Feb 17, 2025 9:53 am
On the esp32 - there is a MQTT library. It would be fairly easy to use that - and it supports extra features such as certification, Last Will and Testament messages etc...

Martin
Is this library you mentioned available in flowcode?

NOTE: I found an interesting solution. I printed the code I wanted using the Arduino ide with the help of Chatgpt and Deepseek and it works great.

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

Posted: Mon Feb 17, 2025 10:04 pm
by mnfisher
Maybe - it could certainly be used as the basis for a FC component.

I managed to get it up and running - and connected to a topic this evening. So, at present, just printing the data posted when a value is published.
Need some more work yet - to allow secure connections, post data etc - but it works AOK. It's very rough and ready at the moment (it only supports 'connected' and 'published' events - so I'll polish it a bit more before posting...

And - yes - I used chatgpt for some help too!

Martin

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

Posted: Wed Feb 19, 2025 9:33 pm
by mnfisher
So - if anyone would like to play...

This is a very simple demo program using the esp32 thingspeak component. There are some advantages to using this - it supports secure connections and mqtt v5 (though not here!) for example.

However - as it stands this should be known as IOT_Made_Less_Than_Easy.

Actually it is easy to set up for thingspeak - the broker address is set (a global variable) and you'll need to set the channel id, the username and password (from thingspeak mqtt devices (username is actually ClientID)). Also set your SSID and password in the wifi connect :-)

Then compile and open a UART to the esp32 using PuTTY or your terminal program of choice.

Here - after connecting (mqtt_start) - the mqtt client runs on an event driven basis - I've only implemented a very basic handler for connect (subscribe to the channel - field1) and data (display the data) (although it displays a message for each event)

The main program loop just publishes data to field1 every 10s - incrementing by 13 every iteration. It does demonstrate how a program can run - and only perform an action on an event). It is perhaps a mistake to have print statements in the main loop and event handler - as an event could possible occur in the middle of the 'main' print. However for this demo it is a risk I am prepared to take...

You can experiment - setting qos / retain or adding other fields as required.

Martin

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

Posted: Wed Feb 19, 2025 10:33 pm
by ayhan1
Actually you don't need to do this. The standard mqtt example given in the flowcode examples can already connect to port 1883 and send data without a username and password. The problem is that I cannot connect to mqtt broker with flowcode by entering username and password using port 8883.

NOTE:
With the mqtt example given in the flowcode wiki, I can send and receive data to the test server using port 1883 of brokers such as hivemq.