]> git.piffa.net Git - sketchbook_andrea_bak/blob - hardware/ethernet/ethernet_time/ethernet_time.ino
Initial Commit
[sketchbook_andrea_bak] / hardware / ethernet / ethernet_time / ethernet_time.ino
1 //#include <net.h>
2 //#include <EtherCard.h>
3 //#include <enc28j60.h>
4
5 // This is a demo of the RBBB running as webserver with the Ether Card
6 // 2010-05-28 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
7  // https://hwstartup.wordpress.com/2013/03/25/how-to-connect-an-arduino-to-the-internet-for-10/
8
9 #include <EtherCard.h>
10
11 // ethernet interface mac address, must be unique on the LAN
12 static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
13 static byte myip[] = { 192,168,0,100 };
14
15 byte Ethernet::buffer[500];
16 BufferFiller bfill;
17
18 void setup () {
19   if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
20     Serial.println( "Failed to access Ethernet controller");
21   ether.staticSetup(myip);
22 }
23
24 static word homePage() {
25   long t = millis() / 1000;
26   word h = t / 3600;
27   byte m = (t / 60) % 60;
28   byte s = t % 60;
29   bfill = ether.tcpOffset();
30   bfill.emit_p(PSTR(
31     "HTTP/1.0 200 OK\r\n"
32     "Content-Type: text/html\r\n"
33     "Pragma: no-cache\r\n"
34     "\r\n"
35     "<meta http-equiv='refresh' content='1'/>"
36     "<title>RBBB server</title>"
37     "<h1>$D$D:$D$D:$D$D</h1>"),
38       h/10, h%10, m/10, m%10, s/10, s%10);
39   return bfill.position();
40 }
41
42 void loop () {
43   word len = ether.packetReceive();
44   word pos = ether.packetLoop(len);
45   
46   if (pos)  // check if valid tcp data is received
47     ether.httpServerReply(homePage()); // send web page data
48 }