howdy,
I am currently using a UNO + Ethernet shield which shows me the status of garage door on a basic web server i.e. http://192.168.1.50 - shows the web page with the info . What I was needing ( if at all possible ) if for the status of the door to be show via a query string i.e. http://192.168.1.50/?=open or http://192.168.1.50/?=closed. I am running an npm homebridge server which can send GET requests to see if my garage door is open or not, and as I have nor provided a URL my iPhone freaks out every time I open the garage door using homekit.
I was wondering if this is possible ? any help would be greatly appreciated
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,50);
EthernetServer server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
pinMode(3, INPUT);
}
void loop()
{
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("<!DOCTYPE html>");
client.println("<html>");
client.println("<head>");
client.println("<meta http-equiv=\"refresh\" content=\"1\">");
client.println("</head>");
client.println("<body>");
GetSwitchState(client);
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}
void GetSwitchState(EthernetClient cl)
{
if (digitalRead(5)) {
cl.println("<p>main door is open</p>");
}
else {
}
if (digitalRead(6)) {
cl.println("<p>main door is in the middle</p>");
}
else {
}
if (digitalRead(7)) {
cl.println("<p>main door is closed</p>");
}
else {
}
if (digitalRead(8)) {
cl.println("<p>manual door is closed</p>");
}
else {
}
if (digitalRead(9)) {
cl.println("<p>manual door is open</p>");
}
else {
}
}