用arduino和w5100怎么网页外网控制led灯?需要什么技术?求指点?
现在能实现局域网控制led灯的开关,现在求怎么通过外网控制led开关?需要服务器吗?需要什么技术 求指点#include <SPI.h>
#include <Ethernet.h>
intred = 9; //设置输出端口
int i ;
int red_color,asc;//定义各颜色的PWM值参数
String POST = "";
String SET = "";
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//服务端IP地址
IPAddress ip(192,168,1,178);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
pinMode(red, OUTPUT);
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
//设置端口为输出
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line-----------
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank){
// it is after the double cr-lf that the variables are
// read another line!
String POST = "";
// int p = 1;
while(client.available())
{
c = client.read();
// save the variables somewhere
POST += c;
}
// send a standard http response header
//打印输出网页代码
client.println("<html><head><title>Lamaq Color palette</title>"
"<style>*{font-family:Arial;}body{background-color:#f2f2f2;}h1{color:#222;}</style>"
"<body><div style='text-align:center;'>"
"<div>Color palette"
"<table width='30%'align='center'>"
"<tr><td>"
"<table width='100%' height='100'cellspacing='1'><tbody><tr>");
/*********************************************************/
client.println("</tr></tbody></table>");
client.println("<tablewidth='100%'id='led'>");
client.print("<tbody><tr>");
client.print("<form method='post' id='ledform'>Led color:");
client.print("<input type='text' name='led' id='led' value='");
/*******************************************************************/
//for (int j=0; j<10; j++){
i = int(POST);
if(i==49){red_color=240;}
if(i==48){red_color=0;}
// }
// i = int(POST);
//{red_color=240;client.print(POST);}
/*********************************************************/
client.print("'>");
client.println("<input type='submit' value='Submit'>"
"</form></tr></tbody></table></td></tr></table></div></div></body></html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
// i=1;
}
analogWrite(red, red_color);
} 上面是局域网代码?怎么弄能实现 外网控制? 急需,各位大师,给点指点。 现在做到了吗? fuhome.net
费用就是一个arduino 再加一个网络模块
页:
[1]