Saltar al contenido

ejemplo de código de programación del módulo de relé nodemcu esp8266

Ya no tienes que indagar más en otras webs ya que llegaste al espacio indicado, contamos con la solución que quieres hallar y sin problema.

Ejemplo: control de relé nodemcu esp8266

/*********
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp8266-relay-module-ac-web-server/
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*********/

// Import required libraries
#include "ESP8266WiFi.h"
#include "ESPAsyncWebServer.h"

// Set to true to define Relay as Normally Open (NO)
#define RELAY_NO    true

// Set number of relays
#define NUM_RELAYS  5

// Assign each GPIO to a relay
int relayGPIOs[NUM_RELAYS] = 5, 4, 14, 12, 13;

// Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

const char* PARAM_INPUT_1 = "relay";  
const char* PARAM_INPUT_2 = "state";

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

const char index_html[] PROGMEM = R"rawliteral(
DOCTYPEHTML><html><head><metaname="viewport"content="width=device-width, initial-scale=1"><style>htmlfont-family: Arial;display: inline-block;text-align: center;h2font-size:3.0rem;pfont-size:3.0rem;bodymax-width:600px;margin:0px auto;padding-bottom:25px;.switchposition: relative;display: inline-block;width:120px;height:68px.switch inputdisplay: none.sliderposition: absolute;top:0;left:0;right:0;bottom:0;background-color:#ccc;border-radius:34px.slider:beforeposition: absolute;content:"";height:52px;width:52px;left:8px;bottom:8px;background-color:#fff;-webkit-transition:.4s;transition:.4s;border-radius:68pxinput:checked+.sliderbackground-color:#2196F3input:checked+.slider:before-webkit-transform:translateX(52px);-ms-transform:translateX(52px);transform:translateX(52px)style>head><body><h2>ESP Web Serverh2>
  %BUTTONPLACEHOLDER%
<script>functiontoggleCheckbox(element)var xhr =newXMLHttpRequest();if(element.checked) xhr.open("GET","/update?relay="+element.id+"&state=1",true);else xhr.open("GET","/update?relay="+element.id+"&state=0",true);
  xhr.send();script>body>html>
)rawliteral";

// Replaces placeholder with button section in your web page
String processor(const String& var)
  //Serial.println(var);
  if(var == "BUTTONPLACEHOLDER")
    String buttons ="";
    for(int i=1; i<=NUM_RELAYS; i++)
      String relayStateValue = relayState(i);
      buttons+= "<h4>Relay #" + String(i) + " - GPIO " + relayGPIOs[i-1] + "h4>

¡Haz clic para puntuar esta entrada!
(Votos: 2 Promedio: 3.5)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *