Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

checking status every five seconds and successfully turning on stopli…

…ghts
  • Loading branch information...
commit 5da52ca5a837f25c0d06862dff434b7a85f7cefc 1 parent 7850117
Greg Borenstein authored
Showing with 81 additions and 35 deletions.
  1. +5 −0 github_test_fail.html
  2. +76 −35 stoplight_firmware/stoplight_firmware.pde
View
5 github_test_fail.html
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ <h1>Fail</h1>
+ </body>
+</html>
View
111 stoplight_firmware/stoplight_firmware.pde
@@ -1,58 +1,99 @@
#include <Ethernet.h>
#include <WString.h>
-byte mac[] = { 0x00, 0x26, 0x4a, 0x14, 0x7F, 0x9F };
-byte ip[] = { 192,168,1,147 };
-byte server[] = {128,122,157,177}; // itp.nyu.edu //{ 66,102,7,104 }; // Google
+int red = 2;
+int yellow = 3;
+int green = 4;
+
+byte mac[] = {
+ 0x00, 0x26, 0x4a, 0x14, 0x7F, 0x9F };
+byte ip[] = {
+ 192,168,1,147 };
+byte server[] = {
+ 128,122,157,177}; // itp.nyu.edu //{ 66,102,7,104 }; // Google
#define maxResponseLength 1000
String response = String(maxResponseLength);
+// 0 => not connected
+// 1 => connected
+int notConnectedMode = 0;
+int connectedMode = 1;
+int mode = 0;
+
Client client(server, 80);
void setup()
{
+
+ pinMode(red, OUTPUT);
+ pinMode(yellow, OUTPUT);
+ pinMode(green, OUTPUT);
+
Ethernet.begin(mac, ip);
- Serial.begin(9600);
-
+ // Serial.begin(9600);
+
delay(1000);
-
- Serial.println("connecting...");
-
- if (client.connect()) {
- Serial.println("connected");
- client.println("GET /~gab305/github_test_fail.html HTTP/1.0");
- client.println();
- } else {
- Serial.println("connection failed");
- }
}
void loop()
{
- if (client.available()) {
- char c = client.read();
- //Serial.print(c);
- response.append(c);
- }
-
- if (!client.connected()) {
- // TODO: change this to 412
- if(response.contains("HTTP/1.1 404")){
- if(response.contains("building")){
- Serial.println("YELLOW - 412");
- } else {
- Serial.println("RED - 412");
+ if(mode == notConnectedMode){
+ // try to connect
+ // Serial.println("connecting...");
+ if (client.connect()) {
+ // Serial.println("connected");
+ client.println("GET /~gab305/github_test_fail.html HTTP/1.0");
+ client.println();
+ mode = connectedMode;
+ }
+ else {
+ // Serial.println("connection failed");
+ delay(2000);
+ // Serial.println("trying again...");
+ }
+
+ }
+ // in connectedMode
+ else {
+ if (client.available()) {
+ char c = client.read();
+ // Serial.print(c);
+ response.append(c);
+ }
+
+ if (!client.connected()) {
+ // TODO: change this to 412
+ if(response.contains("HTTP/1.1 404")){
+ if(response.contains("building")){
+ // Serial.println("YELLOW - 412");
+ digitalWrite(yellow, HIGH);
+ delay(1000);
+ digitalWrite(yellow, LOW);
+ }
+ else {
+ // Serial.println("RED - 412");
+ digitalWrite(red, HIGH);
+ delay(1000);
+ digitalWrite(red, LOW);
+ }
+
+ }
+ else if(response.contains("HTTP/1.1 200")){
+ // Serial.println("GREEN - 200");
+ digitalWrite(green, HIGH);
+ delay(1000);
+ digitalWrite(green, LOW);
}
+ // Serial.println();
+ // Serial.println("disconnecting.");
+ client.stop();
- } else if(response.contains("HTTP/1.1 200")){
- Serial.println("GREEN - 200");
+ response = "";
+ mode = notConnectedMode;
+ delay(5000);
}
- Serial.println();
- Serial.println("disconnecting.");
- client.stop();
- for(;;)
- ;
}
}
+
Please sign in to comment.
Something went wrong with that request. Please try again.