#include <WiFi.h>
#include<WebServer.h>
#define TRIG 5
#define ECHO 18
#define ULTRA V3
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
WebServer Server(80);
String createwebpage(float distance)
{
String html = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="5">
<style>
body{
background: white;
font-family: Arial;
padding: 20px;
}
.bar {
background: #ddd;
border-radius: 25px;
height: 30px;
width: 100%;
overflow: hidden;
margin-bottom: 20px;
}
.fill {
height: 100%;
background: green;
border-radius: 25px;
text-align: right;
padding-right: 10px;
line-height: 30px;
color: white;
}
</style>
</head>
<body>
<h2>ESP32 SENSOR DATA</h2>
<h3>Distance</h3>
<div class="bar">
<div class="fill" style="width:Distancecm;">
Distancecm
</div>
</div>
</body>
</html>
)rawliteral";
html.replace("Distance", String(Distancecm, 2));
return html;
}
void handleRoot()
{
float raw = scale.get_units(10); // average of 10 readings
float Distancecm= raw; // after calibration this becomes kg
Server.send(200, "text/html", createwebpage(Diatancecm));
}
void setup()
{
Serial.begin(115200);
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
Server.on("/", handleRoot);
Server.begin();
}
void loop()
{
Server.handleClient();
}
}