FluxBench.AIShared project · read-only

WiFi Web Dashboard

ESP32 DevKit (WROOM-32)·Arduino C++·Updated Jul 27, 2026·by FluxBench TeamIncludes Lab + Schematic

The ESP32 serves its own live dashboard page straight from the chip: sensor voltage from the bench potentiometer on GPIO34, an LED toggle link, and a page-hit counter. In the simulator a virtual browser starts visiting / and /led about 2.5 seconds after server.begin() (one request every 4 seconds), so you can watch requests arrive in the serial monitor and see the onboard LED toggle — no network needed. On real hardware, put in your WiFi name and password and open the printed IP address in your phone's browser.

sketch.ino
// WiFi Web Dashboard - the ESP32 serves a live sensor page from its own little web server.
// In the FluxBench simulator there is no real network: a virtual browser starts visiting
// your routes about 2.5 s after server.begin() (one request every 4 s), so you can watch
// the request log and the LED toggle without any hardware. On the real board, join your
// WiFi and open the printed IP address in your phone's browser.

#include <WiFi.h>
#include <WebServer.h>

#define SENSOR_PIN 34   // potentiometer wiper - the "sensor" shown on the dashboard
#define LED_PIN 2       // onboard LED - toggled from the /led page

WebServer server(80);
bool ledOn = false;
int hits = 0;

float readVolts() {
  return analogRead(SENSOR_PIN) * (3.3 / 4095.0);
}

void handleRoot() {
  hits++;
  float v = readVolts();
  String html = "<html><head><meta http-equiv='refresh' content='5'></head><body>";
  html += "<h1>FluxBench Dashboard</h1>";
  html += "<p>Sensor: " + String(v, 2) + " V</p>";
  if (ledOn) html += "<p>LED is ON - <a href='/led'>toggle</a></p>";
  else       html += "<p>LED is OFF - <a href='/led'>toggle</a></p>";
  html += "<p>Page hits: " + String(hits) + "</p>";
  html += "</body></html>";
  server.send(200, "text/html", html);
  Serial.printf("served / : sensor %.2f V, hit #%d\n", v, hits);
}

void handleLed() {
  ledOn = !ledOn;
  digitalWrite(LED_PIN, ledOn ? HIGH : LOW);
  server.send(200, "text/html", "<p>LED toggled - <a href='/'>back</a></p>");
  if (ledOn) Serial.println("served /led : LED now ON");
  else       Serial.println("served /led : LED now OFF");
}

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);

  WiFi.begin("your-wifi", "your-password");
  Serial.print("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }
  Serial.println();
  Serial.print("Connected! Open http://");
  Serial.println(WiFi.localIP());

  server.on("/", handleRoot);
  server.on("/led", handleLed);
  server.begin();
}

void loop() {
  server.handleClient();
  delay(10);
}

Built with FluxBench.AI — the AI workbench for embedded projects.