Is it possible control esp32 from my own website?

Hello dears,
i am trying to make project using esp32 and the codes runs very well and esp32 is runing as webserver and providing webpage which is using websocket .. but actually i want this webpage to run in my website which is web host with domain and then i can make any one controls the esp32 by using my website by user and password i provide them . i really do not know how to make this and what topic i should read about and if there are any example for such communication please let me know
this is the basic example i want this webpage code in the code to not be in the esp32 i want this to be in my own website and from there it controls the esp32

//============================
//ESP32 Web Server: Toggle LED
//============================
#include <WiFi.h>
#include <WebServer.h>
#include "webpageCode.h"
//------------------------------------------
const char* ssid     = "ssid";
const char* password = "password";
//------------------------------------------
WebServer server(80);
//------------------------------------------
#include "functions.h"
//===================================================================
void setup()
{
  Serial.begin(115200); pinMode(2, OUTPUT); delay(10);
  //-----------------------------------------------------------------
  Serial.println();
  Serial.print("Connecting to WiFi ");
  WiFi.begin(ssid, password);
  while (WiFi.status()!=WL_CONNECTED){delay(500); Serial.print(".");}
  Serial.println(); Serial.println("WiFi connected.");
  Serial.print("IP address: "); Serial.println(WiFi.localIP());
  //-----------------------------------------------------------------
  server.on("/", webPage);
  server.on("/led", LEDtoggle);
  server.begin();
}
//===================================================================
void loop() {server.handleClient();}

function.h file:

//=====================
//web handler functions
//=====================
void webPage()
{
  server.send(200,"text/html", webpageCode);
}
//---------------------------------------------
void LEDtoggle()
{
  digitalWrite(2, !digitalRead(2)); delay(500);
  server.send(200,"text/html", webpageCode);
}

webpageCode.h file:

//=================
//Webpage HTML code
//=================
String webpageCode = R"***(
<!DOCTYPE html>
<html>
  <head>    
        <title>ESP32 Web Server</title>
  </head>
  <style>
        body {font-family: "Calibri"; text-align:center; background-color: rgba(128, 128, 128, 0.589)}
        h1   {color: rgba(0, 0, 255, 0.788); font-size: 50px;}
        h2   {color: rgb(155, 11, 11); font-size: 30px;}
        #btn
          {
            display: inline-block;
            text-decoration: none;
            background: #b60303;
            color: rgba(255,255,255, 0.80);
            font-weight: bold;
            font: 50px arial, sans-serif;
            width: 100px;
            height: 100px;
            line-height: 100px;
            border-radius: 50%;
            margin: 30%;
            margin-top: 60px;
            text-align: center;
            vertical-align: middle;
            overflow: hidden;
            box-shadow: 0px 0px 0px 8px #0813018e;
            border: solid 2px rgba(247, 243, 7, 0.836);
            transition: 0.4s;
            cursor: pointer;
          }
  </style>
  <body>
        <h1>
              ESP32 Web Server<br>
        </h1>
        <h2>
              Click to toggle LED
              <a href="/led" id="btn" onclick="onoff()">LED</a>
        </h2>
        <script>
            function onoff()
            {
                  var x = document.getElementById("btn");
                  x.innerHTML = "T";
            }       
        </script>
  </body>
</html>
)***";

I have a web site where I control/monitor 13 ESP32's from.

I have an RaspberryPi that is the MQTT Broker for all 13 ESP32's. The RaspberryPi interfaces the ESP32's to my website.

1 Like

i think this will help, Arduino - Webserver with and Arduino + Ethernet Shield

how is that been done any article of how this to be done ?
i found this guy doing the same as i want to do but he is not sharing the codes

this not what i want he is writing the webpage inside his code !

```
 if (c == '\n') {          
           Serial.println(readString); //print to serial monitor for debuging
     
           client.println("HTTP/1.1 200 OK"); //send new page
           client.println("Content-Type: text/html");
           client.println();     
           client.println("<HTML>");
           client.println("<HEAD>");
           client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
           client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
           client.println("<link rel='stylesheet' type='text/css' href='https://randomnerdtutorials.com/ethernetcss.css' />");
           client.println("<TITLE>Random Nerd Tutorials Project</TITLE>");
           client.println("</HEAD>");
           client.println("<BODY>");
           client.println("<H1>Random Nerd Tutorials Project</H1>");
           client.println("<hr />");
           client.println("<br />");  
           client.println("<H2>Arduino with Ethernet Shield</H2>");
           client.println("<br />");  
           client.println("<a href=\"/?button1on\"\">Turn On LED</a>");
           client.println("<a href=\"/?button1off\"\">Turn Off LED</a><br />");   
           client.println("<br />");     
           client.println("<br />"); 
           client.println("<a href=\"/?button2on\"\">Rotate Left</a>");
           client.println("<a href=\"/?button2off\"\">Rotate Right</a><br />"); 
           client.println("<p>Created by Rui Santos. Visit https://randomnerdtutorials.com for more projects!</p>");  
           client.println("<br />"); 
           client.println("</BODY>");
           client.println("</HTML>");
```

Have you looked into using Arduino IoT?

I did that i already have account there but i want to keep all my work in my website

Then get your own MQTT Broker.

Okay thank you sir , but how i can do that do you have any link to read or this MQQT can be installed in online webserver ?what is the best way to do that ? Thank you very much for your help sir i appreciate your response and kindly helping

1 Like

Have you done stuff like enter words into an internet search engine?

1 Like

hi man, have you managed to solve this problem, because i too am working on a project that needs me to control everything from my own web page

Yes , actually i set up mqtt broker to aws server and then used java mqtt client to connect to my broker it was also easy to code mqtt from esp32 .. another way i am learning now is to use google firebase and also google offers google cloud iot service with mqtt and data management.. you have to read in mqtt and how to use it ... Its kind of fun

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.