还有另外一个库,程序是
#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[] = { 172,20,10,203 };
char website[] PROGMEM = "api.yeelink.net";
byte Ethernet::buffer[500];
static BufferFiller bfill; // used as cursor while filling the buffer
void setup () {
Serial.begin(9600);
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
Serial.println("Setting up DHCP");
if (!ether.dhcpSetup())
Serial.println( "DHCP failed");
ether.printIp("My IP: ", ether.myip);
ether.printIp("Netmask: ", ether.mymask);
ether.printIp("GW IP: ", ether.gwip);
ether.printIp("DNS IP: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("Server: ", ether.hisip);
Ethernet.begin(mac,ether.myip);
server.begin();
}
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"
"ragma: no-cache\r\n"
"\r\n"
"<meta http-equiv='refresh' content='1'/>"
"<title>RBBB server</title>"
"<h1>$D$DD$DD$D</h1>"),
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);
Serial.println(len);
Serial.println(pos);
if (pos) // check if valid tcp data is received
{
bfill = ether.tcpOffset();
Serial.println("data=");
char* data = (char *) Ethernet::buffer + pos;
// Serial.println(data,DEC);
ether.tcpSend();
delay(200);
}
// ether.httpServerReply(homePage()); // send web page data
}
这个可以ping通,但是数据发不过去,有可能是没弄懂怎么显示,发过去的应该是字符串,不知道怎么转换,搞不懂啊,求大神指点
|