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
C++ Arduino http请求_C++_Arduino_Httprequest - Fatal编程技术网

C++ Arduino http请求

C++ Arduino http请求,c++,arduino,httprequest,C++,Arduino,Httprequest,我将数据发送到Web服务器,Web服务器存储在mysql数据库中。如何将stuff(ok)变量返回到arduino并进行串行打印(#stuff) PHP文件: $stuff = ""; include("conec.php"); if ($_GET["value"]) { $link=Conection(); $Sql="insert into table (VALUE) values ('".($_GET["value"])."')"; mysql_query($Sql,$link); $s

我将数据发送到Web服务器,Web服务器存储在mysql数据库中。如何将stuff(ok)变量返回到arduino并进行串行打印(#stuff)

PHP文件:

$stuff = "";
include("conec.php");
if ($_GET["value"]) {
$link=Conection();
$Sql="insert into table (VALUE) values ('".($_GET["value"])."')"; 
mysql_query($Sql,$link);
$stuff = ok;
}

我不知道arduino,但我猜是
client.read()从响应中读取一个字符。现在,您正在读取变量
c
,并覆盖该变量,直到读取整个响应。尝试创建字符串缓冲区,并将字符读入字符串。完成后,请尝试打印出缓冲区

如果不进行任何测试,代码将遵循以下原则:

string buffer;
int counter = 0;
while (client.connected()) {
  while (client.available()) {
   buffer[counter++] = client.read();
  }
}
Serial.println("Closing connection");
Serial.println("Buffer value is: " + buffer);
client.close();
这将取代:

char c = client.read();
while (client.connected()) {
  while (client.available()) {
   char c = client.read();
  }
}
Serial.println("Closing connection");
client.close();
您还必须在PHP文件中放入
echo$stuff
,以便响应传入的请求

编辑

你还有几个问题。mysql库已被弃用,我建议查看mysqli php库。您还容易受到SQL注入的攻击,即
$\u GET[“value”]
直接注入SQL查询字符串。考虑使用函数mysqli\u real\u escape\u string()来保护自己


您也没有将
$stuff
分配给字符串。请确保将
ok
放在引号中。

您只是想将输出结果回传给请求吗<代码>echo$stuff我想使用我发送的$stuff变量在arduino中进行串行打印。不起作用,逻辑看起来不错,但什么也没有显示:缓冲区值是:将浏览器导航到运行PHP文件的服务器,它应该打印您要查找的值。另外,请查看定义
$stuff
的位置,确保通过将
中的“ok”
放在引号中,将其分配给字符串。此外,在PHP文件中,使用mysql\u real\u escape\u string()函数进行SQL注入检查会使您很容易受到攻击。mysql库也不推荐使用,请改为使用mysqli。我已经尝试使用此“”或“”,我可以看到打印此$stuff,但arduino无法读取此值,我不知道为什么。谢谢你的sql表示法,但我会在第二步中解决这个问题,因为这不是我现在的首要任务。
char c = client.read();
while (client.connected()) {
  while (client.available()) {
   char c = client.read();
  }
}
Serial.println("Closing connection");
client.close();