Sorry for the long write up i have to devide it into two messages because of the attached sketches code....
Hi everyone
I am new to Arduino and my biggest experience has been trying to get other people sketches to work with my home automation environment which is SmartThings using ST-Anything Arduino libraries developed by Dan (ogiewon) [DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32 - #2814 by richland007 - Projects & Stories - SmartThings Community
When i was trying to automate my door lock which is a strike type i came across this project Smart Door Lock w/ WiFi Login Page by Arduino & ESP8266 - ElectroPeak
which basically has this 2 sketches
1: for the ESP-01
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// WiFi network
const char* ssid = "YourSSID";
const char* password = "YourPASSWORD";
ESP8266WebServer server ( 80 );
char htmlResponse[3000];
void handleRoot() {
snprintf ( htmlResponse, 3000,
"<!DOCTYPE html>\
<html lang=\"en\">\
<head>\
<style>\
body {background-color: rgb(160, 0, 53);}\
h3 {color: white;text-align:center;}\
p {color: white; text-align:center;}\
div {color: white; text-align:center;}\
ID {text-align:center;}\
input {text-align:center;}\
</style>\
<meta charset=\"utf-8\">\
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\
</head>\
<body>\
<h3>\<canter>Electropeak Smart Security Door</canter>\</h3>\
<p>\<canter>Please type your ID</canter>\</p>\
<div>ID: <input type='text' name='pass_word' id='pass_word' align='center' size=10 autofocus></div> \
<div>\
<button id=\"save_button\">Log In</button>\
</div>\
<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js\"></script>\
<script>\
var pass;\
$('#save_button').click(function(e){\
e.preventDefault();\
pass = $('#pass_word').val();\
$.get('/save?pass=' + pass, function(data){\
console.log(data);\
});\
});\
</script>\
</body>\
</html>");
server.send ( 200, "text/html", htmlResponse );
}
void handleSave() {
if (server.arg("pass")!= ""){
Serial.println(server.arg("pass"));
}
}
void setup() {
// Start serial
Serial.begin(115200);
delay(10);
// Connecting to a WiFi network
Serial.println();
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());
server.on ( "/", handleRoot );
server.on ("/save", handleSave);
server.begin();
Serial.println ( "HTTP server started" );
}
void loop() {
server.handleClient();
}
and this one for the Arduino UNO-R3 (which i have no idea why is he using it when the ESP-01 could do it all)
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete
void setup() {
// initialize serial:
Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
pinMode(9,OUTPUT);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
if (inputString=="your_password")
{
digitalWrite(9,HIGH);
delay(300);
digitalWrite(9,LOW);
Serial.println(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}