I need to send a message to the given phone number when the user ID is typed.
Can anyone please help me with this
#include <WiFi.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
byte rowPins[ROWS] = { 13, 12, 14, 27 }; //connect to the row pinouts of the keypad
byte colPins[COLS] = { 26, 25, 33, 32 }; //connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String Event_Name = "Attendance";
String Key = "kPABqDk57rSZkTz1bUMG1sZ0jIulbdgG_9o5kYYFbMB"; //nlGjtBEifiySWwQmTgZAipFdSmCgQLXOa4cMcAnin05
// Replace with your unique IFTTT URL resource
String resource = "/trigger/" + Event_Name + "/with/key/" + Key;
// Maker Webhooks IFTTT
const char* server = "maker.ifttt.com";
// Replace with your SSID and Password
const char* ssid = "Dineth";
const char* password = "Dineth2008";
int input;
struct {
const char* name;
const int id;
}
Users[] = {
{ "Parrot", 11 },
{ "bla", 12 },
{ "Dineth", 13 },
{ "Aakesh", 14 }
};
size_t UserCount = sizeof Users / sizeof Users[0];
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.setCursor(3, 0);
lcd.print("Attendance");
lcd.setCursor(4, 1);
lcd.print("System");
delay(1600);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Your ID:");
Serial.print("Connecting to: ");
Serial.print(ssid);
WiFi.begin(ssid, password);
int timeout = 10 * 4; // 10 seconds
while (WiFi.status() != WL_CONNECTED && (timeout-- > 0)) {
delay(250);
Serial.print(".");
}
Serial.println("");
if (WiFi.status() != WL_CONNECTED) {
Serial.println("Failed to connect, going back to sleep");
}
Serial.print("WiFi connected in: ");
Serial.print(millis());
Serial.print(", IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key >= '0' && key <= '9') {
input *= 10;
input += key - '0';
}
lcd.setCursor(0, 1);
lcd.print(input);
Serial.print(input);
if (key == '#') // 'enter'
{
for (size_t i = 0; i < UserCount; i++) {
if (input == Users[i].id) {
SendData(Users[i].name, Users[i].id);
return;
}
}
// User ID not found!
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("No ID Found Like: ");
lcd.setCursor(0, 1);
lcd.println(input);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Your ID:");
input = 0;
}
if (key == '*') {
input = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Your ID:");
}
}
}
void makeIFTTTRequest(const char *name, int id) {
Serial.print("Connecting to ");
Serial.print(server);
WiFiClient client;
int retries = 5;
while (!!!client.connect(server, 80) && (retries-- > 0)) {
Serial.print(".");
}
Serial.println();
if (!!!client.connected()) {
Serial.println("Failed to connect...");
}
Serial.print("Request resource: ");
Serial.println(resource);
// Temperature in Celsius
String jsonObject = String("{\"value1\":\"") + name + "\",\"value2\":\"" + String(id) + "\"}";
client.println(String("POST ") + resource + " HTTP/1.1");
client.println(String("Host: ") + server);
client.println("Connection: close\r\nContent-Type: application/json");
client.print("Content-Length: ");
client.println(jsonObject.length());
client.println();
client.println(jsonObject);
int timeout = 5 * 10; // 5 seconds
while (!!!client.available() && (timeout-- > 0)) {
delay(100);
}
if (!!!client.available()) {
Serial.println("No response...");
}
while (client.available()) {
Serial.write(client.read());
}
Serial.println("\nclosing connection");
client.stop();
}
void SendData(const char *name, int id) {
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("Attended ;)");
lcd.setCursor(0, 1);
lcd.println(name);
makeIFTTTRequest(name, id);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Your ID:");
input = 0;
}