-
Notifications
You must be signed in to change notification settings - Fork 0
/
door_security_node.cpp
106 lines (82 loc) · 2.12 KB
/
door_security_node.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <Arduino.h>
#include <Keypad.h>
#include <WiFi.h>
#include <ThingSpeak.h>
#include <LittleFS.h>
#include <SD.h>
#include <Update.h>
#include <ETH.h>
#define irpin 14
const char* ssid = "";
const char* password = "";
WiFiClient client;
unsigned long myChannelNumber = ;
const char* myWriteAPIKey = "";
const byte r = 4;
const byte c = 3;
char keys[r][c] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rpins[r] = {17, 5, 18, 19};
byte cpins[c] = {21, 22, 23};
Keypad keypad = Keypad(makeKeymap(keys), rpins, cpins, r, c);
const String pass = "172931";
String inpPass = "";
int attempt = 0;
int irstate = digitalRead(irpin);
void Connect_to_Wifi();
void pass_check();
void setup() {
Serial.begin(115200);
Connect_to_Wifi();
}
void loop() {
pass_check();
}
void Connect_to_Wifi() {
WiFi.begin(ssid, password);
WiFi.mode(WIFI_STA);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("\nConnection to ThingSpeak Server Established!!!\n");
}
ThingSpeak.begin(client);
}
void pass_check() {
char key = keypad.getKey();
if (key != NO_KEY) {
if (key == '*') {
inpPass = ""; //resetting the input password
Serial.println("\n\tcleared\n\t");
}
else if (key == '#') {
if (inpPass == pass) {
Serial.println("\nCorrect Password\n");
attempt = 0;
}
else {
int x = ThingSpeak.setField(2, irstate);
Serial.println("\nInvalid Password\n");
attempt++;
int c = ThingSpeak.setField(1, attempt);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if (attempt == 3 && irstate == 0) {
Serial.println("\nInvasion Detected!!! Sending Alert!#!#!\n");
}
else if (attempt == 3 && irstate == 1) {
Serial.println("\nCloud Intrusion Detected!!! Please Shutdown the Power!!!\n");
}
}
}
else { //if a number key is pressed
inpPass += key; //add the pressed key to the input password
Serial.print(key); //print the pressed key
}
}
}