Re: ESP32 no reply: SSL/TLS connection failed (worldtimeapi.org)
Posted: Sat Dec 28, 2024 6:53 am
Hi
Yeah, the string could be a bit confusing.
"GET /api/timezone/europe/brussels HTTP/1.1\r\nHost: www.worldtimeapi.org\r\n\r\n" is the actual string, but I could have explained it a bit better.
I have a variable populated with a bit of your code (coz I was lazy and copied it) and then added the remaining structure.
First off we connect to the server, which in this case is www.worldtimeapi.org (thanks for finding that site, very handy to all I'm sure).
Once connected we then send the GET string as above which is made up of the following in a calculation:-
String variable Send which is already initialised with "GET /api/timezone/europe/brussels" (Send = "GET /api/timezone/europe/brussels")
We then add " HTTP/1.1\r\nHost: " (Send is now = "GET /api/timezone/europe/brussels HTTP/1.1\r\nHost: " )
We then add "www.worldtimeapi.org" (Send is now "GET /api/timezone/europe/brussels HTTP/1.1\r\nHost: www.worldtimeapi.org" )
We then add "\r\n\r\n" (Send is now "GET /api/timezone/europe/brussels HTTP/1.1\r\nHost: www.worldtimeapi.org\r\n\r\n" )
Using another calculation Len=Length$(Send) gives us the length of the Send string (74 bytes: note that \r and \n are single bytes not double so \r\n are two bytes, \r\n\r\n is four). It is very important to use this calculation as you must tell the server exactly how many bytes to expect.
You should try simulating as it allows you to see what is happening in real time. I can step through the chart reading the value of every variable as I go. You could instead enable the UART and send out "Status" messages at key points such as "Connecting to SSID - " before you attempt connecting and then "OK if successful or such like.
I only have this as a "one-shot", needing a reset to rerun the code (pressing button on chip) but you can of course modify to do anything. As the site is free and not for commercial use, there may be restrictions on how many times you will be allowed to connect in a given time frame and it isn't guaranteed to actually be available, but I think it's great for hobby purposes. I think Benj mentioned somewhere in a previous post that the RTC inside the ESP32 wasn't too accuarate, but if updating every hour then it keeps time well enough.
Hope this helps.
Regards
Yeah, the string could be a bit confusing.
"GET /api/timezone/europe/brussels HTTP/1.1\r\nHost: www.worldtimeapi.org\r\n\r\n" is the actual string, but I could have explained it a bit better.
I have a variable populated with a bit of your code (coz I was lazy and copied it) and then added the remaining structure.
First off we connect to the server, which in this case is www.worldtimeapi.org (thanks for finding that site, very handy to all I'm sure).
Once connected we then send the GET string as above which is made up of the following in a calculation:-
String variable Send which is already initialised with "GET /api/timezone/europe/brussels" (Send = "GET /api/timezone/europe/brussels")
We then add " HTTP/1.1\r\nHost: " (Send is now = "GET /api/timezone/europe/brussels HTTP/1.1\r\nHost: " )
We then add "www.worldtimeapi.org" (Send is now "GET /api/timezone/europe/brussels HTTP/1.1\r\nHost: www.worldtimeapi.org" )
We then add "\r\n\r\n" (Send is now "GET /api/timezone/europe/brussels HTTP/1.1\r\nHost: www.worldtimeapi.org\r\n\r\n" )
Using another calculation Len=Length$(Send) gives us the length of the Send string (74 bytes: note that \r and \n are single bytes not double so \r\n are two bytes, \r\n\r\n is four). It is very important to use this calculation as you must tell the server exactly how many bytes to expect.
You should try simulating as it allows you to see what is happening in real time. I can step through the chart reading the value of every variable as I go. You could instead enable the UART and send out "Status" messages at key points such as "Connecting to SSID - " before you attempt connecting and then "OK if successful or such like.
I only have this as a "one-shot", needing a reset to rerun the code (pressing button on chip) but you can of course modify to do anything. As the site is free and not for commercial use, there may be restrictions on how many times you will be allowed to connect in a given time frame and it isn't guaranteed to actually be available, but I think it's great for hobby purposes. I think Benj mentioned somewhere in a previous post that the RTC inside the ESP32 wasn't too accuarate, but if updating every hour then it keeps time well enough.
Hope this helps.
Regards