布列松 发表于 2015-4-11 11:51:41

tsaiwn 发表于 2015-4-11 08:51 static/image/common/back.gif
问题出在你送出给另一端的 HTTP 回应漏掉了最后的\r\n\r\n

试这:


也是没有效果,和我之前的一样的

布列松 发表于 2015-4-11 17:59:11

tsaiwn 发表于 2015-4-11 08:51 static/image/common/back.gif
问题出在你送出给另一端的 HTTP 回应漏掉了最后的\r\n\r\n

试这:


搞定的,朋友,谢谢你,原来是我自己数组写错了......

布列松 发表于 2015-4-11 23:03:19

tsaiwn 发表于 2015-4-11 08:51 static/image/common/back.gif
问题出在你送出给另一端的 HTTP 回应漏掉了最后的\r\n\r\n

试这:


如果这段代码 我想控制的4个数字口LED,应该怎样改

tsaiwn 发表于 2015-4-11 23:56:28

布列松 发表于 2015-4-11 23:03 static/image/common/back.gif
如果这段代码 我想控制的4个数字口LED,应该怎样改

类似啊
就仿照你现在的, 例如:
// status 改 status2
if(strstr((char *)Ethernet::buffer + pos, "GET /?status2=ON") != 0) {
检查收到不同字符串做不同事情
让status2=ON 代表 led2 ON
}
//...
就复制四分, 各自改一改

但是,
最后那回传要注意友四分:

bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
      "Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
      "<html><head><title>WebLed</title></head>"
      "<body>"
      "LED Status: $S "
      "<a href=\"/?status=$S\"><input type=\"button\" value=\"$S\"></a>"
      "<br><br>"

      "LED2 Status: $S "
      "<a href=\"/?status2=$S\"><input type=\"button\" value=\"$S\"></a>"
      "<br><br>"

      "LED3 Status: $S "
      "<a href=\"/?status3=$S\"><input type=\"button\" value=\"$S\"></a>"
      "<br><br>"

      "LED4 Status: $S "
      "<a href=\"/?status4=$S\"><input type=\"button\" value=\"$S\"></a>"
      "<br><br>"

      "</body></html>\r\n\r\n"      
      ), statusLabel, buttonLabel, buttonLabel,
      statusLabel2, buttonLabel2, buttonLabel2,
      statusLabel3, buttonLabel3, buttonLabel3,
      statusLabel4, buttonLabel4, buttonLabel4,
      );


布列松 发表于 2015-4-12 12:32:55

tsaiwn 发表于 2015-4-11 23:56 static/image/common/back.gif
类似啊
就仿照你现在的, 例如:
// status 改 status2


发现前面如果这样加的话,上传成功,但主板好像是死机了,

char* on = "ON";
char* off = "OFF";
char* statusLabel;
char* buttonLabel;
char* statusLabel2;
char* buttonLabel2;

布列松 发表于 2015-4-12 15:37:03

tsaiwn 发表于 2015-4-11 23:56 static/image/common/back.gif
类似啊
就仿照你现在的, 例如:
// status 改 status2


能不能完整的帮忙改一遍,我今天改了半天也没改好

tsaiwn 发表于 2015-4-12 18:18:46

本帖最后由 tsaiwn 于 2015-4-13 19:26 编辑

布列松 发表于 2015-4-12 15:37 static/image/common/back.gif
能不能完整的帮忙改一遍,我今天改了半天也没改好#include <EtherCard.h>

static byte mymac[] = {0x74,0x69,0x69,0x2D,0x30,0x31};
static byte myip[] = {192,168,1,180};
byte Ethernet::buffer;

const int ledPin = 3;
boolean ledStatus;

char* on = "ON";
char* off = "OFF";
char* statusLabel;
char* buttonLabel;
unsigned char hexdata = {0x01,0x05,0x00,0x10,0xFF,0x00,0x8D,0xFF};
unsigned char yy[] = {0x0 ? ?? ??????? ? };

void setup () {

Serial.begin(9600);
Serial.println("WebLed Demo");

if (!ether.begin(sizeof Ethernet::buffer, mymac, 10))
    Serial.println( "Failed to access Ethernet controller");
else
   Serial.println("Ethernet controller initialized");

if (!ether.staticSetup(myip))
    Serial.println("Failed to set IP address");

Serial.println();

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
ledStatus = false;
}

void loop() {

word len = ether.packetReceive();
word pos = ether.packetLoop(len);
doLed(pos);
doLed2(pos);
doLed3(pos);
doLed4(pos);

    BufferFiller bfill = ether.tcpOffset();
    /////
    bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
      "Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
      "<html><head><title>WebLed</title></head>"
      "<body>"
      "LED Status: $S "
      "<a href=\"/?status=$S\"><input type=\"button\" value=\"$S\"></a>"
      "<br><br>"

      "LED2 Status: $S "
      "<a href=\"/?status2=$S\"><input type=\"button\" value=\"$S\"></a>"
      "<br><br>"

      "LED3 Status: $S "
      "<a href=\"/?status3=$S\"><input type=\"button\" value=\"$S\"></a>"
      "<br><br>"

      "LED4 Status: $S "
      "<a href=\"/?status4=$S\"><input type=\"button\" value=\"$S\"></a>"
      "<br><br>"

      "</body></html>\r\n\r\n"      
      ), statusLabel, buttonLabel, buttonLabel,
      statusLabel2, buttonLabel2, buttonLabel2,
      statusLabel3, buttonLabel3, buttonLabel3,
      statusLabel4, buttonLabel4, buttonLabel4,
      );
