@@ -16,7 +16,13 @@ bool powerOn, standBy, reset, kill;
1616bool powerLed;
1717
1818void setup () {
19+ // PINs and serial
20+ pinMode (IN_PIN_POWER_LED, INPUT_PULLUP);
21+ pinMode (OUT_PIN_POWER, OUTPUT);
22+ pinMode (OUT_PIN_RESET, OUTPUT);
1923 Serial.begin (9600 );
24+
25+ // Server
2026 Ethernet.begin (mac, ip);
2127 server.begin ();
2228 Serial.print (" Server started at " );
@@ -37,11 +43,6 @@ void setup() {
3743 return ;
3844 }
3945 Serial.println (" SUCCESS - Found file." );
40-
41- // PINs
42- pinMode (IN_PIN_POWER_LED, INPUT_PULLUP);
43- pinMode (OUT_PIN_POWER, OUTPUT);
44- pinMode (OUT_PIN_RESET, OUTPUT);
4546}
4647
4748void loop () {
@@ -104,7 +105,8 @@ void loop() {
104105 controlOutput (OUT_PIN_RESET, 500 );
105106 reset = false ;
106107 } else if (kill) {
107- controlOutput (OUT_PIN_POWER, 4500 );
108+ Serial.println (" kill" );
109+ controlOutput (OUT_PIN_POWER, 5000 );
108110 kill = false ;
109111 }
110112}
@@ -113,34 +115,37 @@ void sendResponse(String req, EthernetClient client) {
113115 client.println (" HTTP/1.1 200 OK" );
114116 if (req == " " ) req = " index.htm" ;
115117
118+ // Send file to client
116119 if (req.endsWith (" .htm" )) {
117120 client.println (" Content-Type: text/html\n\r\n\r " );
121+ File webFile = SD.open (req);
122+ if (webFile) {
123+ while (webFile.available ()) {
124+ client.write (webFile.read ());
125+ }
126+ webFile.close ();
127+ }
118128 }
119- else
120- client.println (" \n\r\n\r " );
121-
122- // Send file to client
123- File webFile = SD.open (req);
124- if (webFile) {
125- while (webFile.available ()) {
126- client.write (webFile.read ());
127- }
128- webFile.close ();
129- }
130129 // Other actions
131130 else {
131+ Serial.println (" Other" );
132+ client.println (" \n\r\n\r " );
132133 if (req == " powerStatus" ) {
133134 if (powerLed) client.write (" powerStatus:on" );
134135 else client.write (" powerStatus:off" );
135136 }
136- else if (req == " powerOn" )
137+ else if (req == " powerOn" ) {
137138 if (!powerLed) powerOn = true ;
138- else if (req == " standBy" )
139+ }
140+ else if (req == " standBy" ) {
139141 if (powerLed) standBy = true ;
140- else if (req == " reset" )
142+ }
143+ else if (req == " reset" ) {
141144 if (powerLed) reset = true ;
142- else if (req == " kill" )
145+ }
146+ else if (req == " kill" ) {
143147 if (powerLed) kill = true ;
148+ }
144149 else
145150 client.println (" HTTP/1.1 404 Not Found\n\r " );
146151 }
0 commit comments