https://github.com/Ldufan/ESP8266_Heweather新版和风天气api使用起来比老版本调用方便的多了,但是今天一上午用示例程序没有任何问题,但是放到自己程序里就无法显示天气信息,走else
else { // 更新失败 Serial.println("Update Failed..."); Serial.print("Server Response: "); Serial.println(weatherNow.getServerCode()); // 参考 https://dev.heweather.com/docs/start/status-code }
参考中也没有给出任何建议,
通过自己尝试发现,1)连接wifi成功后再进行和风天气api初始化
weatherNow.config(UserKey, Location, Unit, Lang); // 配置请求信息
2)进入loop循环后,首要进行调取天气,再进行其他操作,具体原因没有搞明白,但是放到后面会导致esp8266重启。
ConnectWiFi(); // 连接WiFi weatherNow.config(UserKey, Location, Unit, Lang); // 配置请求信息 } void loop(){ if(weatherNow.get()){ // 获取天气更新 Serial.println(F("======Weahter Now Info======")); Serial.print("Server Response: "); Serial.println(weatherNow.getServerCode()); // 获取API状态码 Serial.print(F("Last Update: ")); Serial.println(weatherNow.getLastUpdate()); // 获取服务器更新天气信息时间 Serial.print(F("Temperature: ")); Serial.println(weatherNow.getTemp()); // 获取实况温度 Serial.print(F("FeelsLike: ")); Serial.println(weatherNow.getFeelLike()); // 获取实况体感温度 Serial.print(F("Icon: ")); Serial.println(weatherNow.getIcon()); // 获取当前天气图标代码 Serial.print(F("Weather Now: ")); Serial.println(weatherNow.getWeatherText()); // 获取实况天气状况的文字描述 Serial.print(F("windDir: ")); Serial.println(weatherNow.getWindDir()); // 获取实况风向 Serial.print(F("WindScale: ")); Serial.println(weatherNow.getWindScale()); // 获取实况风力等级 Serial.print(F("Humidity: ")); Serial.println(weatherNow.getHumidity()); // 获取实况相对湿度百分比数值 Serial.print(F("Precip: ")); Serial.println(weatherNow.getPrecip()); // 获取实况降水量,毫米 Serial.println(F("========================")); } else { // 更新失败 Serial.println("Update Failed..."); Serial.print("Server Response: "); Serial.println(weatherNow.getServerCode()); // 参考 https://dev.heweather.com/docs/start/status-code } delay(ROUND * 60000); }
标签:esp8266,no,获取,天气,实况,print,weatherNow,println,Serial From: https://www.cnblogs.com/mhkj/p/16665628.html