Your $5 ESP32 can host a working website with no extra hardware

Hosting a website typically involves paying to host your site on a server, or running your own server on a local computer.You may be surprised to learn that you can host small websites on a cheap ESP32 microcontroller, with no additional hardware required.Add How-To Geek on Google Add as Preferred Source Follow on Google Discover What you need to host a website on an ESP32 An ESP32 and some free software can do the job Close An ESP32 is a small, inexpensive microcontroller with a processor, a small amount of flash storage, and built-in Wi-Fi.

This means that an ESP32 has everything you need to host your own website.There's memory to store the pages, a network connection to expose those pages to other devices, and it's capable of running software that can serve those pages to phones or computers.You don't need hardware such as external hard drives to host your website.

All you need is the ESP32, a USB data cable to upload the software, and a computer to set it up.You'll also need a power source for your ESP32, such as a smartphone charger with a suitable connector.The final thing you'll need is the software that can compile your code and upload it to the ESP32.

The free Arduino IDE software is a great choice, and despite the name, it also supports ESP32 boards.Install Arduino IDE on a Windows, Mac, or Linux computer, go to File > Preferences on Windows or Arduino IDE > Settings on Mac.Select Additional Boards Manager URLs and paste the following link: https://espressif.github.io/arduino-esp32/package_esp32_index.json.

Click the Boards Manager icon in the left-hand menu, search for esp32, and find esp32 by Espressif Systems.Click the Install button.You now have all the tools needed to compile and install software on your ESP32.

Related How to start your coding journey with an ESP32 (without relying on vibe coding) There's still a place for learning to code the old-fashioned way, and it's more fun than you think.Posts 1 By  Umair Khurshid How to create a website using an Arduino sketch The website's code is written in C++ The next step is to create the code that will run your website.Programs created in Arduino IDE are called sketches, and are written in C++ code.

Arduino IDE then compiles this code into firmware you can upload and run on your ESP32.Don't worry if you don't have the first clue about coding.Any modern AI chatbot should be able to generate the code for a simple website.

To put this to the test, I asked ChatGPT to generate the code for a very simple website that lets you create small polls that people in the household can vote on from their own devices, such as what to eat for dinner or what to watch on TV tonight.The code below is what ChatGPT generated.You can use it to build your own small poll website, or ask a chatbot to create something else.

