Blinker 天气时钟8266 12864LCD屏(针对新版库v0.3.4接口更新)-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 20909|回复: 48

[分享] Blinker 天气时钟8266 12864LCD屏(针对新版库v0.3.4接口更新)

[复制链接]
发表于 2020-6-22 22:10 | 显示全部楼层 |阅读模式
本帖最后由 526598 于 2020-7-6 09:33 编辑

本贴针对 blinker新版本库(v0.3.4)天气接口重新编写程序
/\ \     /\ \    __        /\ \              v0.3.4
\ \ \___ \ \ \  /\_\    ___\ \ \/'\      __   _ __   
.\ \ '__`\\ \ \ \/\ \ /' _ `\ \ , <    /'__`\/\`'__\
  \ \ \L\ \\ \ \_\ \ \/\ \/\ \ \ \\`\ /\  __/\ \ \./
   \ \_,__/ \ \__\\ \_\ \_\ \_\ \_\ \_\ \____\\ \_\  
    \/___/   \/__/ \/_/\/_/\/_/\/_/\/_/\/____/ \/_/

低于此版本请参考https://www.arduino.cn/thread-98403-1-1.html
材料清单请参考我之前的帖子https://www.arduino.cn/thread-98403-1-1.html
此版程序自定义天气图标(上一版的样式太少)
增加屏幕刷新功能,因为复工之前工作积攒的比较多时间有限,有些地方不是很满意,希望大家多包涵
天气信息于Blinker点灯平台获取
Lcd12864 驱动为u8g2
参考资料及部分代码来自:https://www.arduino.cn/thread-41193-1-1.html
OLED/LCD/12864 WEB在线图片取模工具beta https://www.arduino.cn/thread-42174-1-1.html
时间字体:u8g2_font_logisoso28_tf
日期字体:u8g2_font_wqy12_t_gb2312a
温度字体:u8g2_font_wqy16_t_gb2312b
字体请参考u8g2库文件 (win10)C:\Users\Administrator\Documents\Arduino\libraries\u8g2\src\clib\u8g2.h
U8g2lib库在Arduino中 项目-加载库-管理库-搜索u8g2-安装即可或参考https://github.com/olikraus/u8g2
手动下载地址(未在其他机器测试):http://downloads.arduino.cc/libraries/github.com/olikraus/U8g2-2.27.6.zip
其他型号LCD参考Arduino开发软件的文件-示例-u8g2,任选里面有好多注释掉的连接方式仔细看备注
其他问题后面补充,有疑问请留言,所学有限尽量回答,见谅!

视频地址:https://www.bilibili.com/video/BV12k4y1679Q/
微信图片_20200622214414.jpg

连接图
8266 ESP -01
微信图片_20200523204041.png

