Bueno aun me queda pulir mas el código pero ya es funcional, he incluido el propio boton de sonoff, a ver si puedes explicarme un poco mas que querías phroc hacer con los cables que soldaste.
/*
Simple Wifi Switch
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPClient.h>
MDNSResponder mdns;
// Replace with your network credentials
const char* ssid = "TU_RED_WIFI";
const char* password = "CLAVE_WIFI";
const char* device = "LED COCINA";
ESP8266WebServer server(80);
String web_on_html = "<h1>SONOFF switch is ON</h1><p><a href=\"on\"><button>ON</button></a> <a href=\"off\"><button>OFF</button></a></p>";
String web_off_html = "<h1>SONOFF switch is OFF</h1><p><a href=\"on\"><button>ON</button></a> <a href=\"off\"><button>OFF</button></a></p>";
String web_on_xml = "<?xml version='1.0'?><sonoff><estado>100</estado></sonoff>";
String web_off_xml = "<?xml version='1.0'?><sonoff><estado>0</estado></sonoff>";
String config_on_html = "<html> <title>Tuknet Wifi Rele</title> <div style='vertical-align:middle; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); -webkit-transform: translate(-50%, -50%);' > <table style='margin: 0 auto;' border='0' cellpadding='0' cellspacing='0' width='100%'> <tr> <td style='padding: 10px 0 30px 0;'> <table align='center' border='0' cellpadding='0' cellspacing='0' width='600' style='border: 1px solid #cccccc; border-collapse: collapse;'> <tr> <td align='center' style='padding: 20px 0px 20px 0;'> <img src='https://www.tuknet.es/wp-content/uploads/2018/07/logo-tuknet_small.png' srcset='https://www.tuknet.es/wp-content/uploads/2018/07/logo-tuknet_small.png' alt='Tuknet 2018' width='203' height='55' /> </td> </tr> <tr> <td bgcolor='#ffffff' style='padding: 40px 30px 40px 30px;'> <table border='0' cellpadding='0' cellspacing='0' width='100%'> <tr> <td> <table border='0' cellpadding='0' cellspacing='0' width='100%'> <p style='font-size:20px;text-align:center;'>El LED COCINA esta <b>encendido</b></p></table> </td> </tr> </table> </td> </tr> <tr> <td bgcolor='#2a70d3' style='padding: 30px 30px 30px 30px;'> <table border='0' cellpadding='0' cellspacing='0' width='100%'> <tr> <td style='text-align:center;color: #ffffff; font-family: Arial, sans-serif; font-size: 14px;' > ® Tuknet 2018 <br/></td></tr> </table> </td> </tr> </table> </div> </td> </tr> </table> </div> </html>";
String config_off_html = "<html> <title>Tuknet Wifi Rele</title> <div style='vertical-align:middle; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); -webkit-transform: translate(-50%, -50%);' > <table style='margin: 0 auto;' border='0' cellpadding='0' cellspacing='0' width='100%'> <tr> <td style='padding: 10px 0 30px 0;'> <table align='center' border='0' cellpadding='0' cellspacing='0' width='600' style='border: 1px solid #cccccc; border-collapse: collapse;'> <tr> <td align='center' style='padding: 20px 0px 20px 0;'> <img src='https://www.tuknet.es/wp-content/uploads/2018/07/logo-tuknet_small.png' srcset='https://www.tuknet.es/wp-content/uploads/2018/07/logo-tuknet_small.png' alt='Tuknet 2018' width='203' height='55' /> </td> </tr> <tr> <td bgcolor='#ffffff' style='padding: 40px 30px 40px 30px;'> <table border='0' cellpadding='0' cellspacing='0' width='100%'> <tr> <td> <table border='0' cellpadding='0' cellspacing='0' width='100%'> <p style='font-size:20px;text-align:center;'>El LED COCINA esta <b>apagado</b></p></table> </td> </tr> </table> </td> </tr> <tr> <td bgcolor='#2a70d3' style='padding: 30px 30px 30px 30px;'> <table border='0' cellpadding='0' cellspacing='0' width='100%'> <tr> <td style='text-align:center;color: #ffffff; font-family: Arial, sans-serif; font-size: 14px;' > ® Tuknet 2018 <br/></td></tr> </table> </td> </tr> </table> </div> </td> </tr> </table> </div> </html>";
int gpio_13_led = 13;
int gpio_12_relay = 12;
int gpio_0_button = 0;
int value = 0;
int estado = 0;
void setup(void){
// Init
pinMode(gpio_13_led, OUTPUT);
digitalWrite(gpio_13_led, LOW);
pinMode(gpio_12_relay, OUTPUT);
digitalWrite(gpio_12_relay, LOW);
HTTPClient http;
http.begin("http://api.eedomus.com/set?api_user=[TU_API_USER]&api_secret=[TU_API_SECRET]&action=periph.value&periph_id=[TU_ID_PERIFERICO]8&value=101");
Serial.begin(115200);
delay(5000);
pinMode(gpio_0_button, INPUT);
WiFi.begin(ssid, password);
Serial.println("Connecting to wifi..");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(gpio_13_led, LOW);
delay(500);
Serial.print(".");
Serial.println(WiFi.localIP());
Serial.println(WiFi.status());
digitalWrite(gpio_13_led, HIGH);
delay(500);
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Dispositivo: ");
Serial.println(device);
if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", [](){
if(digitalRead(gpio_12_relay)==HIGH) {
server.send(200, "text/html", config_on_html);
} else {
server.send(200, "text/html", config_off_html);
}
});
//Inicio prueba
server.on("/xml", [](){
if(digitalRead(gpio_12_relay)==HIGH) {
server.send(200, "text/html", web_on_xml);
} else {
server.send(200, "text/html", web_off_xml);
}
});
//Fin de prueba
server.on("/onapi[HASH_API]", [](){
server.send(200, "text/html", config_on_html);
digitalWrite(gpio_13_led, LOW);
digitalWrite(gpio_12_relay, HIGH);
HTTPClient http;
http.begin("http://api.eedomus.com/set?api_user=[TU_API_USER]&api_secret=[TU_API_SECRET]&action=periph.value&periph_id=[TU_ID_PERIFERICO]8&value=101");
int httpCode = http.GET();
delay(1000);
});
server.on("/offapi[HASH_API]", [](){
server.send(200, "text/html", config_off_html);
digitalWrite(gpio_13_led, HIGH);
digitalWrite(gpio_12_relay, LOW);
HTTPClient http;
http.begin("http://api.eedomus.com/set?api_user=[TU_API_USER]&api_secret=[TU_API_SECRET]&action=periph.value&periph_id=[TU_ID_PERIFERICO]8&value=102");
int httpCode = http.GET();
delay(1000);
});
server.begin();
Serial.println("Server ready..");
}
void loop(void){
value = digitalRead(gpio_0_button);
if (value == HIGH) {
Serial.println("Suelto");
}
else {
Serial.println("Pulsado");
estado = digitalRead(gpio_12_relay);
if (estado == 1){
Serial.println("El rele estaba encendido lo apago");
digitalWrite(gpio_13_led, HIGH);
digitalWrite(gpio_12_relay, LOW);
HTTPClient http;
http.begin("http://api.eedomus.com/set?api_user=[TU_API_USER]&api_secret=[TU_API_SECRET]&action=periph.value&periph_id=[TU_ID_PERIFERICO]8&value=102");
int httpCode = http.GET();
delay(1000);
}
else{
Serial.println("El rele estaba apagado lo enciendo");
digitalWrite(gpio_13_led, LOW);
digitalWrite(gpio_12_relay, HIGH);
HTTPClient http;
http.begin("http://api.eedomus.com/set?api_user=[TU_API_USER]&api_secret=[TU_API_SECRET]&action=periph.value&periph_id=[TU_ID_PERIFERICO]8&value=101");
int httpCode = http.GET();
delay(1000);
}
}
delay(1000);
server.handleClient();
}