]> git.piffa.net Git - sketchbook_andrea_bak/blob - hardware/ethernet/ethernet_hello_world/ethernet_hello_world.ino
Initial Commit
[sketchbook_andrea_bak] / hardware / ethernet / ethernet_hello_world / ethernet_hello_world.ino
1 // This is a demo of the RBBB running as webserver with the Ether Card
2 // Simple Hello World
3
4 #include <EtherCard.h>
5
6 // ethernet interface mac address, must be unique on the LAN
7 static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
8 static byte myip[] = { 192,168,0,100 };
9
10 byte Ethernet::buffer[500];
11 BufferFiller bfill;
12
13 void setup () {
14   if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
15     Serial.println( "Failed to access Ethernet controller");
16   ether.staticSetup(myip);
17 }
18
19 static word homePage() {
20   bfill = ether.tcpOffset();
21   bfill.emit_p(PSTR(
22     "HTTP/1.0 200 OK\r\n"
23     "Content-Type: text/html\r\n"
24     "Pragma: no-cache\r\n"
25     "\r\n"
26     "<meta http-equiv='refresh' content='1'/>"
27     "<title>RBBB server</title>"
28     "<h1>Hello World 2</h1>"));
29   return bfill.position();
30 }
31
32 void loop () {
33   word len = ether.packetReceive();
34   word pos = ether.packetLoop(len);
35   
36   if (pos)  // check if valid tcp data is received
37     ether.httpServerReply(homePage()); // send web page data
38 }