4 Read a value from a Arduino sensor and publish
7 Note: you can set up the NIC with DHCP or static address
11 #include <EtherCard.h>
13 // ethernet interface mac address, must be unique on the LAN
14 static byte mymac[] = {
15 0x74,0x69,0x69,0x2D,0x30,0x31 };
16 //static byte myip[] = { 192,168,0,100 };
18 byte Ethernet::buffer[500];
22 int analogSensor = A0;
27 if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
28 Serial.println( "Failed to access Ethernet controller");
29 ether.staticSetup(myip);
36 Serial.println("\n[getDHCPandDNS]");
37 if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
38 Serial.println( "Failed to access Ethernet controller");
40 if (!ether.dhcpSetup())
41 Serial.println("DHCP failed");
44 static word homePage() {
45 bfill = ether.tcpOffset();
48 "Content-Type: text/html\r\n"
49 "Pragma: no-cache\r\n"
51 "<meta http-equiv='refresh' content='1'/>"
52 "<title>Arduino WebServer</title>"
53 "<h1>Arduino analog Read</h1>"
54 "<p>Analog Value from Arduino: $D</p>"),
56 return bfill.position();
60 sensorRead = analogRead(analogSensor);
62 word len = ether.packetReceive();
63 word pos = ether.packetLoop(len);
65 if (pos) // check if valid tcp data is received
66 ether.httpServerReply(homePage()); // send web page data