I'm a Newbie with this and trying to understand what im doing wrong. I'm trying to get this code to send the "SMS" only when the SoundDetector senses sound and becomes High. Right now when the Board iniationally powered up, it sends the sms. But i want it to remain connected to the internet at all times and send a sms Only when SoundDection is High. Anyone with the skills of helping me plug in the correct changes? Thanks in advance.
#include <ESP8266WiFi.h>
int ledPin = 4; // Turns on when soundDetection sensor detects sound and become High
int soundDetection = 5; // When pressed inPin 5 becomes High and turns on LED and initiates MakerIFTTT to send sms
int val = 0;
int soundDetectionStat;
int DigitalRead = 0;
int makerifttt = val;
WiFiClient client;
String MakerIFTTT_Key ;
;String MakerIFTTT_Event;
char *append_str(char *here, String s) { int i=0; while (*here++ = s[i]){i++;};return here-1;}
char *append_ul(char *here, unsigned long u) { char buf[20]; return append_str(here, ultoa(u, buf, 10));}
char post_rqst[256];char *p;char *content_length_here;char *json_start;int compi;
void setup()
{
Serial.begin(9600);
WiFi.disconnect();
delay(3000);
Serial.println("START");
WiFi.begin("NSA SURVEILLANCE TEAM","????????");
while ((!(WiFi.status() == WL_CONNECTED))){
delay(300);
Serial.print("..");
}
Serial.println("Connected");
Serial.println("Your IP Is");
Serial.println((WiFi.localIP().toString()));
{
pinMode(ledPin, OUTPUT);
pinMode(soundDetection, INPUT);
}
delay(1000);
if (digitalRead, HIGH)(client.connect("maker.ifttt.com",80)); {
MakerIFTTT_Key ="??????????????????????";
MakerIFTTT_Event ="SMS";
p = post_rqst;
p = append_str(p, "POST /trigger/");
p = append_str(p, MakerIFTTT_Event);
p = append_str(p, "/with/key/");
p = append_str(p, MakerIFTTT_Key);
p = append_str(p, " HTTP/1.1\r\n");
p = append_str(p, "Host: maker.ifttt.com\r\n");
p = append_str(p, "Content-Type: application/json\r\n");
p = append_str(p, "Content-Length: ");
content_length_here = p;
p = append_str(p, "NN\r\n");
p = append_str(p, "\r\n");
json_start = p;
p = append_str(p, "{\"value1\":\"");
p = append_str(p, "???????????");
p = append_str(p, "\",\"value2\":\"");
p = append_str(p, "ALARM_SOUNDING");
p = append_str(p, "\",\"value3\":\"");
p = append_str(p, "");
p = append_str(p, "\"}");
compi= strlen(json_start);
content_length_here[0] = '0' + (compi/10);
content_length_here[1] = '0' + (compi%10);
client.print(post_rqst);
}
}
void loop()
{
val = digitalRead(soundDetection);
digitalWrite(ledPin, val);
Serial.println(soundDetection, val);
delay(1000);
}