连接图
8266 ESP -12F注意U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 0, /* data=*/ 2, /* CS=*/ 1, /* reset=*/ 16);// Feather HUZZAH ESP8266, E=clock=14, RW=data=13, RS=CS
因为esp-12f针脚比较充裕 修改 /*CS=*/ 1 为 /*CS=*/ 4 ,方便布线。下图为3v12864接法,5v12864请将红黑线分别接到5v正负上
esp-12f2.png
esp-12f针脚定义参考
esp-12f.jpg



  1. #define BLINKER_WIFI
  2. #include <Blinker.h>
  3. #include <SPI.h>
  4. #include <U8g2lib.h>

  5. char auth[] = "Your Device Secret Key";
  6. char ssid[] = "Your WiFi network SSID or name";
  7. char pswd[] = "Your WiFi network WPA password or WEP key";

  8. char w_addr[]="beijingshi"; /*城市关键字.注意不要有空格
  9. 城市关键字,参考 https://diandeng.tech/doc/weather-and-air
  10. */
  11. int num_second=0;
  12. int num_minute=0;
  13. int num_hour=0;
  14. int num_month=0;
  15. int num_mday=0;
  16. int num_year=0;
  17. char aqi_level[12]="";
  18. char aqi_pm25[8]="";
  19. char aqi_pm10[8]="";
  20. char aqi_SO2[8]="";
  21. char aqi_NO2[8]="";
  22. char aqi_CO[8]="";
  23. char aqi_O3[8]="";
  24. char aqi_4[26]="";
  25. int weather_code=0;
  26. char w_weather[10]="";
  27. char w_temp[7]="18 °C";
  28. char* ch;//用于查找数据是否包含天气关键字时接受返回值
  29. bool first_label=false; //开机标签,开机第一时间更新天气信息
  30. U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 0, /* data=*/ 2, /* CS=*/ 1, /* reset=*/ 16); // Feather HUZZAH ESP8266, E=clock=14, RW=data=13, RS=CS
  31. //天气图标列表[阴,雪,雨,多云,晴,雾霾,夜晚晴,夜晚多云] 取模教程 https://www.arduino.cn/thread-42174-1-1.html
  32. static unsigned char weather_icon[8][180]={/*阴*/
  33.   {   0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
  34.       0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,
  35.       0xE0,0x3F,0x00,0xF0,0x00,0xF0,0xFF,0x00,0xF0,0x00,0x38,0xC0,0x01,0xF0,0x00,0x0C,0x00,0x03,
  36.       0xF0,0x00,0x06,0x00,0x06,0xF0,0x00,0x07,0x00,0x0E,0xF0,0xE0,0x03,0x00,0x0C,0xF0,0xF0,0x03,
  37.       0x00,0x0C,0xF0,0x38,0x00,0x00,0x18,0xF0,0x0C,0x00,0x00,0xF8,0xF0,0x0E,0x00,0x00,0xF8,0xF1,
  38.       0x06,0x00,0x00,0x80,0xF3,0x06,0x00,0x00,0x00,0xF7,0x06,0x00,0x00,0x00,0xF6,0x06,0x00,0x00,
  39.       0x00,0xF6,0x06,0x00,0x00,0x00,0xF6,0x06,0x00,0x00,0x00,0xF6,0x0E,0x00,0x00,0x00,0xF6,0x0C,
  40.       0x00,0x00,0x00,0xF7,0x38,0x00,0x00,0x80,0xF3,0xF0,0xFF,0xFF,0xFF,0xF1,0xE0,0xFF,0xFF,0xFF,
  41.       0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,
  42.       0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
  43.       /*雪*/
  44.   {   0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
  45.       0x00,0xF0,0x00,0x80,0x19,0x00,0xF0,0x00,0x80,0x1F,0x00,0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,
  46.       0x00,0x06,0x00,0xF0,0x00,0x00,0x06,0x00,0xF0,0x80,0x01,0x06,0x18,0xF0,0x80,0x01,0x06,0x18,
  47.       0xF0,0x80,0x01,0x06,0x18,0xF0,0xE0,0x83,0x1F,0x7E,0xF0,0xE0,0xFF,0xF9,0x7F,0xF0,0x00,0xFC,
  48.       0xF0,0x03,0xF0,0x00,0x70,0xE0,0x00,0xF0,0x00,0x30,0xC0,0x00,0xF0,0x00,0x30,0xC0,0x00,0xF0,
  49.       0x00,0x30,0xC0,0x00,0xF0,0x00,0x30,0xC0,0x00,0xF0,0x00,0x70,0xE0,0x00,0xF0,0x00,0xFC,0xF0,
  50.       0x03,0xF0,0xE0,0xFF,0xF9,0x7F,0xF0,0xE0,0x87,0x1F,0x7C,0xF0,0x80,0x01,0x06,0x18,0xF0,0x80,
  51.       0x01,0x06,0x18,0xF0,0x80,0x01,0x06,0x18,0xF0,0x00,0x00,0x06,0x00,0xF0,0x00,0x00,0x06,0x00,
  52.       0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,0x80,0x1F,0x00,0xF0,0x00,0x80,0x19,0x00,0xF0,0x00,0x00,
  53.       0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
  54.       /*雨*/
  55.   {   0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
  56.       0x00,0xF0,0x00,0xC0,0x3F,0x00,0xF0,0x00,0xF0,0xFF,0x00,0xF0,0x00,0x38,0xC0,0x01,0xF0,0x00,
  57.       0x1C,0x80,0x03,0xF0,0x00,0x0C,0x00,0x03,0xF0,0x00,0x06,0x00,0x06,0xF0,0xE0,0x07,0x00,0x06,
  58.       0xF0,0xF0,0x03,0x00,0x04,0xF0,0x38,0x00,0x00,0x1C,0xF0,0x18,0x00,0x00,0xFC,0xF0,0x0C,0x00,
  59.       0x00,0xF8,0xF1,0x0C,0x00,0x00,0x80,0xF1,0x0C,0x00,0x00,0x00,0xF3,0x0C,0x00,0x00,0x00,0xF3,
  60.       0x0C,0x00,0x00,0x00,0xF3,0x18,0x30,0x0C,0x03,0xF3,0x38,0x30,0x0C,0x83,0xF1,0x70,0x30,0x0C,
  61.       0xC3,0xF1,0x60,0x18,0x86,0xC1,0xF0,0x00,0x18,0x86,0x01,0xF0,0x00,0x18,0x86,0x01,0xF0,0x00,
  62.       0x1C,0xC7,0x01,0xF0,0x00,0x0C,0xC3,0x00,0xF0,0x00,0x0C,0xC3,0x00,0xF0,0x00,0x00,0x03,0x00,
  63.       0xF0,0x00,0x80,0x01,0x00,0xF0,0x00,0x80,0x01,0x00,0xF0,0x00,0x80,0x01,0x00,0xF0,0x00,0x00,
  64.       0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
  65.       /*多云*/
  66.   {   0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
  67.       0x00,0xF0,0x00,0x00,0x38,0x00,0xF0,0x80,0x03,0x30,0x00,0xF0,0x80,0x01,0x20,0x00,0xF0,0x80,
  68.       0x00,0x00,0x00,0xF0,0x00,0xE0,0x07,0x00,0xF0,0x00,0xF8,0x0F,0x00,0xF0,0x00,0x1C,0x1C,0x00,
  69.       0xF0,0x00,0x0E,0x30,0x00,0xF0,0x00,0x06,0x70,0x00,0xF0,0x00,0x07,0x60,0x08,0xF0,0x00,0x03,
  70.       0xC0,0x18,0xF0,0x08,0x03,0xC0,0x08,0xF0,0x0C,0xC3,0x7F,0x00,0xF0,0x08,0xE3,0xFF,0x00,0xF0,
  71.       0x00,0x7E,0xE0,0x00,0xF0,0x00,0x1E,0x80,0x01,0xF0,0x00,0x1C,0x80,0x03,0xF0,0x00,0x0E,0x00,
  72.       0x03,0xF0,0xC0,0x0F,0x00,0x03,0xF0,0xE0,0x07,0x00,0x03,0xF0,0x70,0x00,0x00,0x1F,0xF0,0x38,
  73.       0x00,0x00,0x7F,0xF0,0x38,0x00,0x00,0xFE,0xF0,0x38,0x00,0x00,0xE0,0xF1,0x38,0x00,0x00,0xC0,
  74.       0xF1,0x70,0x00,0x00,0xC0,0xF1,0xE0,0xFF,0xFF,0xFF,0xF0,0xC0,0xFF,0xFF,0x7F,0xF0,0x00,0xFE,
  75.       0xFF,0x1F,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
  76.       /*晴*/
  77.   {   0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
  78.       0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x06,0x00,0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,
  79.       0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
  80.       0xF0,0xC0,0x81,0x1F,0x38,0xF0,0xC0,0xC0,0x3F,0x30,0xF0,0x40,0xE0,0x70,0x20,0xF0,0x00,0x30,
  81.       0xC0,0x00,0xF0,0x00,0x38,0xC0,0x01,0xF0,0x00,0x18,0x80,0x01,0xF0,0x00,0x18,0x80,0x01,0xF0,
  82.       0x00,0x18,0x80,0x01,0xF0,0x00,0x18,0x80,0x01,0xF0,0x00,0x38,0xC0,0x01,0xF0,0x00,0x30,0xC0,
  83.       0x00,0xF0,0x40,0xE0,0x70,0x20,0xF0,0xC0,0xC0,0x3F,0x30,0xF0,0xC0,0x81,0x1F,0x38,0xF0,0x00,
  84.       0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
  85.       0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,0x00,0x06,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,
  86.       0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
  87.       /*雾霾*/
  88.   {   0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
  89.       0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x80,0x1F,0x00,0xF0,0x00,0xE0,0x7F,0x00,0xF0,0x00,
  90.       0x70,0xE0,0x00,0xF0,0x00,0x18,0x80,0x01,0xF0,0x00,0x0C,0x00,0x03,0xF0,0x00,0x04,0x00,0x02,
  91.       0xF0,0xC0,0x07,0x00,0x06,0xF0,0xE0,0x03,0x00,0x04,0xF0,0x70,0x00,0x00,0x04,0xF0,0x18,0x00,
  92.       0x00,0x7C,0xF0,0x1C,0x00,0x00,0xFC,0xF0,0x0C,0x00,0x00,0xC0,0xF1,0x0C,0x00,0x00,0x80,0xF3,
  93.       0x0C,0x00,0x00,0x00,0xF3,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
  94.       0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0xF0,0xFF,0x8F,0xFF,0xF0,0xF0,0xFF,0x8F,0xFF,0xF0,0x00,
  95.       0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
  96.       0xF0,0xF0,0xF8,0xFF,0xFF,0xF0,0xF0,0xF8,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,
  97.       0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
  98.       /*夜晚晴*/
  99.   {   0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
  100.       0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x18,0x00,0xF0,0x00,0x06,0x3C,0x00,0xF0,0x00,
  101.       0x0F,0xFF,0x00,0xF0,0x80,0x0F,0x7E,0x00,0xF0,0xC0,0x0D,0x3C,0x00,0xF0,0xC0,0x0C,0x7E,0x00,
  102.       0xF0,0x60,0x0C,0x66,0x00,0xF0,0x60,0x0C,0x00,0x00,0xF0,0x30,0x0C,0x00,0x00,0xF0,0x30,0x1C,
  103.       0x00,0x00,0xF0,0x30,0x18,0x00,0x00,0xF0,0x30,0x18,0x00,0x08,0xF0,0x30,0x30,0x00,0x3E,0xF0,
  104.       0x30,0x70,0x00,0x1C,0xF0,0x30,0xE0,0x00,0x14,0xF0,0x30,0xC0,0x01,0x00,0xF0,0x30,0x80,0x03,
  105.       0x00,0xF0,0x30,0x00,0x07,0x00,0xF0,0x60,0x00,0x3E,0x00,0xF0,0x60,0x00,0xF8,0x1F,0xF0,0xC0,
  106.       0x00,0xE0,0x3F,0xF0,0xC0,0x01,0x00,0x38,0xF0,0x80,0x03,0x00,0x1C,0xF0,0x00,0x07,0x00,0x0E,
  107.       0xF0,0x00,0x1E,0x80,0x07,0xF0,0x00,0xF8,0xFF,0x01,0xF0,0x00,0xE0,0x7F,0x00,0xF0,0x00,0x00,
  108.       0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
  109.       /*夜晚多云*/
  110.   {   0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x0C,0x00,0xF0,0x00,0x00,0x0E,
  111.       0x00,0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,0x80,0x0F,0x00,0xF0,0x00,
  112.       0x80,0x1D,0x00,0xF0,0x00,0xC0,0x19,0x00,0xF0,0x00,0xC0,0x18,0x00,0xF0,0x00,0xC0,0x30,0x00,
  113.       0xF0,0x00,0xC0,0x70,0x00,0xF0,0x00,0xC0,0xE0,0x00,0xF0,0x00,0x80,0xC1,0x01,0xF0,0x00,0x80,
  114.       0x81,0x03,0xF0,0x00,0x80,0x07,0x1F,0xF0,0x00,0xC0,0x3F,0xFC,0xF3,0x00,0xE0,0x7F,0xF0,0xF3,
  115.       0x00,0x70,0xE0,0xE0,0xF1,0x00,0x38,0xC0,0xF9,0xF0,0x00,0x18,0x80,0x3F,0xF0,0x00,0x1E,0x80,
  116.       0x0F,0xF0,0xC0,0x0F,0x00,0x03,0xF0,0xE0,0x0F,0x00,0x03,0xF0,0x70,0x00,0x00,0x07,0xF0,0x30,
  117.       0x00,0x00,0x7F,0xF0,0x30,0x00,0x00,0xFE,0xF0,0x30,0x00,0x00,0xC0,0xF0,0x30,0x00,0x00,0xC0,
  118.       0xF0,0x70,0x00,0x00,0xC0,0xF0,0xE0,0xFF,0xFF,0xFF,0xF0,0xC0,0xFF,0xFF,0x7F,0xF0,0x00,0xFE,
  119.       0xFF,0x1F,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0}
  120.   };
  121. //天气图标列表[阴,雪,雨,多云,晴,雾霾,夜晚晴,夜晚多云]
  122. void weatherData(const String & data){  //更新天气数据
  123.     DynamicJsonDocument jsonBuffer(256);
  124.     //BLINKER_LOG("weather: ", data);
  125.     if(data[0]=='{'){
  126.       //BLINKER_LOG("成功获取天气信息!");
  127.       first_label=false;  
  128.       DeserializationError error = deserializeJson(jsonBuffer, data);
  129.       JsonObject doc = jsonBuffer.as<JsonObject>();
  130.       //Serial.print("sizeof(doc):");
  131.       //Serial.println(sizeof(doc));
  132.       if(error!= NULL){    //天气获取失败
  133.         //BLINKER_LOG("weatherData_error!");
  134.         delay(60000);
  135.         return;
  136.       }
  137.       else{   
  138.         //BLINKER_LOG("分解天气信息");  
  139.         //doc["city"]                         //城市或地区
  140.         //doc["province"]                     //
  141.         strcpy(w_weather,doc["weather"]);    //天气现象 "阴"
  142.         strcpy(w_temp,doc["temp"]);          //温度 "24"  
  143.         strcat(w_temp," °C");
  144.         //doc["humi"]                         //湿度 "86"  
  145.         //doc["wind"]                         //风向 "北"
  146.         //doc["power"]                        //风力 "≤3"
  147.         //doc["updateTime"]:                  //更新时间 "2020-06-21 18:26:00"
  148.         //天气图标列表[阴,雪,雨,多云,晴,雾霾,夜晚晴,夜晚多云]
  149.         //BLINKER_LOG("分解天气信息2");
  150.         if((ch=strstr(w_weather,"雪"))!=NULL){
  151.           weather_code=1;
  152.         }
  153.         else if((ch=strstr(w_weather,"雨"))!=NULL){
  154.           weather_code=2;
  155.         }
  156.         else if((ch=strstr(w_weather,"阴"))!=NULL){
  157.           weather_code=0;
  158.         }
  159.         else if((ch=strstr(w_weather,"云"))!=NULL){
  160.           if (Blinker.hour()<18){
  161.             weather_code=3;
  162.           }
  163.           else{
  164.             weather_code=7;
  165.           }         
  166.         }
  167.         else if((ch=strstr(w_weather,"晴"))!=NULL){
  168.           if (Blinker.hour()<18){
  169.             weather_code=4;
  170.           }
  171.           else{
  172.             weather_code=6;
  173.           }
  174.         }
  175.         else if(((ch=strstr(w_weather,"雾"))!=NULL)or((ch=strstr(w_weather,"霾"))!=NULL)){
  176.           weather_code=5;
  177.         }
  178.       }
  179.     }
  180.     else{
  181.       //BLINKER_LOG("天气信息获取失败!请检查地址变量w_addr[]=",w_addr,",或获取天气数据次数用尽!");
  182.       //BLINKER_LOG("1分钟后重试");
  183.       delay(60000);
  184.     }
  185. }
  186. void airData(const String & data){      //更新空气数据
  187.     //BLINKER_LOG("AQI: ", data);
  188.     if(data[0]=='{'){
  189.       DynamicJsonDocument jsonBuffer(512);
  190.       DeserializationError error = deserializeJson(jsonBuffer, data);
  191.       JsonObject doc = jsonBuffer.as<JsonObject>();
  192.       if(error != NULL){    //天气获取失败
  193.         //BLINKER_LOG("airData_error!");
  194.         //Serial.println(error.c_str());
  195.         delay(1000);
  196.         //return;
  197.       }
  198.       else{
  199.         strcpy(aqi_level,doc["level"]);
  200.         //Serial.println(strlen(doc["pm25"]));
  201.         if(strlen(doc["pm25"])<2){
  202.           strcpy(aqi_pm25," ");
  203.         }
  204.         strcat(aqi_pm25,doc["pm25"]);
  205.         strcpy(aqi_pm10,doc["pm10"]);
  206.         //Serial.println(strlen(doc["SO2"]));
  207.         if(strlen(doc["SO2"])<2){
  208.           strcpy(aqi_SO2," ");
  209.         }
  210.         strcat(aqi_SO2,doc["SO2"]);
  211.         strcpy(aqi_NO2,doc["NO2"]);
  212.         //Serial.println(strlen(doc["CO"]));
  213.         if(strlen(doc["CO"])<2){
  214.           strcpy(aqi_CO," ");
  215.         }
  216.         strcat(aqi_CO,doc["CO"]);
  217.         strcpy(aqi_O3,doc["O3"]);
  218.         //BLINKER_LOG("成功获取空气数据!");
  219.         //BLINKER_LOG("aqi_level=",aqi_level);
  220.         //BLINKER_LOG("aqi_pm25=",aqi_pm25);
  221.         //BLINKER_LOG("aqi_pm10=",aqi_pm10);
  222.         //BLINKER_LOG("aqi_SO2=",aqi_SO2);
  223.         //BLINKER_LOG("aqi_NO2=",aqi_NO2);
  224.         //BLINKER_LOG("aqi_CO=",aqi_CO);
  225.         //BLINKER_LOG("aqi_O3=",aqi_O3);
  226.       }
  227.     }
  228. }
  229. void dis_air_weather(){                 //显示空气质量数据
  230.   char str_temp[26]="";  
  231.   do {
  232.       u8g2.clearBuffer();
  233.       u8g2.setFont(u8g2_font_wqy12_t_gb2312a); // 汉字 14*26
  234.       u8g2.setCursor(6, 15);
  235.       strcpy(str_temp,"空气质量:  ");
  236.       strcat(str_temp,aqi_level);
  237.       u8g2.print(str_temp);
  238.       //BLINKER_LOG(str_temp);
  239.       
  240.       u8g2.setCursor(6, 31);
  241.       strcpy(str_temp,"pm2.5: ");
  242.       strcat(str_temp,aqi_pm25);
  243.       //strcat(str_temp, "μg/m³");
  244.       strcat(str_temp,"  pm10: ");
  245.       strcat(str_temp,aqi_pm10);
  246.      // strcat(str_temp, "μg/m³");
  247.       u8g2.print(str_temp);
  248.       //BLINKER_LOG(str_temp);
  249.       
  250.       u8g2.setCursor(5, 47);
  251.       strcpy(str_temp,"SO2  : ");
  252.       strcat(str_temp,aqi_SO2);
  253.       //strcat(str_temp, "μg/m³");
  254.       strcat(str_temp,"  NO2 : ");
  255.       strcat(str_temp,aqi_NO2);
  256.       //strcat(str_temp, "μg/m³");
  257.       u8g2.print(str_temp);
  258.       //BLINKER_LOG(str_temp);
  259.       
  260.       u8g2.setCursor(5, 63);
  261.       strcpy(str_temp,"CO   : ");
  262.       strcat(str_temp,aqi_CO);
  263.       //strcat(str_temp, "mg/m³");
  264.       strcat(str_temp,"  O3  : ");
  265.       strcat(str_temp,aqi_O3);
  266.       //strcat(str_temp, "μg/m³");
  267.       u8g2.print(str_temp);
  268.       //BLINKER_LOG(str_temp);
  269.   } while ( u8g2.nextPage() );
  270. }
  271. void dis_Time_weather(){              //显示时间及天气信息
  272.   //BLINKER_LOG("dis_Time_weather......");
  273.   char str_date[10]="";
  274.   char str_big_Time[7]="";
  275.   char str_temp[6]="";  
  276.   //BLINKER_LOG("format_str");
  277.   do {
  278.     u8g2.clearBuffer();
  279.     itoa(num_hour,str_temp,10);   //时分
  280.     if(num_hour<10){
  281.       strcat(str_big_Time,"0");
  282.     }
  283.     strcat(str_big_Time,str_temp);     
  284.     itoa(num_minute,str_temp,10);
  285.     strcat(str_big_Time,":");
  286.     if(num_minute<10){
  287.       strcat(str_big_Time,"0");
  288.     }
  289.     strcat(str_big_Time,str_temp);
  290.     u8g2.setFont(u8g2_font_logisoso28_tf ); // 大字 14*26
  291.     u8g2.setCursor(0, 34);
  292.     u8g2.print(str_big_Time);
  293.    
  294.     //BLINKER_LOG("时间:",str_big_Time);

  295.     if(num_year<10){
  296.       strcat(str_date,"0");
  297.     }
  298.     itoa(num_year,str_temp,10);   //日期
  299.     strcat(str_date,str_temp);
  300.     itoa(num_month,str_temp,10);
  301.     strcat(str_date,"-");
  302.     if(num_month<10){
  303.       strcat(str_date,"0");
  304.     }
  305.     strcat(str_date,str_temp);
  306.     itoa(num_mday,str_temp,10);
  307.     strcat(str_date,"-");
  308.     if(num_mday<10){
  309.       strcat(str_date,"0");
  310.     }
  311.     strcat(str_date,str_temp);
  312.     strcat(str_date,"星期");
  313.     switch(Blinker.wday()){
  314.       case 0:
  315.         strcat(str_date,"日");
  316.         break;
  317.       case 1:
  318.         strcat(str_date,"一");
  319.         break;
  320.       case 2:
  321.         strcat(str_date,"二");
  322.         break;
  323.       case 3:
  324.         strcat(str_date,"三");
  325.         break;
  326.       case 4:
  327.         strcat(str_date,"四");
  328.         break;
  329.       case 5:
  330.         strcat(str_date,"五");
  331.         break;
  332.       case 6:
  333.         strcat(str_date,"六");
  334.         break;
  335.     }
  336.     u8g2.setFont(u8g2_font_wqy12_t_gb2312a); // 汉字 14*26
  337.     u8g2.setCursor(0, 54);
  338.     u8g2.print(str_date);
  339.     //BLINKER_LOG("日期:",str_date);
  340.     u8g2.setCursor(96, 54);
  341.     u8g2.print(w_temp);
  342.     u8g2.drawLine(88, 2, 88, 61);    //分割线
  343.     //BLINKER_LOG("分割线:");
  344.     u8g2.drawXBM(92,2,36,36,weather_icon[weather_code]); //天气图标
  345.     //BLINKER_LOG("天气图标:",weather_code);
  346.    } while ( u8g2.nextPage() );
  347. }
  348. void dataRead(const String & data){
  349.     //BLINKER_LOG("Blinker readString: ", data);
  350.     uint32_t BlinkerTime = millis();
  351.     Blinker.vibrate();        
  352.     Blinker.print("millis", BlinkerTime);
  353.     digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  354.     Blinker.aqi(w_addr);
  355.     delay(10000);
  356. }
  357. void setup(){
  358.     Serial.begin(57600);
  359.     BLINKER_DEBUG.stream(Serial);
  360.     pinMode(LED_BUILTIN, OUTPUT);
  361.     digitalWrite(LED_BUILTIN, LOW);
  362.     Blinker.begin(auth, ssid, pswd);
  363.     Blinker.attachData(dataRead);
  364.     Blinker.attachWeather(weatherData);   
  365.     Blinker.attachAir(airData);
  366.     Blinker.setTimezone(8.0);
  367.     u8g2.begin();           //选择U8G2模式,或者U8X8模式
  368.     u8g2.enableUTF8Print(); //  UTF8 输出(汉字显示不是很好,勉强够用)
  369.     first_label=true;
  370.     do {
  371.       u8g2.clearBuffer();
  372.       u8g2.setFont(u8g2_font_wqy12_t_gb2312a); // 汉字 14*26
  373.       u8g2.setCursor(36, 38);
  374.       u8g2.print("连接WIFI...");
  375.   } while ( u8g2.nextPage() );
  376. }
  377. void loop(){
  378.     Blinker.run();
  379.     if((first_label==true)){   
  380.       delay(1000);
  381.       Blinker.run();
  382.       delay(1000);
  383.       if (Blinker.init()){       //开机第一次更新天气信息
  384.         delay(1000);
  385.         //BLINKER_LOG("开机第一次更新天气信息,w_addr=",w_addr);
  386.         num_second=Blinker.second();
  387.         num_minute=Blinker.minute();
  388.         num_hour=Blinker.hour();            
  389.         num_year=Blinker.year()%100;  
  390.         num_month=Blinker.month();
  391.         num_mday=Blinker.mday();
  392.         dis_Time_weather(); //先显示时间,再获取天气信息(获取天气时间相对比较长)
  393.         
  394.         Blinker.weather(w_addr);
  395.         //BLINKER_LOG("请求天气数据完毕,first_label=",first_label);
  396.         delay(1000);
  397.         Blinker.aqi(w_addr);
  398.         //BLINKER_LOG("请求空气数据完毕");
  399.         dis_Time_weather();                   //联网成功先显示1秒时间
  400.         delay(1000);
  401.         dis_air_weather();                   //显示1秒空气信息
  402.         delay(1000);
  403.       }
  404.     }
  405.     else{
  406.       num_second=Blinker.second();
  407.       //BLINKER_LOG("正常工作,num_second=",num_second);
  408.       if(num_second==0){
  409.         num_minute=Blinker.minute();
  410.         dis_Time_weather();               //每分钟更新一次时间
  411.         if(num_minute==0){
  412.           num_hour=Blinker.hour();
  413.           Blinker.weather(w_addr);        //每小时(整点)更新一次天气信息
  414.           if(num_hour=0){
  415.             num_year=Blinker.year()%100;  //每天(零点)更新日期数据
  416.             num_month=Blinker.month();
  417.             num_mday=Blinker.mday();
  418.           }
  419.         }
  420.         if(num_minute==30){
  421.           Blinker.aqi(w_addr);//每小时(半点)更新一次天气信息
  422.         }
  423.       }
  424.       if(num_second==50){
  425.         dis_air_weather();                   //显示空气信息
  426.       }
  427.      delay(1000);
  428.     }

  429. }
复制代码


--------2020-07-05更新-----最近工作太忙,赶上周日把之前的问题同意处理一下,问题主要出现在API访问次数限制上,由于调试反复重启,所以每天50次限制马上就使用没了,所以会获取不到天气信息。之前的程序没考虑那么多,原来是获取到天气信息后才显示时间天气画面所以会卡开机动画。新程序开机动画被删除了,增加空气质量数据画面,dis_air_weather(),看大家喜欢用哪个自己选吧。开机动画void dis_refresh()我放在附件里.目前还有点问题,就是刚开机会重启几次才能正常工作,目前还没找到问题,由于白天还得上班,大家谁有解决办法分享一下万分感谢


微信图片_20200523204743.jpg

void dis_refresh.zip

570 Bytes, 下载次数: 101

 楼主| 发表于 2020-6-28 19:39 | 显示全部楼层
tnn0220 发表于 2020-6-26 10:26
我又认真地看了一下编译报错信息,发现很多错误都指向blinker,所以怀疑其版本有差异,我将blinker库从
l ...

有时间我要做个定时显示未来3天预报的
发表于 2020-6-23 00:55 来自手机 | 显示全部楼层
大佬,我想用1.3寸oled    SH1106主控的
发表于 2020-6-23 06:12 | 显示全部楼层
icon_top=temp_loop;   大佬: 这句没通过啊
发表于 2020-6-23 06:21 | 显示全部楼层
icon_top=temp_loop;   大佬: 这句没通过啊
Arduino:1.8.10 (Windows 7), 开发板:"Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from C:\Users\Administrator\sketchbook\libraries\Blinker\src/Blinker.h:46:0,

                 from C:\Users\Administrator\sketchbook\LCD128X64TIANQI\LCD128X64TIANQI.ino:4:

C:\Users\Administrator\sketchbook\libraries\Blinker\src/BlinkerSerialESPMQTT.h:147:27: error: cannot declare field 'BlinkerSerialESPMQTT::Transp' to be of abstract type 'BlinkerSerialMQTT'

         BlinkerSerialMQTT Transp;

                           ^~~~~~

In file included from C:\Users\Administrator\sketchbook\libraries\Blinker\src/BlinkerSerialESPMQTT.h:4:0,

                 from C:\Users\Administrator\sketchbook\libraries\Blinker\src/Blinker.h:46,

                 from C:\Users\Administrator\sketchbook\LCD128X64TIANQI\LCD128X64TIANQI.ino:4:

C:\Users\Administrator\sketchbook\libraries\Blinker\src/Adapters/BlinkerSerialMQTT.h:26:7: note:   because the following virtual functions are pure within 'BlinkerSerialMQTT':

class BlinkerSerialMQTT : public BlinkerStream

       ^~~~~~~~~~~~~~~~~

In file included from C:\Users\Administrator\sketchbook\libraries\Blinker\src/Adapters/BlinkerSerialMQTT.h:13:0,

                 from C:\Users\Administrator\sketchbook\libraries\Blinker\src/BlinkerSerialESPMQTT.h:4,

                 from C:\Users\Administrator\sketchbook\libraries\Blinker\src/Blinker.h:46,

                 from C:\Users\Administrator\sketchbook\LCD128X64TIANQI\LCD128X64TIANQI.ino:4:

c:\users\administrator\sketchbook\libraries\blinker\src\blinker\blinkerstream.h:42:29: note:         virtual int BlinkerStream::duerPrint(const String&, bool)

                 virtual int duerPrint(const String & data, bool report = false) = 0;

                             ^~~~~~~~~

C:\Users\Administrator\sketchbook\LCD128X64TIANQI\LCD128X64TIANQI.ino: In function 'void dis_refresh()':

LCD128X64TIANQI:176:22: error: incompatible types in assignment of 'int' to 'int [20]'

     icon_logo=rand()%8;

                      ^

LCD128X64TIANQI:186:18: error: incompatible types in assignment of 'int' to 'int [20]'

         icon_top=temp_loop;

                  ^~~~~~~~~

"Wire.h" 对应多个库
已使用: C:\Program
"Blinker.h" 对应多个库
已使用: C:\Users\Administrator\sketchbook\libraries\Blinker
"SoftwareSerial.h" 对应多个库
已使用: C:\Program
"Arduino_JSON.h" 对应多个库
已使用: C:\Users\Administrator\sketchbook\libraries\Arduino_JSON
"SPI.h" 对应多个库
已使用: C:\Program
"U8g2lib.h" 对应多个库
已使用: C:\Users\Administrator\sketchbook\libraries\U8g2
exit status 1
incompatible types in assignment of 'int' to 'int [20]'

 楼主| 发表于 2020-6-23 07:07 来自手机 | 显示全部楼层
上官嘉萱 发表于 2020-6-23 00:55
大佬,我想用1.3寸oled    SH1106主控的

驱动参考https://www.arduino.cn/thread-41193-1-1.html
上面我也有说,我也是跟着一点一点学点的,布局方面我没用过,得你自己研究了。别叫我大佬,我也小白一个|(•_•) |,叫别人看到该笑话了
 楼主| 发表于 2020-6-23 07:11 来自手机 | 显示全部楼层
本帖最后由 526598 于 2020-6-23 07:24 编辑
lucq7896 发表于 2020-6-23 06:21
icon_top=temp_loop;   大佬: 这句没通过啊
Arduino:1.8.10 (Windows 7), 开发板:"Arduino/Genuino Mega o ...

刚看了下是我写错了,刚刚发现icon_top [   i  】 发不出去,发出去【i】就没了,你自己加下吧应该是"icon_top【i】 =temp_loop;"已改
第一,你之前不是说用的是esp-12么?那不是8266么?Mega 2560是什么板子?别的没用过我也不懂
第二,关于 对应多个库 的问题我之前的处理就是把软件关了从开就好了,不过有的是开发环境的原因对我来说就比较复杂了,建议百度

发表于 2020-6-23 08:42 | 显示全部楼层
我再研究一下  您也看一下
123.png
 楼主| 发表于 2020-6-23 09:27 | 显示全部楼层
上官嘉萱 发表于 2020-6-23 08:42
我再研究一下  您也看一下

那个位置应该有个【i】不知道为什么【i】不能发出来,我把【i】改成temp_i了,我白天在外面没办法试,你先试试,我晚上回去看
发表于 2020-6-23 09:31 | 显示全部楼层
526598 发表于 2020-6-23 09:27
那个位置应该有个【i】不知道为什么【i】不能发出来,我把【i】改成temp_i了,我白天在外面没办法试,你 ...

您把您的程序那里截图发出来        或者上传压缩包   应该问题就解决了          i应该是触发了网页的某个函数
发表于 2020-6-23 09:40 | 显示全部楼层
这次编译还是通不过.原因何在?
Arduino:1.8.5 (Windows 7), 开发板:"Adafruit Feather HUZZAH ESP8266, 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

C:\Users\dell\Documents\Arduino\blinker-weather\blinker-weather.ino: In function 'void weatherData(const String&)':

blinker-weather:239: error: 'StaticJsonDocument' was not declared in this scope

     StaticJsonDocument<400> doc;

     ^

blinker-weather:239: error: 'doc' was not declared in this scope

     StaticJsonDocument<400> doc;

                             ^

blinker-weather:241: error: 'DeserializationError' was not declared in this scope

     DeserializationError error = deserializeJson(doc, data);

     ^

blinker-weather:241: error: expected ';' before 'error'

     DeserializationError error = deserializeJson(doc, data);

                          ^

blinker-weather:243: error: 'error' was not declared in this scope

     if(error){    //澶╂皵鑾峰彇澶辫触

        ^

C:\Users\dell\Documents\Arduino\blinker-weather\blinker-weather.ino: In function 'void dis_refresh()':

blinker-weather:343: error: incompatible types in assignment of 'int' to 'int [20]'

     icon_logo=rand()%8;

              ^

blinker-weather:363: error: incompatible types in assignment of 'int' to 'int [20]'

         icon_top=temp_loop;

                 ^

C:\Users\dell\Documents\Arduino\blinker-weather\blinker-weather.ino: In function 'void setup()':

blinker-weather:577: error: 'class BlinkerESPMQTT' has no member named 'attachWeather'

     Blinker.attachWeather(weatherData);

             ^

In file included from C:\Users\dell\Documents\Arduino\libraries\Blinker\src/Blinker/BlinkerProtocol.h:4:0,

                 from C:\Users\dell\Documents\Arduino\libraries\Blinker\src/BlinkerESPMQTT.h:12,

                 from C:\Users\dell\Documents\Arduino\libraries\Blinker\src/Blinker.h:149,

                 from C:\Users\dell\Documents\Arduino\blinker-weather\blinker-weather.ino:3:

C:\Users\dell\Documents\Arduino\libraries\Blinker\src/Blinker/BlinkerApi.h: In instantiation of 'BlinkerProtocol<Transp>::BlinkerProtocol(Transp&) [with Transp = BlinkerMQTT]':

C:\Users\dell\Documents\Arduino\libraries\Blinker\src/BlinkerESPMQTT.h:31:26:   required from here

C:\Users\dell\Documents\Arduino\libraries\Blinker\src/Blinker/BlinkerApi.h:69:7: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

class BlinkerApi

       ^

In file included from C:\Users\dell\Documents\Arduino\libraries\Blinker\src/BlinkerESPMQTT.h:12:0,

                 from C:\Users\dell\Documents\Arduino\libraries\Blinker\src/Blinker.h:149,

                 from C:\Users\dell\Documents\Arduino\blinker-weather\blinker-weather.ino:3:

C:\Users\dell\Documents\Arduino\libraries\Blinker\src/Blinker/BlinkerProtocol.h:57:29: note: synthesized method 'BlinkerApi<BlinkerProtocol<BlinkerMQTT> >::BlinkerApi()' first required here

             , canParse(false)

                             ^

exit status 1
'StaticJsonDocument' was not declared in this scope

在文件 -> 首选项开启
“编译过程中显示详细输出”选项
这份报告会包含更多信息。
https://www.suiyikan.tv/video/play/220428-1-42.html


https://www.cmdy5.com/play/24283.html?24283-1-33
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 11:56 , Processed in 0.085057 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表