/////
    ether.httpServerReply(bfill.position());
}
void doLed( word pos) {
   if(pos) {
    if(strstr((char *)Ethernet::buffer + pos, "GET /?status=ON") != 0) {
      Serial.write(hexdata, 8);
      ledStatus = true;
    }

    if(strstr((char *)Ethernet::buffer + pos, "GET /?status=OFF") != 0) {
      Serial.write(yy,sizeof( yy ));
      ledStatus = false;
    }

    if(ledStatus) {
      digitalWrite(ledPin, HIGH);
      statusLabel = on;
      buttonLabel = off;
    } else {
      digitalWrite(ledPin, LOW);
      statusLabel = off;
      buttonLabel = on;
    }
}
}
void doLed2( word pos ) {
自己參考以下改
}
void doLed3( word pos ) {
自己參考以下改
}
void doLed4(word pos ) {
   if(pos) {
    if(strstr((char *)Ethernet::buffer + pos, "GET /?status4=ON") != 0) {
      ??? ??? Serial.write(hexdata, 8);
      ledStatus4 = true;
    }

    if(strstr((char *)Ethernet::buffer + pos, "GET /?status4=OFF") != 0) {
      ??? ??? Serial.write(yy,sizeof( yy ));
      ledStatus4 = false;
    }

    if(ledStatus4) {
      digitalWrite(ledPin4, HIGH);
      statusLabel4 = on;
      buttonLabel4 = off;
    } else {
      digitalWrite(ledPin4, LOW);
      statusLabel4 = off;
      buttonLabel4 = on;
    }
}
}

tsaiwn 发表于 2015-4-12 18:21:10

tsaiwn 发表于 2015-4-12 18:18 static/image/common/back.gif



注意前面要有各 Variable!
led*2
led*3
led*4
...

布列松 发表于 2015-4-13 00:08:46

tsaiwn 发表于 2015-4-12 18:21 static/image/common/back.gif
注意前面要有各 Variable!
led*2
led*3


doLed2(pos);    这个怎么解



tsaiwn 发表于 2015-4-13 00:17:22

布列松 发表于 2015-4-13 00:08 static/image/common/back.gif
doLed2(pos);    这个怎么解

你是不是自己沒寫以下這
void doLed2( word pos ) {
自己參考以下改
}
void doLed3( word pos ) {
自己參考以下改
}
void doLed4(word pos ) {
   if(pos) {
...

布列松 发表于 2015-4-13 12:41:48

tsaiwn 发表于 2015-4-13 00:17 static/image/common/back.gif
你是不是自己沒寫以下這
void doLed2( word pos ) {
自己參考以下改


我加你QQ 说说

布列松 发表于 2015-4-13 12:45:33

tsaiwn 发表于 2015-4-13 00:17 static/image/common/back.gif
你是不是自己沒寫以下這
void doLed2( word pos ) {
自己參考以下改


我按照这样复制下去,校验有错误提示,不知怎样修改

布列松 发表于 2015-4-13 13:43:54

tsaiwn 发表于 2015-4-13 00:17 static/image/common/back.gif
你是不是自己沒寫以下這
void doLed2( word pos ) {
自己參考以下改


我后面有加 这个代码的

void doLed2( word pos )
   if(pos) {
    if(strstr((char *)Ethernet::buffer + pos, "GET /?status2=ON") != 0) {
      Serial.write(hexdata, 8);
      ledStatus2 = true;
    }

    if(strstr((char *)Ethernet::buffer + pos, "GET /?status2=OFF") != 0) {
      Serial.write(yy,sizeof( yy ));
      ledStatus2 = false;
    }

    if(ledStatus4) {
      digitalWrite(ledPin2, HIGH);
      statusLabel2 = on;
      buttonLabel2 = off;
    } else {
      digitalWrite(ledPin2, LOW);
      statusLabel2 = off;
      buttonLabel2 = on;
    }

}

tsaiwn 发表于 2015-4-13 14:44:11

布列松 发表于 2015-4-13 13:43 static/image/common/back.gif
我后面有加 这个代码的

void doLed2( word pos )


你这句:
void doLed2( word pos )
后面的 "{ " 到哪去了
太离谱了吧 !?
要自己多加油 !

tsaiwn 发表于 2015-4-13 14:47:22

布列松 发表于 2015-4-13 13:43 static/image/common/back.gif
我后面有加 这个代码的

void doLed2( word pos )


最简单就是把我给你的整个
void doLed4(word pos) {
...
...
}
整个复制贴上, 再把有 4 的都改为 2
再复制一份, 把 4 都改为 3
只能帮到这啰 !
页: 1 [2] 3 4
查看完整版本: enc28j60 控制多个 led IO 的代码,模块本身带控制的html页面