-
-
Save wero1414/4421b5d9d726a7e9c758 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <Arduino.h> | |
ADC_MODE(ADC_VCC); | |
const char* ssid = "513570"; | |
const char* password = "H21208269B2B"; | |
const char* host = "maker.ifttt.com"; | |
const String IFTTT_Event = "button"; //Cambiar para vaiedad | |
const int puertoHost = 80; | |
const String Maker_Key = "lidz28r6iDLuC1CrSs_8rYq1geSSs9p9BfEI57gwGsO"; | |
String conexionIF = "POST /trigger/"+IFTTT_Event+"/with/key/"+Maker_Key +" HTTP/1.1\r\n" + | |
"Host: " + host + "\r\n" + | |
"Content-Type: application/x-www-form-urlencoded\r\n\r\n"; | |
void setup() { | |
Serial.begin(115200); | |
delay(1000); | |
Serial.println(); | |
Serial.print("Connecting to "); | |
Serial.println(ssid); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected"); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
} | |
void loop() { | |
int level = analogRead(A0); | |
level = map(level, 580, 774, 0, 100); | |
Serial.print("Battery level: "); | |
Serial.print(level); | |
Serial.println("%"); | |
/* if(b<3){ | |
mandarNot(); | |
delay(1000); | |
} | |
*/ | |
} | |
void mandarNot(){ | |
Serial.print("connecting to "); | |
Serial.println(host); | |
WiFiClient client; | |
if (!client.connect(host, puertoHost)) { | |
Serial.println("Conexion fallida"); | |
return; | |
} | |
client.print(conexionIF); | |
delay(10); | |
while(client.available()){ | |
String line = client.readStringUntil('\r'); | |
Serial.print(line); | |
} | |
Serial.println(); | |
Serial.println("Cerrando conexion"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment