2014-3-12 20:56:52 [显示全部楼层]
3687浏览
查看: 3687|回复: 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无反应:'(。求解~求大神。。。

Leotower  中级技师

发表于 2014-3-13 18:24:42

如下来自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
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies |上传

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
关于楼主
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail