How to send data from website to Arduino ESP32

Is it possible to send JSON payload to ESP32 from website ?

It is possible to make an HTTP request from the ESP32 and read the response from your HTTP website on your Arduino ESP32.

This is a basic HTTP request to get you started. arduino-esp32/BasicHttpClient.ino at master · espressif/arduino-esp32 · GitHub

The Arduino JSON library works well to parse your JSON. https://arduinojson.org/

@Thee_Captain, thank you. Information you have shared is to make request to external website, in this case to Example Domain.

I am looking for sending payload from external application (Example Domain) to Ardunio.

MusicianTeen:
@Thee_Captain, thank you. Information you have shared is to make request to external website, in this case to Example Domain.

I am looking for sending payload from external application (Example Domain) to Ardunio.

How do you plan to receive the payload from your arduino?

MusicianTeen:
@Thee_Captain, thank you. Information you have shared is to make request to external website, in this case to Example Domain.

I am looking for sending payload from external application (Example Domain) to Ardunio.

String payload = http.getString();

This contains the HTTP resppnse from your website. Your endpoint should contain your JSON string.

It is not really advised to initiate"sending" things from "websites." HTTP doesn't really work that way. There are things like push notifications that are initiated by the server, but these are not native HTTP and usually requires a service from iOS or Android. Here is W3C's push API: Push API

I think using push notifications is not the solution to most problems. Most problems require a client to request the resource.

Maybe if you explain your project, it would become more clear what solution you need.

thank you @Thee_Captain

I am beginner with Arduino. I am working with ESP32 board and have connected that to my local wifi and have local ip address. How do I access this ESP32 over internet - externally from servers not connected to local wifi ?

You have to set a port forwarding from you modem to your ESP32 IP

lesept:
You have to set a port forwarding from you modem to your ESP32 IP

And you must have a public IP address(you shouldn't be behind a NAT) and this IP should be static. You can ask these from your ISP.

If you can't do the above it's really much easier to just periodically poll the server via the ESP and not the other way around.

If server->ESP connection is an absolute necessity you can try maintaining a TCP connection between the two then the server can send data to ESP at any time.
However for this you have to write a program for the server and on both your server and ESP you should have good code that handles disconnecting/reconnecting to make sure connection is never lost. Also you'll probably need a Virtual Private Server for this.

MusicianTeen:
thank you @Thee_Captain

I am beginner with Arduino. I am working with ESP32 board and have connected that to my local wifi and have local ip address. How do I access this ESP32 over internet - externally from servers not connected to local wifi ?

So I wouldn't try to "access the ESP32" from outside the local network. I would access the server on the outside external network from my ESP32 using an HTTP GET request. Then I would read the response from the server that is on Thee Internet.

Local ESP32 sends GET Request to www.example.com/json/id/21.html
www.example.com responds with a JSON text string to your ESP32
Local ESP32 reads, parses and handles the JSON response body

In most cases this client server paradigm will work.

So in the basic example, lines 88-92, String payload will contain the response body from the server anywhere on Thee Internet.

// file found at server
if(httpCode == HTTP_CODE_OK) {
 String payload = http.getString();
 USE_SERIAL.println(payload);
}

You need to set the server up at your endpoint, www.example.com/json/id/21.html, to respond with a JSON string. This is as easy as writing a file named 21.html with a JSON string in the file. Then store that file at your_http_root/json/id/ on your HTTP Server on the domain www.example.com.

You can also dynamically create that page using a scripting language like PHP, Ruby, Python ect.

Check out this for accessing an ESP from anywhere, do be careful ! if you can get in maybe others can too.