/* ESP32 HTTP IoT Server Example for Wokwi.com
https://wokwi.com/projects/320964045035274834
To test, you need the Wokwi IoT Gateway, as explained here:
https://docs.wokwi.com/guides/esp32-wifi#the-private-gateway
Then start the simulation, and open http://localhost:9080
in another browser tab.
Note that the IoT Gateway requires a Wokwi Club subscription.
To purchase a Wokwi Club subscription, go to https://wokwi.com/club
*/
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <uri/UriBraces.h>
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define WIFI_CHANNEL 6
WebServer server(80);
void sendHtml() {
String gpsa = "abc";
String response = R"(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Form</title>
<!-- Include necessary libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js" integrity="sha256-/H4YS+7aYb9kJ5OKhFYPUjSJdrtV6AeyJOtTkw6X72o=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/TweenMax.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id="app" class="mdui-theme-light">
<h1>Cloud Chat</h1>
<link rel="stylesheet" href="/index.4d663569.css">
<div class="mdui-theme-light">
<mdui-card>
<ul id="messages"></ul>
</mdui-card></div>
<div id="formb3">
<mdui-text-field type="text" name="name" placeholder="Enter your Username" id="input_btrusername" variant="outlined" onkeypress="handle(event)">
<mdui-button onclick="setUsername();">Start</mdui-button>
</mdui-text-field></div>
<script>function handle(e) {
if (e.keyCode === 13) setUsername();
}
function CHAThandle(e) {
if (e.keyCode === 13) addMessage();
}
</script>
<div id="formb2">
<mdui-card> <mdui-text-field type="text" name="messabge" placeholder="Enter message here" id="input_btrmeassage" onkeypress="CHAThandle(EVENT)" "="">
<br>
</mdui-text-field></mdui-card>
<mdui-button type="submit" onclick="addMessage()">Send
</mdui-button></div>
<script>let username = "";
let lastSyncTime = 0;
document.head.appendChild((($1, s)=>{
$1.src = s;
return $1;
})(document.createElement("script"), "cloud.js"));
var test = cloud_chatMessages;
var cloud_chatMessages = [];
function addMessage() {
var message = document.getElementById("input_btrmeassage").value;
cloud_chatMessages.push(`${username} : ` + message);
document.getElementById("input_btrmeassage").value = "";
updateMessages();
}
setInterval(updateMessages, 0); // update every 5 seconds
function updateMessages() {
let messages = cloud_chatMessages;
let messagesElement = document.getElementById("messages");
messagesElement.innerHTML = "";
for (const message of messages)messagesElement.innerHTML += `<h3>${message} ` + ` </h3>`;
lastSyncTime = Date.now();
}
function setUsername(newUsername) {
username = document.getElementById("input_btrusername").value;
fmbnsr.hidden = false;
$("#formb3").remove();
updateMessages();
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js" integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>var o = document.createElement("script");
o.src = "https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.slim.js", o.onload = ()=>{
let n = io("https://cloudvarapi.kihtrak.com/"), o = "playground", i = (window.location.hostname && (o = encodeURIComponent(window.location.protocol + "//" + window.location.hostname).replace(/\./g, "%2E")), n.on("init-" + o, (o)=>{
for(var n in o)i[n] = JSON.parse(JSON.stringify(o[n])), null == window[n] && (window[n] = o[n]);
}), n.on("newVal-" + o, (o)=>{
var n = Object.keys(o)[0];
window[n] = o[n], i[n] = JSON.parse(JSON.stringify(o[n]));
}), {}), t = (o)=>"number" == typeof o || "string" == typeof o ? o : "object" == typeof o ? JSON.stringify(o) : "function" == typeof o ? o.toString() : o;
setInterval(()=>{
for(var o in window)0 == o.indexOf("cloud_") && t(i[o]) !== t(window[o]) && (i[o] = "object" == typeof window[o] ? JSON.parse(JSON.stringify(window[o])) : window[o], n.emit("varChanged", {
[o]: "function" == typeof window[o] ? window[o].toString() : window[o]
}));
}, 0);
}, document.head.appendChild(o);
const fm1bnsr = document.getElementById("formb3");
const fmbnsr = document.getElementById("formb2");
fmbnsr.hidden = true;
</script>
</div>
<!-- Include your other scripts -->
<script src="/index.579125c3.js"></script>
<script src="/index.ac9dc4ba.js" defer=""></script>
</body>
</html>
)";
response.replace("sb", gpsa);
server.send(200, "text/html", response);
}
void setup(void) {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD, WIFI_CHANNEL);
Serial.print("Connecting to WiFi ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", sendHtml);
server.on(UriBraces("/toggle/{}"), []() {
String led = server.pathArg(0);
Serial.print("Toggle LED #");
Serial.println(led);
sendHtml();
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void) {
server.handleClient();
delay(2);
}