Skip to content

Instantly share code, notes, and snippets.

@ankit-lakhanpal
Created September 24, 2015 11:39
Show Gist options
  • Save ankit-lakhanpal/c3d0b8e5b37179139a5c to your computer and use it in GitHub Desktop.
Save ankit-lakhanpal/c3d0b8e5b37179139a5c to your computer and use it in GitHub Desktop.
// This is a demo of the RBBB running as webserver with the Ether Card
// 2010-05-28 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
#include <EtherCard.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,0,177 };
int x=120;
byte Ethernet::buffer[500];
BufferFiller bfill;
void setup () {
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println(F("Failed to access Ethernet controller"));
ether.staticSetup(myip);
}
void loop () {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos) // check if valid tcp data is received
ether.httpServerReply(homePage()); // send web page data
}
static word homePage() {
long t = millis() / 1000;
word h = t / 3600;
byte m = (t / 60) % 60;
byte s = t % 60;
bfill = ether.tcpOffset();
bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"\r\n"
"<meta http-equiv='refresh' content='1'/>"
"<title>RBBB server</title>"
"<h1>KARAN's server running $D$D:$D$D:$D$D</h1>"
"<h></h>"),
h/10, h%10, m/10, m%10, s/10, s%10);
return bfill.position();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment