Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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
ESP8266 Arduino IDE JSON HTTP请求_Json_Wifi_Arduino Esp8266 - Fatal编程技术网

ESP8266 Arduino IDE JSON HTTP请求

ESP8266 Arduino IDE JSON HTTP请求,json,wifi,arduino-esp8266,Json,Wifi,Arduino Esp8266,我一直试图在ESP8266上获取天气信息,以便在OLED显示屏上显示 if (!client.connect("api.apixu.com", 80)) { Serial.println("connection failed"); return;} client.print("GET " + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Content-Type: application/json\r\n" +

我一直试图在ESP8266上获取天气信息,以便在OLED显示屏上显示

if (!client.connect("api.apixu.com", 80)) {
  Serial.println("connection failed");
   return;}

  client.print("GET " + url + " HTTP/1.1\r\n" +
  "Host: " + host + "\r\n" +
  "Content-Type: application/json\r\n" + 
  "Connection: close\r\n\r\n");

   char c[1024];
  // Read all the lines of the reply from server and print them to Serial
   while(client.available()){
      c[0] = client.read();Serial.print(c);}
这是我请求和读取JSON内容的代码。但不管我怎么做,代码都不会进入while循环

有人能发现错误吗


提前谢谢你!:D

我以某种方式修复了它,该代码适用于所有出现相同错误的人,即
available()
始终为0

client.print(字符串(“GET”)+url+“HTTP/1.1\r\n”+
主机:“+Host+”\r\n“+
“连接:关闭\r\n\r\n”);
无符号长超时=毫秒();
while(client.available()==0){
如果(毫秒()-超时>5000){
Serial.println(“>>>客户端超时!”);
client.stop();
返回;
}