Req: ESP32 read website example

For general Flowcode discussion that does not belong in the other sections.
MJU20
Posts: 244
http://meble-kuchenne.info.pl
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Req: ESP32 read website example

Post by MJU20 »

Is there an example of how to read a website with the ESP32 chip?

All I want to do is read a website (like: https://api.thingspeak.com/channels/466 ... tatus=true ) and process the returned data.

I did this before in version 6 with the ESP8266 but can't find the "ClientSendRequest" version for the ES32.
This request (fake one), returns a text which I want to search for a certain string, and return the value behind this string.

So:

Code: Select all

{"created_at":"2022-07-07T16:32:20Z","entry_id":2198,"field1":"217.1","field2":"525.2","field3":"103.0","status":"MQTTPUBLISH"}
Needs to be spilt to the values behind "field1":" and "field2":" and so on...

Any examples of how to do this?
Thanks!

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 284 times
Been thanked: 412 times

Re: Req: ESP32 read website example

Post by chipfryer27 »

Hi

In the v8 forum I've been playing with ThingSpeak using an ESP8266 and a SIM800 module. Quite straightforward to read from ThingSpeak by just modifying key etc. I think it can also be accessed using MQTT but I haven't tried it yet.

I've only just started playing with the ESP32 in FAD so I'm no expert. I may be wrong but perhaps you need to use the ESP32 component and the Network Communications component (or MQTT)?

I'll try and have a play at the weekend, but I'm sure somebody will give far better advice before then :)

Regards

MJU20
Posts: 244
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Req: ESP32 read website example

Post by MJU20 »

Hey thank you chipfryer!

I've altered the MQTT subscribe Flowcode from the Wiki (https://www.flowcode.co.uk/wiki/images/ ... P8266.fcfx) and I can connect and subscribe..

But then.. The data isn't always received from the MQTT broker.
Most of the time I receive 1 or just a few updates from the broker and then it stops.
Why? I don't know.

So I think that it's better to get the receiver to periodically get the values itself by requesting the latest measurements (see first post).

Why the MQTT component doesn't receive updates is a mystery. Could the be because the QOS = 0?

So I'm looking to "GET" the values by an HTTP request.

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 70 times
Been thanked: 217 times

Re: Req: ESP32 read website example

Post by LeighM »

An MQTT connection has a timeout, which you can reset with an MQTT PING command to keep it alive. Otherwise you have to reconnect. This could be your issue. Also, as you say, I think on QoS 0 you will only get updates when they are Published.

MJU20
Posts: 244
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Req: ESP32 read website example

Post by MJU20 »

LeighM wrote:
Fri Jul 08, 2022 5:07 pm
An MQTT connection has a timeout, which you can reset with an MQTT PING command to keep it alive. Otherwise you have to reconnect. This could be your issue. Also, as you say, I think on QoS 0 you will only get updates when they are Published.
Thanks LeighM.
Do you think there is a minimum time needed between 2 pings? How many pings are appropriate in a certain timespan?

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 70 times
Been thanked: 217 times

Re: Req: ESP32 read website example

Post by LeighM »

The keep alive period can be set to anything you want when you establish the client connection, but typically 60 seconds.

MJU20
Posts: 244
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Req: ESP32 read website example

Post by MJU20 »

Things are getting to work.. thanks for your help!
I will share my project (like I always do :-) in the near future.

But still I'm looking for an example to read the response from a request like asked in my first post in this topic.

I can't find how to "ClientSendRequest" like I've used before to get a response..
What component do I use?

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 284 times
Been thanked: 412 times

Re: Req: ESP32 read website example

Post by chipfryer27 »

Hi

What service are you intending to connect to? Many out there such as HiveMQ / ThingSpeak etc. Same but different. Are you going to use the ESP32 or the 8266 from earlier?

I created an account with HiveMQ but have trouble using the CLI for Windows. Good chance that's due to attempting connection late at night, lengthy keys and Leffe....

Regards

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 284 times
Been thanked: 412 times

Re: Req: ESP32 read website example

Post by chipfryer27 »

Hi MJU20

My first attempt at getting an ESP32 to do something so forgive the crudeness. FC made this quite easy, so thanks Matrix :)

Over in the v8 forum I documented updating a ThingSpeak channel using RS232 and an ESP8266 and SIM800 using "GET" etc. When using these commands you need to tell your device how many bytes you are about to send including CRLF etc as I'm sure you know as you are already using ClientSendRequest.

Someone with better knowledge than I may have a better way, but the attached chart works for me to update a ThingSpeak channel with a value using an ESP32. It is very basic with no checks to see if you are connected to your WiFi or the like.

You will of course have to supply your own credentials.

I appreciate it isn't using MQTT but as you just want an example of sending something, hopefully this will give you some pointers and "GET" you started :)

Regards
Attachments
ThingSpeak_ESP32_Example.fcfx
(10.3 KiB) Downloaded 52 times

MJU20
Posts: 244
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Req: ESP32 read website example

Post by MJU20 »

Hey chipfryer27, thank you very very much.

Me too succeeded in publishing things to Thingspeak.
I have a ESP32 running and updating a channel every 5 minutes with data.

I can read the data in a web browser but I want to display it with a subscribed MQTT client which at this moment is running smoothly.
Have to finetune the flowchart and stretch some parameters a bit but I will share it later.

I use the Wiki a lot, but some components are documented very briefly.
Sometimes my problems (and believe me, at the time I ask things on the forum, I've been testing things a loooong time), are solved by asking this on the forum.

Now I've boiled one piece down, now I can start with part 2.

The reason I want to read it via the GET is that this also sends a timestamp.
Thanks again, will respond further later (it's late at night)

Post Reply