Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arduino从网页获取数据_Arduino - Fatal编程技术网

Arduino从网页获取数据

Arduino从网页获取数据,arduino,Arduino,我正在尝试将我的Arduino uno+以太网屏蔽连接到一个php脚本,该脚本从数据库获取一个值,然后发送回,然后显示在串行监视器上。它工作正常,连接成功,我收到了返回的值,但在串行监视器上显示时遇到了问题。它应该只显示服务器发送的内容,而不显示。有人能帮忙吗 串行输出:它应该只输出“值”,但是有些数字不应该存在。如果我把它输出到液晶显示器上,我就不能让它们的数字出现 connecting... connected HTTP/1.1 200 OK Server: cloudflare-nginx

我正在尝试将我的Arduino uno+以太网屏蔽连接到一个php脚本,该脚本从数据库获取一个值,然后发送回,然后显示在串行监视器上。它工作正常,连接成功,我收到了返回的值,但在串行监视器上显示时遇到了问题。它应该只显示服务器发送的内容,而不显示。有人能帮忙吗

串行输出:它应该只输出“值”,但是有些数字不应该存在。如果我把它输出到液晶显示器上,我就不能让它们的数字出现

connecting...
connected
HTTP/1.1 200 OK
Server: cloudflare-nginx
Date: Sat, 04 Jan 2014 15:36:51 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Set-Cookie: __cfduid=dcef101052b82760c1a2de019e6b076141388849811461; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.linku.biz; HttpOnly
X-Powered-By: PHP/5.3.27
CF-RAY: e7901b6dec606e2

4
The 
5
Value
0


disconnecting.
PHP脚本

<?php
echo 'The Value';
?>

阿杜伊诺文字

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };


char server[] = "www.linku.biz";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,177);

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /arduino.php HTTP/1.1");
    client.println("Host: www.linku.biz");
    client.println("Connection: close");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}
#包括
#包括
//在下面输入控制器的MAC地址。
//较新的以太网屏蔽在屏蔽上的标签上印有MAC地址
字节mac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
char服务器[]=“www.linku.biz”;//谷歌名称地址(使用DNS)
//设置DHCP分配失败时要使用的静态IP地址
ip地址ip(192168,0177);
//初始化以太网客户端库
//具有服务器的IP地址和端口
//要连接到的端口(HTTP的默认端口为80):
以太网络客户端;
无效设置(){
//打开串行通信并等待端口打开:
Serial.begin(9600);
而(!串行){
;//等待串行端口连接。仅Leonardo需要
}
//启动以太网连接:
if(以太网开始(mac)==0){
Serial.println(“未能使用DHCP配置以太网”);
//继续下去没有意义,所以永远不要做任何事:
//尝试使用IP地址而不是DHCP连接:
以太网开始(mac,ip);
}
//给以太网屏蔽一秒钟进行初始化:
延迟(1000);
Serial.println(“连接…”);
//如果您获得连接,请通过串行方式报告:
if(客户端连接(服务器,80)){
Serial.println(“已连接”);
//发出HTTP请求:
println(“GET/arduino.php HTTP/1.1”);
client.println(“主机:www.linku.biz”);
client.println(“连接:关闭”);
client.println();
} 
否则{
//如果您没有连接到服务器:
Serial.println(“连接失败”);
}
}
void循环()
{
//如果有可用的传入字节
//从服务器读取并打印它们:
if(client.available()){
char c=client.read();
连续打印(c);
}
//如果服务器已断开连接,请停止客户端:
如果(!client.connected()){
Serial.println();
Serial.println(“断开”);
client.stop();
//永远不做任何事:
虽然(正确);
}
}

不知道这是否有帮助,但请注意,这些数字是读取的可用字符数。4“值”和5“值”


我希望client.available在收到这些字符后立即返回4和5值。我不知道它们是如何转换成ASCI“4”和“5”并打印出来的。

我用这段代码解析数据

String readString;

   //gets byte from ethernet buffer
    readString += client.read(); //places captured byte in 

 //parse readString for request
    index = readString.indexOf("text"); //finds location of first "text"
    data_want = readString.substring(index+some char, index+some char); //captures data String

    Serial.println(data_wand);