dousi1875 2015-12-20 10:57
浏览 46

在arduino客户端的php echo输出ghost char

I try to get a timeStamp from php page (http://www.honeyshare.cn/time.php) and use LinkIt ONE board which is Compatible with arduino as client.There is only one line code "echo time();" on php page.Then I get serial output like this

Connecting to AP
Connecting to WebSite
waiting HTTP response:
HTTP/1.1 200 OK
Date: Sun, 20 Dec 2015 09:17:26 GMT
Server: Apache
Vary: User-Agent,Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

7
1450605837
0

disconnected by server 

1450605837 is what I want.7 above this line and 0 below this line is ghost char.If I would not use echo and only write 1450605837 in php file as string, 7 or 0 will not show in the serial output.

Here is LinkIt ONE board code

#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiClient.h>
#define WIFI_AP "XXXX"
#define WIFI_PASSWORD "XXXXX"
#define WIFI_AUTH LWIFI_WPA  // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP.
#define SITE_URL "www.honeyshare.cn"

LWiFiClient c;

void setup()
{
  LWiFi.begin();
  Serial.begin(115200);

  // keep retrying until connected to AP
  Serial.println("Connecting to AP");
  while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }

  // keep retrying until connected to website
  Serial.println("Connecting to WebSite");
  while (0 == c.connect(SITE_URL, 80))
  {
    Serial.println("Re-Connecting to WebSite");
    delay(1000);
  }

  // send HTTP request, ends with 2 CR/LF
//  Serial.println("send HTTP GET request");
  c.println("GET /time.php HTTP/1.1");
  c.println("Host: " SITE_URL);
  c.println("Connection: close");
  c.println();

  // waiting for server response
  Serial.println("waiting HTTP response:");
  while (!c.available())
  {
    delay(100);
  }
}

boolean disconnectedMsg = false;

void loop()
{
  // Make sure we are connected, and dump the response content to Serial
  while (c)
  {
    int v = c.read();
    if (v != -1)
    {
      Serial.print((char)v);
    }
    else
    {
      Serial.println("no more content, disconnect");
      c.stop();
      while (1)
      {
        delay(1);
      }
    }
  }

  if (!disconnectedMsg)
  {
    Serial.println("disconnected by server");
    disconnectedMsg = true;
  }
 delay(500);
}

Is there any idea about this problem? thx

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
    • ¥15 onvif+openssl,vs2022编译openssl64