WolPoBox
serveur web interne au réseau local
nécessite une ouverture sur le routeur/box
appel:
http://url:port/mac:123456789AB
#include <EtherCard.h>
#include <IPAddress.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x00,0x14,0xA5,0x76,0x19,0x3A };
static byte lowip= 255; // left part by Dhcp 255 if no!
#define VERSION "WOWlanHttpServer 20131230-1624"
static byte broadcast[4] = {255,255,255,255} ; //{255,255,255,255};
int n=0;
int ok=1;
byte Ethernet::buffer[500]; //??????
BufferFiller bfill; //???????
void setup () {
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println("andiamo ");
Serial.println(VERSION);
Serial.print("Ethernet Controller: ");
if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0) {
ok=0;
Serial.println( "Access Failed.");
} else Serial.println("Ok.");
// ether.staticSetup(myip);
if (ok==1) {
Serial.print("Dhcp: ");
if (!ether.dhcpSetup()) {
ok=0;
Serial.println("failed.");
} else Serial.println("Ok.");
}
if (ok==1){
if (lowip<255) ether.myip[3]=lowip;
Serial.println("Clock Server");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
}
static word homePage() {
n=n+1; // compte les appels à 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>Po server</title>"
"<h1>$D$D:$D$D:$D$D</h1> n= $D"),
h/10, h%10, m/10, m%10, s/10, s%10,n); //???????
return bfill.position(); //???????
}
void loop () {
if (ok==1){
//delay(100);
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos) {// check if valid tcp data is received
for (int p=54;p<len;p=p+1){
Serial.print(char(Ethernet::buffer[p]));
// search mac address
}
byte mac[6] ;
char magic[102];
byte unc;
char alphabet[17]="0123456789ABCDEF";
//Serial.println("mac:");
int imac=-1;
for (int repe=0;repe<6;repe=repe+1) magic[repe]=255;
for (int p=63;p<63+12;p=p+2){
imac=imac+1;
char* ici= strchr(alphabet,char(Ethernet::buffer[p]));
int fort= ici-&alphabet[0];
ici= strchr(alphabet,char(Ethernet::buffer[p+1]));
int faible= ici-&alphabet[0];
mac[imac]=fort*16+faible;
for (int repe=0;repe<16;repe=repe+1){
magic[6+6*repe+imac]=fort*16+faible;
}
}
unsigned int po=100;
ether.sendUdp(magic, sizeof magic, po, broadcast, po);
ok=0;
ether.httpServerReply(homePage()); // send web page data
}
}
}