Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- IPAddress ip( 192,168,0,4 );
- byte gateway[] = { 192,168,0,1 };
- byte subnet[] = { 255,255,255,0 };
- IPAddress dns( 192,168,0,1 );
- EthernetServer server(80);
- void setup()
- {
- delay(1500);
- // start the serial library:
- Serial.begin(9600);
- Serial.println("Starting");
- if (Ethernet.begin(mac) == 0)
- {
- Serial.println("Failed to configure Ethernet using DHCP");
- for(;;);
- }
- delay(2000);
- server.begin();
- Serial.print("Init finished IP: ");
- Serial.println(Ethernet.localIP());
- }
- void loop()
- {
- // listen for incoming clients
- EthernetClient client = server.available();
- if (client) {
- Serial.println("Client!");
- // an http request ends with a blank line
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- while(client.available()) {
- char c = client.read();
- // if you've gotten to the end of the line (received a newline
- // character) and the line is blank, the http request has ended,
- // so you can send a reply
- if (c == '\n' && currentLineIsBlank) {
- Serial.println("sending response");
- // send a standard http response header
- client.println("HTTP/1.0 200 OK");
- client.println("Content-Type: text/html");
- client.println();
- client.println("<HTML><BODY>TEST OK!</BODY></HTML>");
- client.stop();
- }
- else if (c == '\n') {
- // you're starting a new line
- currentLineIsBlank = true;
- }
- else if (c != '\r') {
- // you've gotten a character on the current line
- currentLineIsBlank = false;
- }
- }
- }
- Serial.println("Done sending.");
- }
- }
Add Comment
Please, Sign In to add comment