E3

← разместить еще код

Расшаренный код:

#include <WiFi.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <analogWrite.h>
#include <SPIFFS.h>

const char* ssid = "IoT-1";
const char* password = "123456789";

const byte port_led_green = 16;
const byte port_led_yellow = 17;
const byte port_led_red = 18;

byte value_led_green = 0;
byte value_led_yellow = 0;
byte value_led_red = 0;

WebServer server(80);

void pageRoot() {                  
  File page = SPIFFS.open("/index.html", "r");
  String html = page.readString();
  server.send(200, "text/html", html);
}

void pageLed() {
  value_led_green = server.arg("green").toInt();
  value_led_yellow = server.arg("yellow").toInt();
  value_led_red = server.arg("red").toInt();

  analogWrite(port_led_green, value_led_green);
  analogWrite(port_led_yellow, value_led_yellow);
  analogWrite(port_led_red, value_led_red);
    
  server.sendHeader("Location", "/", true);
  server.send(302);
}

void setup() {
  pinMode(port_led_green, OUTPUT);
  pinMode(port_led_yellow, OUTPUT);
  pinMode(port_led_red, OUTPUT);

  SPIFFS.begin();

  WiFi.softAP(ssid, password);
  MDNS.begin("device");

  server.on("/", pageRoot);
  server.on("/led", pageLed);

  server.begin();
}

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