4725| 1
|
[已解决] 求解 web控制uno+opnwtr+w5100 问题 |
#include <SPI.h> #include <Ethernet.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,1, 177); int ledPin7 = 7; char cc = ' '; char ccc = ' '; EthernetServer server(80); void setup() { Serial.begin(9600); while (!Serial) { ; } pinMode(ledPin7, OUTPUT); Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); } void loop() { EthernetClient client = server.available(); if (client) { Serial.println("new client"); boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connnection: close"); client.println(); client.println("<!DOCTYPE HTML>"); client.println("<html>"); // client.println("<meta http-equiv=\"refresh\" content=\"5\">"); for (int analogChannel = 0; analogChannel < 6; analogChannel++) { int sensorReading = analogRead(analogChannel); if (analogChannel == 1) { int A1 = analogRead(analogChannel); int guangqiang = A1; client.print(guangqiang); client.print(":"); } else if (analogChannel == 2) { int A2 = analogRead(analogChannel); int wendu= (A2*0.0048828125*100); client.print(wendu); } } client.println("</html>"); // byte c = client.read(); if(c == 'O' && cc == '=') { if(ccc == 'X') { digitalWrite(7,HIGH); } else if(ccc == 'Y') { digitalWrite(7,LOW); } } ccc = cc; cc = c; break; } if (c == '\n') { currentLineIsBlank = true; } else if (c != '\r') { currentLineIsBlank = false; } } } delay(1); client.stop(); Serial.println("client disonnected"); } } 下位机代码 web里能收到返回的温度值,但是web给UNO发指令 uno无反应:'(。求解~求大神。。。 |
如下来自my friend: Jose from Spain Step 1; Add a button form in his page: http://www.w3school.com.cn/tags/tag_button.asp <form action = "" method = "post"> <button type="ArduinoAction">Click Me!</button> <form> step 2: (pseudocode) similar to line 24, if ( c = ArduinoAction ) turn on LED |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed