ESP32 web server initiating HTTP requests to external Rest API?

georgatos7
Posts: 3
Joined: Sat Oct 09, 2021 10:45 pm

ESP32 web server initiating HTTP requests to external Rest API?

Postby georgatos7 » Sat Feb 04, 2023 1:09 pm

Hello, i was wondering if the following is possible...

1) Can an ESP32 running as a web server initiate/make HTTP requests to an external Rest API ?
2) Do i need to set it up both as a server and a client at the same time or can the ESP-IDF Server API initiate/make requests also?
3) Will the traffic for both incoming and outgoing requests be handled (for port forwarding reasons) by the same port ?

As an example think of an ESP32 used in automation with its own WEB UI making HTTP Requests to Shelly products polling sensors or controlling actuators.

Thanks in advance.

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: ESP32 web server initiating HTTP requests to external Rest API?

Postby boarchuz » Sun Feb 05, 2023 3:32 am

1&2. Yes, an ESP32 can have a HTTP server to respond to requests from clients, as well as a HTTP client to send requests to servers. They may speak the same language but these are separate functions with different roles.
3. No, but this isn't a concern. Your typical router firewall will block all incoming connection requests, but not outgoing ones. Think of all the devices on your network that are connected to the internet without any special firewall rules! You don't need to do anything for the client.

georgatos7
Posts: 3
Joined: Sat Oct 09, 2021 10:45 pm

Re: ESP32 web server initiating HTTP requests to external Rest API?

Postby georgatos7 » Sun Feb 05, 2023 9:22 am

Awesome, I was afraid that running server and client together might cause issues or conflicts that would be hard to spot and debug and would need special handling. It's good to know that this isn't the case and that they are both handled gracefully under the hood by esp-idf.

Thank you again, i will soon be giving this a try.

Who is online

Users browsing this forum: Baidu [Spider] and 118 guests