ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

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

Flowcode v10 ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

Post by MJU20 »

I'm trying to get a time from worldtimeapi.org (port80) -via a GET worldtimeapi.org/api/timezone/europe/brussels\r\n\r\n in the NetworkComms "Send" macro-.
But this does not return a valid JSON value.

I've been testing and used CURL to test the connection and get this return:

Code: Select all

C:\Windows\System32>curl -v "https://worldtimeapi.org/api/timezone/europe/brussels"
* Host worldtimeapi.org:443 was resolved.
* IPv6: 2a09:8280:1::3:e
* IPv4: 213.188.196.246
*   Trying [2a09:8280:1::3:e]:443...
* Connected to worldtimeapi.org (2a09:8280:1::3:e) port 443
* schannel: disabled automatic use of client certificate
* ALPN: curl offers http/1.1
* schannel: failed to receive handshake, SSL/TLS connection failed
* closing connection #0
curl: (35) schannel: failed to receive handshake, SSL/TLS connection failed
This seems to be something with SSL/TLS connection?
I've tried port 443 in FC10 but this also gives me an empty reply..

What can I test further to get a reply from worltimeapi.org?
(I don't have my flowchart here with me so can't upload the testfile)

chipfryer27
Valued Contributor
Posts: 1575
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 560 times

Re: ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

Post by chipfryer27 »

Hi

Generally speaking, I think most microcontrollers would struggle with the HTTPS protocol's encryption process due to their limited resources. Many websites do not enforce the protocol though and still allow access via HTTP. It appears that the website you are using allows HTTP so perhaps try using GET to reach http://worldtimeapi.org/api/timezone/europe/brussels

Hope this helps.

Regards

EDIT...

http://worldtimeapi.org/pages/faqs

If you scroll down the questions you will see
Some IoT devices struggle with HTTPS connections, and the data we return isn't sensitive, so standard HTTP requests to the API are the default.
So if you just use http: you should be good.

MJU20
Posts: 341
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 94 times
Been thanked: 69 times

Re: ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

Post by MJU20 »

Thank you again Chipfryer27.

I've been testing a lot, and all kinds of configurations.
The connection to port 80 for this server was tested before and worked... sometimes :-) (story of my life)

Then I send the GET request, but this does not return any valid reply. None that I can work with.

I've edited a file that I used in the past with another GET request that worked.
I sometimes struggle to get the length of the GET right, I take the length of the string and take 4 off (the GET and the space).

As attachment a file that was edited to receive date from worldtimeapi.org.
I know it's a mess, but this should be clear of what I'm trying to do...
I really someone can help me with this one...
TestOpenTimeFC.fcfx
(27.27 KiB) Downloaded 72 times

chipfryer27
Valued Contributor
Posts: 1575
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 560 times

Re: ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

Post by chipfryer27 »

Hi

I'll have a look once I get a chance (bit busy just now assisting Jorgen as he nips around the world :lol: ).

I usually create a string for my GET requests etc and use the Length$() function to obtain the length.

Flowcode can simulate all of this so it shouldn't be too hard to figure out without hardware. I just need to refresh my memory first (guy's have a fixed amount of memory that acts like a circular buffer. Once full if we need to remember something new we need to forget something else. As I have seen Hally Berry as Catwoman I won't risk remembering Network stuff :lol: )

Regards

chipfryer27
Valued Contributor
Posts: 1575
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 560 times

Re: ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

Post by chipfryer27 »

Hi

See attached.

I used a Pi for simulating this but you should be able to change target. It is rough, as am I at present, and is quite basic. You should consider adding in checks to see if connected to SSIDs etc (if using WiFi). I only simulated so you will need to change things to suit.

Things to look at are how we connect, then what we send as our GET. I can explain it further if needed but not today <s>

The reply from the website is quite long at just under 1200 bytes so you need a device capable of storing this big a string. or once you are confident just grab the first x-bytes of valuable data, ignoring the rest.

I then asked for the first four JSON pairs, which are timezone/day_of_week/day_of_year/datetime.

If you simulate it you should see the values in the Simulation debugger, assuming of course your PC is connected to the internet and you have set up the Network Interface correctly in the Network Comms component (go through options until an IP address appears).

I have it running once then entering an endless loop so as to keep the debugger displayed. I'm sure you will modify to suit.

Once you have it running on your setup please share.

Regards

EDIT...

