#include #include #include #include #include #include //create constructor SSD1306 disp(0x3c, 21, 22); WebServer server(80); const uint8_t cs_SD = 5; //SSID & PSK const String softap = "hogehoge"; const String softappw = "fugafuga1234"; //LED pin number const int ledR = A18; const int ledG = A4; const int ledB = A5; // Slidebar value String valueStringR = String(5); String valueStringG = String(5); String valueStringB = String(5); //Access on root directory. void handleRoot() { //POST Request (LED control) if (server.method() == HTTP_POST) { Serial.print("LED: "); String prm1 = server.arg("prm1"); String prm2 = server.arg("prm2"); Serial.print(prm1 + "="); //R if (prm1 == "R") { valueStringR = prm2; ledcWrite(0, valueStringR.toInt()); Serial.println(valueStringR); } //G if (prm1 == "G") { valueStringG = prm2; ledcWrite(1, valueStringG.toInt()); Serial.println(valueStringG); } //B if (prm1 == "B") { valueStringB = prm2; ledcWrite(2, valueStringB.toInt()); Serial.println(valueStringB); } } //GET Request (send index.htm) String htm = ""; htm += ""; htm += "\n"; htm += "\n"; htm += "\n"; htm += "ESP32 RGB LED controller\n"; htm += "\n"; htm += "\n"; htm += "\n"; htm += "\n"; htm += "

ESP32 with RGB LED

\n"; htm += "

Brightness of R: " + valueStringR + "

\n"; htm += "\n"; htm += "

Brightness of G: " + valueStringG + "

\n"; htm += "\n"; htm += "

Brightness of B: " + valueStringB + "

"; htm += "\n"; htm += "\n"; htm += "\n"; htm += "\n"; server.send(200, "text/html", htm); } // Send jQuery script file void handleJquery() { File file = SD.open("/jquery.min.js", FILE_READ); size_t sent = server.streamFile(file, "text/javascript"); file.close(); } // 404 File Not found void handleNotFound() { String message = "File Not Found\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET) ? "GET" : "POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for (uint8_t i = 0; i < server.args(); i++) { message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; } server.send(404, "text/plain", message); } void setup() { // LED pin assign //R ledcSetup(0, 12800, 8); // ledR is connection to ch0 ledcAttachPin(ledR, 0); //G ledcSetup(1, 12800, 8); // ledG is connection to ch1 ledcAttachPin(ledG, 1); //B ledcSetup(2, 12800, 8); // ledB is connection to ch2 ledcAttachPin(ledB, 2); Serial.begin(115200); WiFi.softAP(softap.c_str(), softappw.c_str()); SD.begin(cs_SD, SPI, 24000000, "/sd"); delay(100); /* Put Server Status */ Serial.print("SSID: "); Serial.println(softap); Serial.print("AP IP address: "); Serial.println(WiFi.softAPIP()); /* Display Server Status */ disp.init(); //Initial Display disp.setFont(ArialMT_Plain_10); //Set Font disp.drawString(0, 0, "ESP32 with RGB LED"); disp.drawString(0, 10, "SSID: " + softap); disp.drawString(0, 20, "PSK : " + softappw); disp.drawString(0, 30, "AP IP address: "); disp.drawString(0, 40, WiFi.softAPIP().toString()); disp.display(); //HTTP Request Handler server.on("/", handleRoot); server.on("/jquery.min.js", handleJquery); server.onNotFound(handleNotFound); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); }