#include #include #include #include #include #include AsyncWebServer server(80); #define FAN_PIN 2 #define DELAY_TIME 1000 // time between measurements [ms] // This next section specifies variables and constants needed by the code snippet to convert serial input from ASCII to int #define numberOfDigits 3 char theNumberString[numberOfDigits + 1]; int input; // HTML based manual Fan speed input const char* PARAM_INPUT_1 = "input1"; // WiFi settings const char* ssid = "LILiK_WiFi"; //replace with your SSID const char* password = "pippopippo"; //password String hostname = "Ventole_Einstein"; // Default Fan Speed int fanSpeedPercent = 20; // HTML WEB interface const char index_html[] PROGMEM = R"rawliteral( ControllerVentoleEinstein

Ciao! Sono l'ESP8266 che gestisce le ventole di Einstein (HP DL380p G8)

% manuale:

Clicca qui sotto per aggiornare il firmware, o il secondo link per il sorgente.

⬆️ OTA Firmware_Update ⬆️ 🐱GitHub🐙

)rawliteral"; void notFound(AsyncWebServerRequest *request) { request->send(404, "text/plain", "Not found"); } // the setup function runs once when you press reset or power the board void setup(void) { pinMode(FAN_PIN, OUTPUT); analogWriteFreq(25000); Serial.begin(115200); WiFi.mode(WIFI_STA); // WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); WiFi.setHostname(hostname.c_str()); //define hostname WiFi.begin(ssid, password); Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); // Send web page with input fields to client server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) { request->send(200, "text/html", index_html); }); // Send a GET request to /get?input1= server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) { String inputMessage; String inputParam; // GET input1 value on /get?input1= if (request->hasParam(PARAM_INPUT_1)) { inputMessage = request->getParam(PARAM_INPUT_1)->value(); inputParam = inputMessage; if (inputMessage.toFloat() > 5 && inputMessage.toFloat() < 101) { fanSpeedPercent = inputMessage.toFloat(); } } else { inputMessage = "No message sent"; inputParam = "none"; } Serial.print("Speed received from HTML page: " ); Serial.println(inputMessage); request->send(200, "text/html", "HTTP GET request sent to your ESP on input field (" + inputParam + ") with value: " + inputMessage + "
Return to Home Page"); }); server.onNotFound(notFound); AsyncElegantOTA.begin(&server); // Start ElegantOTA server.begin(); Serial.println("HTTP server started"); } // the loop function runs over and over again forever void loop() { // Check if a serial interface is running if(Serial.available()){ // Check the first character: if it is "S" it will be followed by 3 digits for the fan speed // S025 = 25% if(Serial.read() == 'S') { for (int i = 0; i < numberOfDigits; theNumberString[i++] = Serial.read()); theNumberString[numberOfDigits] = 0x00; input = atoi(theNumberString); Serial.print("You typed: " ); Serial.println(input); if (input > 4 && input < 101) { fanSpeedPercent = input; } else { Serial.print("Fan Speed out of Range!" ); } } } Serial.print("Fan speed is "); Serial.print(fanSpeedPercent); Serial.println(" %"); Serial.println(); analogWrite(FAN_PIN, ((100 - fanSpeedPercent) / 100.0) * 255); delay(1000); }