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
Tcp 无法使用Arduino ESP8266或兼容板连接到LocalIP或Localhost(127.0.0.1)_Tcp_Arduino_Esp8266_Loopback Address - Fatal编程技术网

Tcp 无法使用Arduino ESP8266或兼容板连接到LocalIP或Localhost(127.0.0.1)

Tcp 无法使用Arduino ESP8266或兼容板连接到LocalIP或Localhost(127.0.0.1),tcp,arduino,esp8266,loopback-address,Tcp,Arduino,Esp8266,Loopback Address,我试图将我的Arduino ESP8266或任何兼容板(如WeMos mini或NodeMCU)与我的本地服务器连接到localhost(127.0.0.1)或172.xx.xx.xxx端口80,我收到httpResponseCode-1错误。但是如果我把它连接到远程服务器,我会得到一个httpresponsecode200(OK) 我正在运行一个XMPP服务器(即使使用Coldfusion服务器进行了测试),我的代码如下所示。有人能帮忙吗 #包括 #包括 #包括 const char*ssid

我试图将我的Arduino ESP8266或任何兼容板(如WeMos mini或NodeMCU)与我的本地服务器连接到
localhost(127.0.0.1)
172.xx.xx.xxx端口80
,我收到
httpResponseCode
-1错误。但是如果我把它连接到远程服务器,我会得到一个
httpresponsecode200(OK)

我正在运行一个
XMPP
服务器(即使使用Coldfusion服务器进行了测试),我的代码如下所示。有人能帮忙吗

#包括
#包括
#包括
const char*ssid=“ssid”;
const char*password=“password”;
//带URL路径的域名或带路径的IP地址
字符串serverName=”http://stackoverflow.com";// 返回200(确定结果)
//字符串serverName=“127.0.0.1”;//给出-1错误,尝试使用172.xx.xx.xx甚至192.168.xx.xx的IP地址。
//以下变量为无符号长,因为时间以
//毫秒,将很快成为一个大于整型存储的数字。
无符号长lastTime=0;
//计时器设置为10分钟(600000)
//无符号长时间显示=600000;
//将计时器设置为5秒(5000)
无符号长时间显示=5000;
无效设置(){
序列号开始(115200);
WiFi.begin(ssid,密码);
Serial.println(“连接”);
while(WiFi.status()!=WL_已连接){
延迟(500);
连续打印(“.”);
}
Serial.println(“”);
串行打印(“连接到IP地址为:”)的WiFi网络;
Serial.println(WiFi.localIP());
println(“计时器设置为5秒(timerDelay变量),在发布第一次读取之前需要5秒。”);
}
void循环(){
//每10分钟发送一次HTTP POST请求
如果((毫秒()-lastTime)>timerDelay){
//检查WiFi连接状态
如果(WiFi.status()==WL_已连接){
HTTPClient-http;
字符串serverPath=serverName+“?温度=24.37”;
//带URL路径的域名或带路径的IP地址
//http.begin(serverPath.c_str());
http.begin(serverName);
//发送HTTP GET请求
int httpResponseCode=http.GET();
如果(httpResponseCode>0){
Serial.print(“HTTP响应代码:”);
Serial.println(httpResponseCode);
字符串有效负载=http.getString();
Serial.println(有效载荷);
}否则{
Serial.print(“错误代码:”);
Serial.println(httpResponseCode);
}
//免费资源
http.end();
}否则{
Serial.println(“WiFi断开”);
}
lastTime=millis();
}
}

127.0.0.1是Arduino本身,而不是您的本地服务器

每个具有IP地址的主机/计算机也具有IP地址127.0.0.1;它是环回接口的地址

此本地主机地址始终指向当前计算机。Arduino也有这个地址,您正在尝试连接到它


使用XMPP服务器的IP地址;首先找出地址是什么,这比猜测和尝试要好得多。

我的Arduino的IP地址是192.168.10.15,而不是127.0.0.1。127.0.0.1是本地主机,XAMPP在其上运行