It needs to be something an ESP32 can handle; there is very limited storage and RAM on cheap ESP32 boards.However, the visitor's browser can often do a lot of the heavy lifting, so you can host some surprisingly impressive sites on the tiny development board.#include <WiFi.h> #include <WebServer.h> #include <Preferences.h> const char* ssid = "YOUR_WIFI_NAME"; const char* password = "YOUR_WIFI_PASSWORD"; WebServer server(80); Preferences prefs; String question, options[4]; uint32_t votes[4]; String key(char c, int i) { return String(c) + i; } String safe(String s) { s.replace("&", "&amp;"); s.replace("<", "&lt;"); s.replace(">", "&gt;"); return s; } void home() { String h = "<meta name='viewport' content='width=device-width,initial-scale=1'>" "<style>body{font:18px Arial;max-width:550px;margin:40px auto;padding:15px;" "background:#f1f4fa}main{background:white;padding:25px;border-radius:15px}" "button,input{padding:12px;margin:5px 0;border-radius:8px}" "button{background:#286fe5;color:white;border:0;cursor:pointer}" "input{display:block;width:90%}</style>" "<main><h1>ESP32 Polls</h1><h2>" + safe(question) + "</h2>"; uint32_t total = 0; for (int i = 0; i < 4; i++) total += votes[i]; h += "<h3>Cast your vote</h3>"; for (int i = 0; i < 4; i++) { if (options[i].isEmpty()) continue; h += "<form action='/vote' method='POST'><button name='i' value='" + String(i) + "'>" + safe(options[i]) + "</button></form>"; } h += "<h3>Results (" + String(total) + " votes)</h3>"; for (int i = 0; i < 4; i++) { if (options[i].isEmpty()) continue; int pct = total ? votes[i] * 100 / total : 0; h += "<p>" + safe(options[i]) + ": " + String(votes[i]) + " votes (" + String(pct) + "%)</p>"; } h += "<details><summary>Create a new poll</summary>" "<form action='/new' method='POST'>" "<input name='q' placeholder='Question' maxlength='120' required>"; for (int i = 0; i < 4; i++) h += "<input name='a" + String(i) + "' maxlength='60' placeholder='Answer " + String(i + 1) + "'" + (i < 2 ? " required" : "") + ">"; h += "<button>Publish poll</button></form></details>" "<script>setInterval(()=>{if(!document.querySelector('details').open)" "location.reload()},5000)</script></main>"; server.send(200, "text/html", h); } void redirectHome() { server.sendHeader("Location", "/"); server.send(303, "text/plain", ""); } void vote() { int i = server.arg("i").toInt(); if (server.hasArg("i") && i >= 0 && i < 4 && !options[i].isEmpty()) { votes[i]++; prefs.putUInt(key('v', i).c_str(), votes[i]); } redirectHome(); } void newPoll() { String q = server.arg("q"); q.trim(); String a[4]; int n = 0; for (int i = 0; i < 4; i++) { String s = server.arg(key('a', i)); s.trim(); if (!s.isEmpty()) a[n++] = s.substring(0, 60); } if (q.isEmpty() || n < 2) { server.send(400, "text/plain", "Enter a question and two answers."); return; } question = q.substring(0, 120); prefs.putString("q", question); for (int i = 0; i < 4; i++) { options[i] = a[i]; votes[i] = 0; prefs.putString(key('a', i).c_str(), options[i]); prefs.putUInt(key('v', i).c_str(), 0); } redirectHome(); } void setup() { Serial.begin(115200); prefs.begin("minipolls", false); question = prefs.getString("q", "What should we watch?"); for (int i = 0; i < 4; i++) { String def = i == 0 ? "Film" : i == 1 ? "TV show" : i == 2 ? "YouTube" : ""; options[i] = prefs.getString(key('a', i).c_str(), def); votes[i] = prefs.getUInt(key('v', i).c_str(), 0); } WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) delay(500); Serial.print("Website: http://"); Serial.println(WiFi.localIP()); server.on("/", HTTP_GET, home); server.on("/vote", HTTP_POST, vote); server.on("/new", HTTP_POST, newPoll); server.begin(); } void loop() { server.handleClient(); } How to upload your website to your ESP32 Add your Wi-Fi credentials to connect to your local network Close Once you have your code, you need to compile it and upload it to your ESP32.

In Arduino IDE, click File > New Sketch.Delete the existing code and paste the code given above.Replace YOUR_WIFI_NAME and YOUR_WIFI_PASSWORD with the SSID and password for your Wi-Fi.

Select File > Save As, give the sketch the name ESP32Polls, and click Save.Connect your ESP32 to your computer using a USB data cable.Click the drop-down box at the top of the screen and select your USB port and board.

For generic ESP32 boards, ESP32 Dev Module is usually the right choice.Click OK to save your settings.Close Click the check mark to compile the code.

If it compiles without errors, click the Upload arrow to upload the compiled code to your ESP32.Once the upload is complete, go to Tools > Serial Monitor, click the Baud dropdown, and select 115200 baud.Finally, locate the EN or RESET button on your ESP32 and press it if you don't already see the startup messages in the Serial Monitor window.

As long as you've included the relevant code in your sketch, one of these messages should include the URL that you need to access your new website.Anyone on your local network can access your website It's a cheap way to set up small local web pages Copy the URL shown in Arduino IDE and paste it into the browser of any device that's connected to the same network as your ESP32.The website should open on the device.

For my polls website, it opens to a webpage with a sample poll that anyone can vote on, along with an option to create a new poll.Because the site is hosted on the ESP32, when anyone votes from their device, the poll will update for anyone else who's connected to the site from their own device, making it easy for a whole household to vote on a decision.It's a simple example of the kind of site that can be useful to run locally on an ESP32.

It's possible to expose your ESP32-based website to the world using methods such as port forwarding.However, this means anyone could access your site and potentially find vulnerabilities that could allow them to attack other devices on your local network.Without robust encryption and authentication, it's safer to leave your website accessible only on your local network.

Your tiny ESP32 can become a working web server Despite its small size and relatively low specs, an ESP32 can do a great job as a small web server.It's a great option if you want small local websites that don't need to be exposed to the outside world.You may be surprised by the websites your small development board is able to run.

Read More
Related Posts