arduino/Mixly心知天气

一、准备

首先百度一下心知天气,获取一下密钥,具体的可以看这一篇Blynk中WebHook组件的使用方法_moshanghuaw的博客-CSDN博客

然后再准备一个esp8266或者esp32都可以

二、程序

mixly程序 

arduino/Mixly心知天气_第1张图片

 arduino程序


#include 
#include 

WeatherNow weatherNow;
Forecast forecast;
LifeInfo lifeInfo;
volatile int item;

void setup(){
  Serial.begin(9600);
  WiFi.begin("xxxxxx", "12345678");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Local IP:");
  Serial.print(WiFi.localIP());

  weatherNow.config("***********", "yongzhou", "c", "zh-Hans");
  forecast.config("***********", "changsha", "c", "zh-Hans");
  lifeInfo.config("***********", "changsha", "c", "zh-Hans");
  item = 0;
}

void loop(){
  delay(1000);
  switch (item) {
   case 0:
    if (weatherNow.update()) {
      item = 1;

    }
    break;
   case 1:
    if (lifeInfo.update()) {
      item = 2;

    }
    break;
   case 2:
    if (forecast.update()) {
      item = 3;

    }
    break;
  }
  Serial.println(weatherNow.getDegree());
  Serial.println(weatherNow.getWeatherText());
  Serial.println(weatherNow.getWeatherCode());
  Serial.println("-----------------------------------");
  Serial.println(forecast.getHigh(0));
  Serial.println(forecast.getLow(0));
  Serial.println(forecast.getDayText(0));
  Serial.println(forecast.getDayCode(0));
  Serial.println(forecast.getNightText(0));
  Serial.println(forecast.getNightCode(0));
  Serial.println(forecast.getRain(0));
  Serial.println(forecast.getWindDirection(0));
  Serial.println(forecast.getWindSpeed(0));
  Serial.println(forecast.getWindScale(0));
  Serial.println(forecast.getHumidity(0));
  Serial.println("-----------------------------------");
  Serial.println(lifeInfo.getCarWash());
  Serial.println(lifeInfo.getDressing());
  Serial.println(lifeInfo.getFactorFlu());
  Serial.println(lifeInfo.getExercise());
  Serial.println(lifeInfo.getTravel());
  Serial.println(lifeInfo.getUV());
  Serial.println("-----------------------------------");

}

需要将程序中你的密钥填进去

三、效果

arduino/Mixly心知天气_第2张图片

arduino/Mixly心知天气_第3张图片 

再配合OLED模块就可以制作一个简单的天气时钟了 

你可能感兴趣的:(Mixly与Arduino,蓝桥杯,fpga开发,职场和发展)