Skip to content

Instantly share code, notes, and snippets.

@wero1414
Created January 21, 2016 00:50
Show Gist options
  • Save wero1414/4421b5d9d726a7e9c758 to your computer and use it in GitHub Desktop.
Save wero1414/4421b5d9d726a7e9c758 to your computer and use it in GitHub Desktop.
#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