• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Problem with http.get on ESP32

Q&A Forum › Category: ESP32 › Problem with http.get on ESP32
0 Vote Up Vote Down
jacques asked 4 years ago

I  am surely missing something, but what ? 
This  is my code 

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <HTTPClient.h>

String tempo="http://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter=2021-02-17&TypeAlerte=TEMPO";
http.begin(tempo.c_str());
http.GET();
TERM.println(http.getString());
http.end();
 

If I put directly the string tempo in a brouwser, I get the answer 

{"JourJ1":{"Tempo":"TEMPO_BLEU"},"JourJ":{"Tempo":"TEMPO_BLEU"}}

But in my arduino script on a ESP-Wroom-32

I get
error code 1001

Can you help me ?

Thanks
Question Tags: ESP32 http.get
13 Answers
0 Vote Up Vote Down
Steve Mercer answered 4 years ago

Take a look at https://randomnerdtutorials.com/esp32-http-get-post-arduino/

 

Is that the entirety of your code? To get to the internet over WiFi you need to connect to your router.

0 Vote Up Vote Down
jacques answered 4 years ago

Thanks for the answer, but

I have seen these pages, but  it was not sufficient to help me.  This is why I  Ask on this forum for specific help.
Of course, there  is  additional for the connection to internet through wifi.  I could test that I am well connected and that the problem is not in the connection.

If you think you have a solution, it is very easy to test it on your side, as  the api is open to all. As I said, everything works well if you just put the http sequence in a browser.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
We’ve tried multiple examples and everything we could think of.
However, it looks like the server has some sort of configuration or firewall software that blocks all connections from “unknown” devices (like IoT) devices. If you access it with a normal web browser, it replies. However, it denies all connections from other devices.
Even with a different code that we’ve trying that makes HTTPS requests, all connections are blocked:

[HTTPS] begin...
[HTTPS] GET...
[HTTPS] GET... failed, error: connection refused

So, it seems that you’ll have to use another service to request weather data. For example, you can use OpenWeatherMap.
I hope this helps.
Regards,
Sara
 
 

0 Vote Up Vote Down
jacques answered 4 years ago

Thanks a lot, Sara.
I see that you have really addressed the problem and not just send a standard reply.
I have made some progress on my side, with the help of my son.
The first step was to be able to make the request from a standard unix machine in command line (here a mac) .
One of the problem seems that the server does not accept any kind of user agent. This has been solved by specifying the  user agent. Now at least the following commands  works

curl -A "Mozilla/5.0 Gecko/20100101" "https://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter=2021-02-15&TypeAlerte=TEMPO"

with the correct answer
{“JourJ1”:{“Tempo”:”TEMPO_BLANC”},”JourJ”:{“Tempo”:”TEMPO_BLANC”}}
I have thus updated  the code as follows


String tempo="https://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter=2021-02-17&TypeAlerte=TEMPO";
String user_agent = "Mozilla/5.0 Gecko/20100101";
TERM.println("");
TERM.println(tempo);
http.begin(tempo,nullptr);
http.setUserAgent(user_agent);
http.GET();
TERM.println(http.getString());
http.end();

But this still not works.

Any additional help is very welcome as it is impossible to get this information from another server.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
Do you get the same error even when setting the user agent?
Does that website allow you to set up an account to use an API or something? (I can’t read french, and even with translater, it isn’t easy to understand).
Regards,
Sara

0 Vote Up Vote Down
jacques answered 4 years ago

Yes,  I have still the same error  even with the new code setting the user-agent 
 

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
I’m not sure, but I think that even though you set the user agent, it knows that it is not an actual web browser making the request.
I’m sorry, but I don’t have any more ideas on how to workaraound this issue.
Regards,
Sara
 

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

I had a similar problem here at work (NOT using ESP32) where the server was only sending the server certificate instead of the entire certificate chain. It would work fine in a browser as browsers support the “certificate discovery” feature which will ask the server for the intermediate and root certificates.

You could try adding the certificate chain (Download the chain from your browser) as a string and specifying that in your http.begin (The second parameter is the Certificate Authority Certificate – CACert).

0 Vote Up Vote Down
jacques answered 4 years ago

Thanks Steve,  but I have also tried that. 
The first attempt was putting the NULL pointer as second argument as in the code above , but to be sure, I did it also with  the  certificate chain downloaded from the browser. 
 

0 Vote Up Vote Down
jacques answered 4 years ago

Thanks Steve,  but I have also tried that. 
The first attempt was putting the NULL pointer as second argument as in the code above , but to be sure, I did it also with  the  certificate chain downloaded from the browser. 
 

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

Just looked at the certificate again and it’s using TLS1.2. Perhaps try the WiFiClientSecure library?

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi again.
Thanks for trying to help, Steve.
I have tried previously with this example with the right certificate, and the connection was refused:
https://github.com/espressif/arduino-esp32/blob/master/libraries/HTTPClient/examples/BasicHttpsClient/BasicHttpsClient.ino
It uses WiFiClientSecure. So, no luck with this, too :/
Regards,
Sara

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

I guess at this point I’m at a loss. I have no idea what’s going on. If it’s only that site then they must have done something strange.

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.