start:arduino:esp32:projetsencours
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| start:arduino:esp32:projetsencours [2022/01/16 12:28] – [ESP32 commande chauffage] gerardadmin | start:arduino:esp32:projetsencours [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 208: | Ligne 208: | ||
| ===== ESP32 commande chauffage ====== | ===== ESP32 commande chauffage ====== | ||
| - | {{ : | + | {{: |
| + | |||
| + | |||
| + | ---------------------------------- | ||
| + | L' | ||
| + | |||
| + | **Apercu de la page web via http:/ | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | === version 1 === | ||
| + | |||
| + | <code c ESP32 relais_OTA_001_Main.ino> | ||
| + | /********* | ||
| + | Rui Santos | ||
| + | Complete project details at https:// | ||
| + | | ||
| + | The above copyright notice and this permission notice shall be included in all | ||
| + | copies or substantial portions of the Software. | ||
| + | | ||
| + | Modification GL 01/2022 | ||
| + | *********/ | ||
| + | |||
| + | // Import required libraries | ||
| + | #include " | ||
| + | #include " | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | |||
| + | // Set to true to define Relay as Normally Open (NO) | ||
| + | #define RELAY_NO | ||
| + | |||
| + | // Set number of relays | ||
| + | #define NUM_RELAYS | ||
| + | |||
| + | // Assign each GPIO to a relay | ||
| + | int relayGPIOs[NUM_RELAYS] = {15}; | ||
| + | |||
| + | // Replace with your network credentials | ||
| + | const char* ssid = " | ||
| + | const char* password = " | ||
| + | |||
| + | /* | ||
| + | // Wifi castellab | ||
| + | const char* ssid = " | ||
| + | const char* password = " | ||
| + | */ | ||
| + | |||
| + | void Wifi_connected(WiFiEvent_t event, WiFiEventInfo_t info){ | ||
| + | Serial.println(" | ||
| + | } | ||
| + | |||
| + | void Get_IPAddress(WiFiEvent_t event, WiFiEventInfo_t info){ | ||
| + | Serial.println(" | ||
| + | Serial.println(" | ||
| + | Serial.println(WiFi.localIP()); | ||
| + | } | ||
| + | |||
| + | void Wifi_disconnected(WiFiEvent_t event, WiFiEventInfo_t info){ | ||
| + | Serial.println(" | ||
| + | Serial.print(" | ||
| + | Serial.println(info.disconnected.reason); | ||
| + | Serial.println(" | ||
| + | WiFi.begin(ssid, | ||
| + | } | ||
| + | |||
| + | |||
| + | const char* PARAM_INPUT_1 = " | ||
| + | const char* PARAM_INPUT_2 = " | ||
| + | |||
| + | // Create AsyncWebServer object on port 80 | ||
| + | AsyncWebServer server(80); | ||
| + | |||
| + | const char index_html[] PROGMEM = R" | ||
| + | < | ||
| + | < | ||
| + | <meta name=" | ||
| + | < | ||
| + | html {font-family: | ||
| + | h2 {font-size: 3.0rem;} | ||
| + | p {font-size: 3.0rem;} | ||
| + | body {max-width: 600px; margin:0px auto; padding-bottom: | ||
| + | .switch {position: relative; display: inline-block; | ||
| + | .switch input {display: none} | ||
| + | .slider {position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: | ||
| + | .slider: | ||
| + | input: | ||
| + | input: | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | <h2> Castellab commande chauffage</ | ||
| + | %BUTTONPLACEHOLDER% | ||
| + | < | ||
| + | var xhr = new XMLHttpRequest(); | ||
| + | if(element.checked){ xhr.open(" | ||
| + | else { xhr.open(" | ||
| + | xhr.send(); | ||
| + | }</ | ||
| + | </ | ||
| + | </ | ||
| + | )rawliteral"; | ||
| + | |||
| + | // Replaces placeholder with button section in your web page | ||
| + | String processor(const String& var){ | ||
| + | // | ||
| + | if(var == " | ||
| + | String buttons =""; | ||
| + | for(int i=1; i< | ||
| + | String relayStateValue = relayState(i-1); | ||
| + | buttons+= "< | ||
| + | } | ||
| + | return buttons; | ||
| + | } | ||
| + | return String(); | ||
| + | } | ||
| + | |||
| + | String relayState(int numRelay){ | ||
| + | if(RELAY_NO){ | ||
| + | if(digitalRead(relayGPIOs[numRelay-1])){ | ||
| + | return ""; | ||
| + | } | ||
| + | else { | ||
| + | return " | ||
| + | } | ||
| + | } | ||
| + | else { | ||
| + | if(digitalRead(relayGPIOs[numRelay-1])){ | ||
| + | return " | ||
| + | } | ||
| + | else { | ||
| + | return ""; | ||
| + | } | ||
| + | } | ||
| + | return ""; | ||
| + | } | ||
| + | |||
| + | void setup(){ | ||
| + | // Serial port for debugging purposes | ||
| + | Serial.begin(115200); | ||
| + | Serial.println(" | ||
| + | pinMode(relayGPIOs[0], | ||
| + | digitalWrite(relayGPIOs[0], | ||
| + | | ||
| + | digitalWrite(relayGPIOs[0], | ||
| + | } | ||
| + | else{ | ||
| + | digitalWrite(relayGPIOs[0], | ||
| + | } | ||
| + | |||
| + | // Set all relays to off when the program starts - if set to Normally Open (NO), the relay is off when you set the relay to HIGH | ||
| + | |||
| + | /*for(int i=1; i< | ||
| + | pinMode(relayGPIOs[i-1], | ||
| + | if(RELAY_NO){ | ||
| + | digitalWrite(relayGPIOs[i-1], | ||
| + | } | ||
| + | else{ | ||
| + | digitalWrite(relayGPIOs[i-1], | ||
| + | } | ||
| + | } | ||
| + | */ | ||
| + | | ||
| + | | ||
| + | | ||
| + | // Connect to Wi-Fi | ||
| + | WiFi.mode(WIFI_STA); | ||
| + | |||
| + | WiFi.disconnect(true); | ||
| + | delay(1000); | ||
| + | |||
| + | WiFi.onEvent(Wifi_connected, | ||
| + | WiFi.onEvent(Get_IPAddress, | ||
| + | WiFi.onEvent(Wifi_disconnected, | ||
| + | WiFi.begin(ssid, | ||
| + | Serial.println(" | ||
| + | |||
| + | /* | ||
| + | WiFi.begin(ssid, | ||
| + | while (WiFi.waitForConnectResult() != WL_CONNECTED) { | ||
| + | Serial.println(" | ||
| + | delay(5000); | ||
| + | ESP.restart(); | ||
| + | } | ||
| + | */ | ||
| + | /* | ||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | delay(1000); | ||
| + | Serial.println(" | ||
| + | } | ||
| + | */ | ||
| + | |||
| + | |||
| + | // Route for root / web page | ||
| + | server.on("/", | ||
| + | request-> | ||
| + | }); | ||
| + | |||
| + | // Send a GET request to < | ||
| + | server.on("/ | ||
| + | String inputMessage; | ||
| + | String inputParam; | ||
| + | String inputMessage2; | ||
| + | String inputParam2; | ||
| + | // GET input1 value on < | ||
| + | if (request-> | ||
| + | inputMessage = request-> | ||
| + | inputParam = PARAM_INPUT_1; | ||
| + | inputMessage2 = request-> | ||
| + | inputParam2 = PARAM_INPUT_2; | ||
| + | if(RELAY_NO){ | ||
| + | Serial.print(" | ||
| + | digitalWrite(relayGPIOs[inputMessage.toInt()-1], | ||
| + | } | ||
| + | else{ | ||
| + | Serial.print(" | ||
| + | digitalWrite(relayGPIOs[inputMessage.toInt()-1], | ||
| + | } | ||
| + | } | ||
| + | else { | ||
| + | inputMessage = "No message sent"; | ||
| + | inputParam = " | ||
| + | } | ||
| + | Serial.println(inputMessage + inputMessage2); | ||
| + | request-> | ||
| + | }); | ||
| + | // Start server | ||
| + | server.begin(); | ||
| + | |||
| + | | ||
| + | .onStart([]() { | ||
| + | String type; | ||
| + | if (ArduinoOTA.getCommand() == U_FLASH) | ||
| + | type = " | ||
| + | else // U_SPIFFS | ||
| + | type = " | ||
| + | |||
| + | // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() | ||
| + | Serial.println(" | ||
| + | }) | ||
| + | .onEnd([]() { | ||
| + | Serial.println(" | ||
| + | }) | ||
| + | .onProgress([](unsigned int progress, unsigned int total) { | ||
| + | Serial.printf(" | ||
| + | }) | ||
| + | .onError([](ota_error_t error) { | ||
| + | Serial.printf(" | ||
| + | if (error == OTA_AUTH_ERROR) Serial.println(" | ||
| + | else if (error == OTA_BEGIN_ERROR) Serial.println(" | ||
| + | else if (error == OTA_CONNECT_ERROR) Serial.println(" | ||
| + | else if (error == OTA_RECEIVE_ERROR) Serial.println(" | ||
| + | else if (error == OTA_END_ERROR) Serial.println(" | ||
| + | }); | ||
| + | |||
| + | ArduinoOTA.begin(); | ||
| + | |||
| + | /* | ||
| + | | ||
| + | Serial.print(" | ||
| + | Serial.println(WiFi.localIP()); | ||
| + | */ | ||
| + | | ||
| + | } | ||
| + | | ||
| + | void loop() { | ||
| + | ArduinoOTA.handle(); | ||
| + | | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===version 2 === | ||
| **Inserer les 4 programmes suivant dans le même repertoire** | **Inserer les 4 programmes suivant dans le même repertoire** | ||
| - | <code c ESP32_Relais_OTA_001_Main.ino> | + | <code c ESP32_Relais_OTA_002_Main.ino> |
| /********* | /********* | ||
| Rui Santos | Rui Santos | ||
| Ligne 299: | Ligne 573: | ||
| const char* ssid = " | const char* ssid = " | ||
| const char* password = " | const char* password = " | ||
| + | |||
| + | void Wifi_connected(WiFiEvent_t event, WiFiEventInfo_t info){ | ||
| + | Serial.println(" | ||
| + | } | ||
| + | |||
| + | void Get_IPAddress(WiFiEvent_t event, WiFiEventInfo_t info){ | ||
| + | Serial.println(" | ||
| + | Serial.println(" | ||
| + | Serial.println(WiFi.localIP()); | ||
| + | } | ||
| + | |||
| + | void Wifi_disconnected(WiFiEvent_t event, WiFiEventInfo_t info){ | ||
| + | Serial.println(" | ||
| + | Serial.print(" | ||
| + | Serial.println(info.disconnected.reason); | ||
| + | Serial.println(" | ||
| + | WiFi.begin(ssid, | ||
| + | } | ||
| + | |||
| const char* PARAM_INPUT_1 = " | const char* PARAM_INPUT_1 = " | ||
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/projetsencours.1642332522.txt.gz · Dernière modification : (modification externe)
