[Arduino] Http WebServer (ENC28J60)
Instale a biblioteca:
cd /usr/share/arduino/libraries/ git clone https://github.com/jcw/ethercard.git chmod -R 755 ethercard/ |
Configure os pinos desta forma:
1 Ground——Ground
2 Power——-VCC
3 Reset——-Reset
4 CS———-DigiPin 8
5 SCK———DigiPin 13
6 SI———-DigiPin 11
7 SO———-DigiPin 12
Utilize o exemplo “RBBB server” da biblioteca “ethercard” ou o exemplo abaixo:
#include <EtherCard.h> // ethernet interface mac address, must be unique on the LAN //static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; static byte mymac[] = { 0x00,0x00,0x00,0x00,0x00,0x01 }; static byte myip[] = { 192,168,1,155 }; byte Ethernet::buffer[500]; BufferFiller bfill; void setup () { if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) Serial.println( "Failed to access Ethernet controller"); ether.staticSetup(myip); } 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>" "<br>" "<br>" "<h1>$D$D:$D$D:$D$D</h1>" "<br>" "<br>" ), h/10, h%10, m/10, m%10, s/10, s%10); return bfill.position(); } 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 } |
Referências
- https://github.com/jcw/ethercard/blob/master/examples/rbbb_server/rbbb_server.ino
- http://forum.pjrc.com/archive/index.php/t-16385.html