arduinoethernet w5100網(wǎng)絡(luò)擴(kuò)展模塊,可以使arduino成為簡(jiǎn)單的web服務(wù)器或者通過(guò)網(wǎng)絡(luò)控制讀寫(xiě)arduino的數(shù)字和模擬接口等網(wǎng)絡(luò)應(yīng)用。可直接使用ide中的ethernet庫(kù)文件便可實(shí)現(xiàn)一個(gè)簡(jiǎn)單web服務(wù)器。
同時(shí)該版本的支持minisd卡(tf卡)讀寫(xiě)
該擴(kuò)展板采用了可堆疊的設(shè)計(jì),可直接插到arduino上,同時(shí)我們的其他擴(kuò)展板也可以插上去。
代碼:
/*
* web server
*
* a simple web server that shows the value of the analoginput pins.
*/
#include
byte mac[] = {0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };
byte ip[] = { 192, 168, 0, 15};
serverserver(80);
void setup()
{
ethernet.begin(mac, ip);
server.begin();
}
{
client client = server.available();
if (client) {
https:// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c =client.read();
https:// if we've gotten tothe end of the line (received a newline
https:// character) and theline is blank, the http request has ended,
https:// so we can send areply
if (c == '\\n' &¤t_line_is_blank) {
https:// send astandard http response header
client.println("http/1.1 200 ok");
client.println("content-type: text/html");
client.println();
https:// outputthe value of each analog input pin
client.print("welcome to tinyos");
client.println("
");
client.print("https://*************************************");
client.println("
");
client.print(www.tinyos.net.cn);
client.println("
");
client.print("https://*************************************");
client.println("
");
for (int i =0; i < 6; i++) {
client.print("analog input ");
client.print(i);
client.print(" is ");
client.print(analogread(i));
client.println("
");
}
break;
}
if (c == '\\n') {
https:// we'restarting a new line
current_line_is_blank = true;
} else if (c != '\\r'){
https:// we'vegotten a character on the current line
current_line_is_blank = false;
}
}
}
client.stop();
}
}