Noticed that at peak times it didn't connect. Increasing delay solved.
Attachments
MJU20_Time_Machine.fcfx
(17.05 KiB) Downloaded 78 times

MJU20
Posts: 341
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 94 times
Been thanked: 69 times

Re: ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

Post by MJU20 »

Thanks Chipfryer27 but I can't replicate the response.

I've been changing the GET request to test it live on a ESP32, but the response is empty most of the time.
This is strange because with other projects where I use a GET, this works fine.

I've been sending these codes, in different combinations to the server but no good response from the server.

Code: Select all

//   SendTXT = " HTTP/1.1\r\nGET "
//   SendTXT = SendTXT + "/api/timezone/europe/brussels"
//SendTXT = SendTXT + " HTTP/1.1\r\nHost: www.worldtimeapi.org"
// SendTXT = SendTXT + "\r\n\r\n"

//Host: worldtimeapi.org

SendTXT = " HTTP/1.1\r\nHost: www.worldtimeapi.org\r\n\r\n"
I manage to not get errors after sending these commands, but there is also never a readable response.
Then I tried to change the length parameter for the SEND macro. After a lot of testing, I get a response (length of the received data), but can never duplicate this parameter.

I need to search further.

I will gladly share the project when I get it to work..

chipfryer27
Valued Contributor
Posts: 1575
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 560 times

Re: ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

Post by chipfryer27 »

Hi

I just downloaded the file, and ran it in simulation. Worked first time and gave me the time in Brussels
Screenshot 2024-12-26 174940.jpg
Screenshot 2024-12-26 174940.jpg (108.79 KiB) Viewed 2370 times
If I get a chance later I'll try it with an ESP32 and in hardware.

Regards

chipfryer27
Valued Contributor
Posts: 1575
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 560 times

Re: ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

Post by chipfryer27 »

Hi

Just modified to run on a 32

ESP32.jpg
ESP32.jpg (107.95 KiB) Viewed 2365 times
MJU20_Time_Machine_ESP32.fcfx
(17.2 KiB) Downloaded 76 times

Not tried in hardware yet, nor have I included any checks to see if connected etc, just simulation, which returns time etc.

After I connect to www.worldtimeapi.org, this is my send string =
"GET /api/timezone/europe/brussels HTTP/1.1\r\nHost: www.worldtimeapi.org\r\n\r\n"

Length of above is 74 bytes

Regards

chipfryer27
Valued Contributor
Posts: 1575
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 560 times

Re: ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

Post by chipfryer27 »

Hi

Found a lolin-lite hiding in a corner.

Ran this

MJU20_Time_Machine_ESP32.fcfx
(23.91 KiB) Downloaded 70 times

Basically, it connects and sends a GET string. Works fine for me.

You will need to enter your SSID and password but other than that it is quite straightforward. I had no display to hand and although I could faff around with the UART to display messages, I chose the lazy route and:-

Once connected to your SSID the on-board LED flashes once.
If it receives valid data it flashes the on-board LED three times.

If simulating you will need to make ret = 1 when it enters the connect to SSID loop (or just disable the loop), and you can see the returns as before.

Regards

Edit...
Bit bored and as I've already taken my Corby Trouser Press to bits, I modified the above to throw out the values over the comm port you use to program. If you run a terminal program after you program the chip, and reset/reboot the chip you will see all sorts of data being dumped then at the end you should see the time zone, day of week / year and date & time

MJU20_Time_Machine_ESP32_uart.fcfx
(29.46 KiB) Downloaded 70 times

MJU20
Posts: 341
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 94 times
Been thanked: 69 times

Re: ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)

Post by MJU20 »

Dear Chipfryer27..

Once again, thank you so much, but for some obscure reason, it’s still not working.
It’s confusing because you’re using this code in your FC10 chart.

Code: Select all

Send = Send + " HTTP/1.1\r\nHost: "
Send = Send + "www.worldtimeapi.org"
Send = Send + "\r\n\r\n"
but in your explanation, you talk about this code:

Code: Select all

"GET /api/timezone/europe/brussels HTTP/1.1\r\nHost: www.worldtimeapi.org\r\n\r\n"
I have the impression that something isn’t right with the length of the transmitted data (either that or the timing is off).

I’ll start again from scratch tomorrow if I have time.
Also, I never use simulation; I run everything directly on the microcontroller.

The strange thing is that I do have other projects running here that work.
This is a stripped-down projects that have proven to work, and I’m using those to get this project working. But retrieving the time is still something that keeps holding me back.

Post Reply