极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9866|回复: 0

【求教】ENC28J60 Ethercard库Stash求教

[复制链接]
发表于 2014-5-3 14:10:01 | 显示全部楼层 |阅读模式
依照官方的DEMO改写了点小代码用来POST数据到PHP碰到了一些问题,请各位大大不吝赐教……
1. 每两次POST必定有一次失败…… 服务器没有响应;
2. 在代码跑到一定时间以后,我在PHP端监听POST的数据就是空的了,不知道为什么。后来查了一下JCW的说法是tcpSend()以后会清空Stash,Stash最大能承受3.5K,我怀疑是Stash并没有在tcpSend()之后被释放导致新的数据没有办法写入Stash。有没有什么办法代替tcpSend()释放Stash?还是说我想错了……

部分代码如下: msg是我要发送的报文内容
void send_Data() {


        ether.hisport = 81;
        Stash stash;

        uint8_t msgLen = msg.length();
        Serial.println(msgLen);


        byte sd = stash.create();
        stash.print(msg);
        stash.save();


        Stash::prepare(PSTR("POST /sysinfo/ardu.php HTTP/1.0" "\r\n"
                "Host: server:81" "\r\n"
                "Content-Length: $D" "\r\n"
                // "Connection: close" "\r\n"
                "Content-Type: application/x-www-form-urlencoded" "\r\n" "\r\n"
                "$H" "\r\n"),
        msgLen, sd);
       
        previousMillis = millis();
        Serial.println(previousMillis);
        session_id = ether.tcpSend();
        Serial.print(session_id);
        Serial.print(" was sent to website... ");

        const char* reply;
        while(millis() - previousMillis < TIMEOUT){
                ether.packetLoop(ether.packetReceive());
                if        ( reply = ether.tcpReply(session_id)) break;
        }

        if(reply != 0) {
                if(strstr(reply, "KO - ") != 0) Serial.println(strstr(reply, "KO - "));
                else Serial.println("OK");
        }
        else {Serial.println("No response <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");}
Serial.println(reply);
}
回复

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-13 23:46 , Processed in 0.035131 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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