@@ -111,43 +111,43 @@ void loop() {
111111 }
112112}
113113
114- void sendResponse (String req , EthernetClient client) {
114+ void sendResponse (String request , EthernetClient client) {
115115 client.println (" HTTP/1.1 200 OK" );
116- if (req == " " ) req = " index.htm" ;
117116
118117 // Send file to client
119- if (req. endsWith ( " .htm " ) ) {
118+ if (request == " " ) {
120119 client.println (" Content-Type: text/html\n\r\n\r " );
121- File webFile = SD.open (req );
120+ File webFile = SD.open (request );
122121 if (webFile) {
123122 while (webFile.available ()) {
124123 client.write (webFile.read ());
125124 }
126125 webFile.close ();
127126 }
128127 }
129- // Other actions
128+ // Button actions and status request
130129 else {
131- Serial.println (" Other" );
132130 client.println (" \n\r\n\r " );
133- if (req == " powerStatus" ) {
134- if (powerLed) client.write (" powerStatus:on" );
135- else client.write (" powerStatus:off" );
131+ switch (request) {
132+ case " powerStatus" :
133+ if (powerLed) client.write (" powerStatus:on" );
134+ else client.write (" powerStatus:off" );
135+ break ;
136+ case " powerOn" :
137+ if (!powerLed) powerOn = true ;
138+ break ;
139+ case " standBy" :
140+ if (powerLed) standBy = true ;
141+ break ;
142+ case " reset" :
143+ if (powerLed) reset = true ;
144+ break ;
145+ case " kill" :
146+ if (powerLed) kill = true ;
147+ break ;
148+ default :
149+ client.println (" HTTP/1.1 404 Not Found\n\r " );
136150 }
137- else if (req == " powerOn" ) {
138- if (!powerLed) powerOn = true ;
139- }
140- else if (req == " standBy" ) {
141- if (powerLed) standBy = true ;
142- }
143- else if (req == " reset" ) {
144- if (powerLed) reset = true ;
145- }
146- else if (req == " kill" ) {
147- if (powerLed) kill = true ;
148- }
149- else
150- client.println (" HTTP/1.1 404 Not Found\n\r " );
151151 }
152152}
153153
0 commit comments