401 Unauthorized
"; void homePage() { bfill.emit_p(PSTR("$F" "" "Relay 2: $F
" "Relay 3: $F
" "Relay 4: $F"), http_OK, PinStatus[1]?PSTR("off"):PSTR("on"), PinStatus[1]?PSTR("ON"):PSTR("OFF"), PinStatus[2]?PSTR("off"):PSTR("on"), PinStatus[2]?PSTR("ON"):PSTR("OFF"), PinStatus[3]?PSTR("off"):PSTR("on"), PinStatus[3]?PSTR("ON"):PSTR("OFF"), PinStatus[4]?PSTR("off"):PSTR("on"), PinStatus[4]?PSTR("ON"):PSTR("OFF")); } void setup() { Serial.begin(9600); if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0); if (!ether.dhcpSetup()); ether.printIp("My Router IP: ", ether.myip); ether.printIp("My SET IP: ", ether.myip); for(int i = 0; i <= 4; i++) { pinMode(LedPins[i],OUTPUT); digitalWrite (LedPins[i],HIGH); PinStatus[i]=false; } } void loop() { delay(1); word len = ether.packetReceive(); // check for ethernet packet / word pos = ether.packetLoop(len); // check for tcp packet / if (pos) { bfill = ether.tcpOffset(); char *data = (char *) Ethernet::buffer + pos; if (strncmp("GET /", data, 5) != 0) { bfill.emit_p(http_Unauthorized); } else { data += 5; if (data[0] == ' ') { homePage(); // Return home page for (int i = 0; i <= 3; i++)digitalWrite(LedPins[i],!PinStatus[i+1]); } else if (strncmp("?ArduinoPIN1=on ", data, 16) == 0) { PinStatus[1] = true; bfill.emit_p(http_Found); } else if (strncmp("?ArduinoPIN2=on ", data, 16) == 0) { PinStatus[2] = true; bfill.emit_p(http_Found); } else if (strncmp("?ArduinoPIN3=on ", data, 16) == 0) { PinStatus[3] = true; bfill.emit_p(http_Found); } else if (strncmp("?ArduinoPIN4=on ", data, 16) == 0) { PinStatus[4] = true; bfill.emit_p(http_Found); } else if (strncmp("?ArduinoPIN1=off ", data, 17) == 0) { PinStatus[1] = false; bfill.emit_p(http_Found); } else if (strncmp("?ArduinoPIN2=off ", data, 17) == 0) { PinStatus[2] = false; bfill.emit_p(http_Found); } else if (strncmp("?ArduinoPIN3=off ", data, 17) == 0) { PinStatus[3] = false; bfill.emit_p(http_Found); } else if (strncmp("?ArduinoPIN4=off ", data, 17) == 0) { PinStatus[4] = false; bfill.emit_p(http_Found); } else { // Page not found bfill.emit_p(http_Unauthorized); } } ether.httpServerReply(bfill.position()); // send http response } }
沒有留言:
張貼留言