Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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
Php Nodemcu不响应http GET请求_Php_Http_Arduino_Esp8266_Nodemcu - Fatal编程技术网

Php Nodemcu不响应http GET请求

Php Nodemcu不响应http GET请求,php,http,arduino,esp8266,nodemcu,Php,Http,Arduino,Esp8266,Nodemcu,我想将HTTP GET请求从我的节点MCU发送到本地主机服务器。nodemcu和我的笔记本电脑都连接到同一个Wifi网络。尽管nodemcu连接到网络,但它不发送请求。 我试着用“邮递员”手动发送请求,然后就成功了。所以我认为问题出在nodemcu代码或设备上。 任何想法都欢迎 #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include &l

我想将HTTP GET请求从我的节点MCU发送到本地主机服务器。nodemcu和我的笔记本电脑都连接到同一个Wifi网络。尽管nodemcu连接到网络,但它不发送请求。 我试着用“邮递员”手动发送请求,然后就成功了。所以我认为问题出在nodemcu代码或设备上。 任何想法都欢迎


#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>

/* Set these to your desired credentials. */
const char *ssid = "******";  //ENTER YOUR WIFI SETTINGS
const char *password = "****";

//Web/Server address to read/write from 
//website or IP address of server

//=======================================================================
//                    Power on setup
//=======================================================================

void setup() {
  delay(1000);
  Serial.begin(115200);
  WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
  delay(1000);
  WiFi.mode(WIFI_STA);        //This line hides the viewing of ESP as wifi hotspot

  WiFi.begin(ssid, password);     //Connect to your WiFi router
  Serial.println("");

  Serial.print("Connecting");
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  //If connection successful show IP address in serial monitor
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //IP address assigned to your ESP
}

//=======================================================================
//                    Main Program Loop
//=======================================================================
void loop() {
  HTTPClient http;    //Declare object of class HTTPClient

  String ADCData, station, getData, Link;
  int adcvalue=253;  //Read Analog value of LDR
  ADCData = String(adcvalue);   //String to interger conversion
  station = "B";

  //GET Data
  getData = "?status=" + ADCData + "&station=" + station ;  //Note "?" //added at front
  Link = "http://localhost/welcome.php" + getData;

  http.begin(Link);     //Specify request destination

  int httpCode = http.GET();            //Send the request
  String payload = http.getString();    //Get the response payload

  Serial.println(httpCode);   //Print HTTP return code
  Serial.println(payload);    //Print request response payload

  http.end();  //Close connection

  delay(5000);  //GET Data at every 5 seconds
}
//=======================================================================


#包括
#包括
#包括
#包括
/*将这些设置为所需的凭据*/
const char*ssid=“*******”//输入您的WIFI设置
常量字符*密码=“****”;
//要从中读取/写入的Web/服务器地址
//服务器的网站或IP地址
//=======================================================================
//开机设置
//=======================================================================
无效设置(){
延迟(1000);
序列号开始(115200);
WiFi.mode(WiFi_OFF);//防止重新连接问题(连接时间过长)
延迟(1000);
WiFi.mode(WiFi_STA);//此行隐藏了ESP作为WiFi热点的查看
WiFi.begin(ssid,密码);//连接到您的WiFi路由器
Serial.println(“”);
串行打印(“连接”);
//等待连接
while(WiFi.status()!=WL_已连接){
延迟(500);
连续打印(“.”);
}
//如果连接成功,在串行监视器中显示IP地址
Serial.println(“”);
串行打印(“连接到”);
序列号println(ssid);
串行打印(“IP地址:”);
Serial.println(WiFi.localIP());//分配给ESP的IP地址
}
//=======================================================================
//主程序循环
//=======================================================================
void循环(){
HTTPClient http;//声明类HTTPClient的对象
字符串ADCData、station、getData、Link;
int adcvalue=253;//读取LDR的模拟值
ADCData=字符串(adcvalue);//字符串到整数的转换
station=“B”;
//获取数据
getData=“?status=“+ADCData+”&station=“+station;//注意”?//添加在前面
链接=”http://localhost/welcome.php“+getData;
http.begin(Link);//指定请求目标
int httpCode=http.GET();//发送请求
字符串负载=http.getString();//获取响应负载
Serial.println(httpCode);//打印HTTP返回代码
Serial.println(负载);//打印请求响应负载
http.end();//关闭连接
延迟(5000);//每5秒获取一次数据
}
//=======================================================================
localhost站点的php代码如下所示

<html>
<body>

status: <?php echo $_GET["status"]; ?><br>
station: <?php echo $_GET["station"]; ?>

</body>
</html>


状态:
电台:
尝试以下方法:

<?php 

echo "<pre>";
print_r($_REQUEST);

?>


localhost是一种简写,意思是“自我”。您告诉NodeMCU将请求发送给它自己,尽管它可能甚至不理解localhost。您需要使用尝试向其发送请求的计算机的实际名称或IP地址。Localhost永远不会像您在这里尝试使用它的方式工作(从一台计算机向另一台计算机发送请求)。

我可以看到您定义了包含查询参数的变量
getData
。但是,我没有看到你在任何地方实际使用这个变量?我在上传到nodemcu时使用了它。在这里错过了。Edited当您说:“到本地主机服务器”,您的意思是您的本地web服务器也在nodemcu设备上吗?如果它在另一台设备上(比如你的笔记本电脑),那么你就不能使用
localhost
,因为它指的是它自己(nodemcu正在调用它自己)。尝试了这个方法。还是没什么。始终在串行监视器中获取-1 127.0.0.1与localhost相同。192.168.***可能是您需要的。