ESP8266 Arduino IDE JSON HTTP请求
我一直试图在ESP8266上获取天气信息,以便在OLED显示屏上显示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" +
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();
返回;
}