Thanks for the help.
Below is the code. It's in bad shape since I'm a beginner at coding.
I grabbed the first example found on the internet that used a "WiShield" to turn LEDs on and off.
Turns out that example was a toggle on and off for LEDs. So I have attempted to change that to meet my objective.
The objective is to click on Lock to have Pin 4 pulse for 1 Second to Lock and click on Unlock to have Pin 5 pulse for 1 second to unlock. Along with feedback text messages about being locked or not.
I will control the locks by two methods 1) via Web page, and 2) via URL sent from my automation system. I have reverse engineerd a Kwikset smart deadbolt and plan to access it's H brigde with the WiFiRedback.
Once I get the output results I'm looking for I will need to learn how to clean the code up.
You can see in the sketch that I have commented out the areas where testing failed using text. Where web printing usng "WiServer.print ("text")" caused the outputs to pulse twice instead of once.
I'll take any help I can get.
int redState = 0;
int greenState = 0;
int redPin = 4;
int greenPin = 5;
char garageDoorLock[] = "GDL"; //Remove these Chars when using text
char garageDoorUnlock[] = "GDU"; //Remove these Chars when using text
char eastPatioLock[] = "EPL"; //Remove these Chars when using text
char eastPatioUnlock[] = "EPU"; //Remove these Chars when using text
// Web page serving function
boolean sendMyPage(char* URL) {
// East patio door lock
//if (strcmp(URL, "/eastPatioLock") == 0) {
if (strcmp(URL, "/EPL") == 0){
redState = 1;
digitalWrite(redPin, redState);
delay (1000);
redState = 0;
digitalWrite(redPin, redState);
// WiServer.print("Locked
");
}
//East patio door unlock
//if (strcmp(URL, "/eastPatioUnlock") == 0) {
if (strcmp(URL, "/EPU") == 0){
greenState = 1;
digitalWrite(greenPin, greenState);
delay (1000);
greenState = 0;
digitalWrite(greenPin, greenState);
// WiServer.print("Unlocked
");
}
// Garage door lock
if (strcmp(URL, "/GDL") == 0) {
redState = 1;
digitalWrite(redPin, redState);
delay (1000);
redState = 0;
digitalWrite(redPin, redState);
// WiServer.print("Locked
");
}
// Garage door unlock
if (strcmp(URL, "/GDU") == 0) {
greenState = 1;
digitalWrite(greenPin, greenState);
delay (1000);
greenState = 0;
digitalWrite(greenPin, greenState);
//WiServer.print("Unlocked
");
}
// Check if the requested URL matches "/"
// if (strcmp(URL, "/") == 0) {
// Use WiServer’s print and println functions to write out the page content
WiServer.print("");
WiServer.print("Door Deadbolt Control
");
//WiServer.print("
");
printEastDoorStatus(eastPatioLock, redState);
//printEastDoorStatus("eastPatioLock", redState);
printGarageStatus(garageDoorLock, greenState);
//printGarageStatus("garageDoorLock", greenState);
WiServer.print("The page you requested was: ");
WiServer.print(URL);
WiServer.print("");
// URL was recognized
return true;
//}
// URL not found
return false;
}
void printEastDoorStatus( String doorName, int lightState) {
WiServer.print(doorName);
WiServer.print(" Deadbolt ");
if(lightState ==0) {
WiServer.print("
Click to Lock <a href=/");
WiServer.print(doorName);
WiServer.print(">Lock
");
//WiServer.print ("
");
WiServer.print(" Click to Unlock <a href=/");
WiServer.print(eastPatioUnlock);
//WiServer.print("eastPatioUnlock");
WiServer.print(">Unlock
");
WiServer.print("
");
}
}
void printGarageStatus( String doorName, int lightState) {
WiServer.print(doorName);
WiServer.print(" Deadbolt ");
if(lightState ==0) {
WiServer.print("
Click to Lock <a href=/");
WiServer.print(doorName);
WiServer.print(">Lock
");
//WiServer.print ("
");
WiServer.print(" Click to Unlock <a href=/");
WiServer.print(garageDoorUnlock);
WiServer.print(">Unlock
");
//WiServer.print("
");
}
}
void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
WiServer.init(sendMyPage);
// Enable Serial output and ask WiServer to generate log messages (optional)
Serial.begin(57600);
WiServer.enableVerboseMode(true);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop(){
// Run WiServer
WiServer.server_task();
delay(10);
}