极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9636|回复: 0

求解 web控制uno+opnwtr+w5100 UNO收不到数据问题

[复制链接]
发表于 2014-3-12 21:30:48 | 显示全部楼层 |阅读模式



#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无反应。求解~求大神。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-14 07:24 , Processed in 0.036450 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表