Go Down

Topic: Esp8622 to trigger event for IFTTT (Read 2137 times) previous topic - next topic

Nate173

I want to co an ESP8622 to trigger an event, and I do don't know where to start I have done a lot of searching for codes and I cannot find any that will help because they are all very different someone help, please.

I need the code to connect to my Wifi
as well as the code to send a trigger to IFTTTT using webhooks

quamikazee

Try this.....

http://sheepdogguides.com/arduino/art4ifttt.htm


I was going to go this route but decided to try setting up a local server instead.   That way MY needs get priority.   Urgent messages are sent immediately instead of entering a public queue which could cause intolerable delays.

quamikazee

As far as connecting your ESP8266 to your WiFi......

Lot's of sketches that do this.

Are you going to run the sketch with the Arduino or upload it directly into the ESP8266 and run it from there?

quamikazee

Look at this code...it initializes the ESP8266 for connecting with your Local network

The full project can be found here.
http://www.instructables.com/id/Wireless-Temperature-and-Humidity-Monitor-With-ESP/


Code: [Select]

#include<stdlib.h>
#include "DHT.h"

#define SSID "<your_network_name>"//your network name
#define PASS "<your_network_password>"//your network password
#define IP "184.106.153.149" // thingspeak.com
#define DHTPIN 7     // what pin the DHT sensor is connected to
#define DHTTYPE DHT11   // Change to DHT22 if that's what you have
#define Baud_Rate 115200 //Another common value is 9600
#define GREEN_LED 3 //optional LED's for debugging
#define RED_LED 4 //optional LED's for debugging
#define DELAY_TIME 60000 //time in ms between posting data to ThingSpeak

//Can use a post also
String GET = "GET /update?key=<your_thingspeak_channel_key>&field1=";
String FIELD2 = "&field2=";

//if you want to add more fields this is how
//String FIELD3 = "&field3=";

bool updated;

DHT dht(DHTPIN, DHTTYPE);

//this runs once
void setup()
{
  Serial.begin(Baud_Rate);
  Serial.println("AT");
 
  delay(5000);
 
  if(Serial.find("OK")){
    //connect to your wifi netowork
    bool connected = connectWiFi();
    if(!connected){
      //failure, need to check your values and try again
      Error();
    }
  }else{
    Error();
  }
 
  //initalize DHT sensor
  dht.begin();
}

//this runs over and over
void loop(){
  float h = dht.readHumidity();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(f)) {
    LightRed();
    return;
  }
 
  //update ThingSpeak channel with new values
  updated = updateTemp(String(f), String(h));
 
  //if update succeeded light up green LED, else light up red LED
  if(updated){
    LightGreen();
  }else{
    LightRed();
  }
 
  //wait for delay time before attempting to post again
  delay(DELAY_TIME);
}

bool updateTemp(String tenmpF, String humid){
  //initialize your AT command string
  String cmd = "AT+CIPSTART=\"TCP\",\"";
 
  //add IP address and port
  cmd += IP;
  cmd += "\",80";
 
  //connect
  Serial.println(cmd);
  delay(2000);
  if(Serial.find("Error")){
    return false;
  }
 
  //build GET command, ThingSpeak takes Post or Get commands for updates, I use a Get
  cmd = GET;
  cmd += tenmpF;
  cmd += FIELD2;
  cmd += humid;
 
  //continue to add data here if you have more fields such as a light sensor
  //cmd += FIELD3;
  //cmd += <field 3 value>
 
  cmd += "\r\n";
 
  //Use AT commands to send data
  Serial.print("AT+CIPSEND=");
  Serial.println(cmd.length());
  if(Serial.find(">")){
    //send through command to update values
    Serial.print(cmd);
  }else{
    Serial.println("AT+CIPCLOSE");
  }
 
  if(Serial.find("OK")){
    //success! Your most recent values should be online.
    return true;
  }else{
    return false;
  }
}
 
boolean connectWiFi(){
  //set ESP8266 mode with AT commands
  Serial.println("AT+CWMODE=1");
  delay(2000);

  //build connection command
  String cmd="AT+CWJAP=\"";
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
 
  //connect to WiFi network and wait 5 seconds
  Serial.println(cmd);
  delay(5000);
 
  //if connected return true, else false
  if(Serial.find("OK")){
    return true;
  }else{
    return false;
  }
}

void LightGreen(){
  digitalWrite(RED_LED, LOW);
  digitalWrite(GREEN_LED, HIGH); 
}

void LightRed(){
  digitalWrite(GREEN_LED, LOW);
  digitalWrite(RED_LED, HIGH);
}

//if an error has occurred alternate green and red leds
void Error(){     
  while(true){     
    LightRed();     
    delay(2000);     
    LightGreen();
    delay(2000);
  }
}

Nate173

As far as connecting your ESP8266 to your WiFi......

Lot's of sketches that do this.

Are you going to run the sketch with the Arduino or upload it directly into the ESP8266 and run it from there?
i am going to directly upload it to the esp

Nate173

This project is still getting to me

Code: [Select]
const char* ssid = "...";
const char* password = "...";

const char* apiKey = "...";
const char* triggerName = "...";


const char* host = "maker.ifttt.com";

int soundSensor = 2;
int LED = 3;

void setup()
{

  pinMode (soundSensor, INPUT);
  pinMode (LED, OUTPUT);
}

void loop()
{
  int statusSensor = digitalRead (soundSensor);
 
  if (statusSensor == 1)
  {
    digitalWrite(LED, HIGH);
  }
 
  else
  {
    digitalWrite(LED, LOW);
  }
 
}



i want to have the led trigger as well as to send the trigger name to ifttt any help will be great I have very little time to work on this considering work/school/newborn which only leave a few hours on the weekend to play around with.

gdsports


Go Up