Blinker 天气时钟8266 12864LCD屏(针对新版库v0.3.4接口更新)
本帖最后由 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点灯平台获取天气部分代码来自:https://www.arduino.cn/thread-94009-1-1.htmlLcd12864 驱动为u8g2参考资料及部分代码来自:https://www.arduino.cn/thread-41193-1-1.html更详细资料:https://geek-workshop.com/forum.php?mod=viewthread&tid=10634&page=1#pid71162OLED/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.hU8g2lib库在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/https://www.bilibili.com/video/BV12k4y1679Q/
连接图8266 ESP -01
连接图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-12f针脚定义参考
#define BLINKER_WIFI
#include <Blinker.h>
#include <SPI.h>
#include <U8g2lib.h>
char auth[] = "Your Device Secret Key";
char ssid[] = "Your WiFi network SSID or name";
char pswd[] = "Your WiFi network WPA password or WEP key";
char w_addr[]="beijingshi"; /*城市关键字.注意不要有空格
城市关键字,参考 https://diandeng.tech/doc/weather-and-air
*/
int num_second=0;
int num_minute=0;
int num_hour=0;
int num_month=0;
int num_mday=0;
int num_year=0;
char aqi_level="";
char aqi_pm25="";
char aqi_pm10="";
char aqi_SO2="";
char aqi_NO2="";
char aqi_CO="";
char aqi_O3="";
char aqi_4="";
int weather_code=0;
char w_weather="";
char w_temp="18 °C";
char* ch;//用于查找数据是否包含天气关键字时接受返回值
bool first_label=false; //开机标签,开机第一时间更新天气信息
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
//天气图标列表[阴,雪,雨,多云,晴,雾霾,夜晚晴,夜晚多云] 取模教程 https://www.arduino.cn/thread-42174-1-1.html
static unsigned char weather_icon={/*阴*/
{ 0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,
0xE0,0x3F,0x00,0xF0,0x00,0xF0,0xFF,0x00,0xF0,0x00,0x38,0xC0,0x01,0xF0,0x00,0x0C,0x00,0x03,
0xF0,0x00,0x06,0x00,0x06,0xF0,0x00,0x07,0x00,0x0E,0xF0,0xE0,0x03,0x00,0x0C,0xF0,0xF0,0x03,
0x00,0x0C,0xF0,0x38,0x00,0x00,0x18,0xF0,0x0C,0x00,0x00,0xF8,0xF0,0x0E,0x00,0x00,0xF8,0xF1,
0x06,0x00,0x00,0x80,0xF3,0x06,0x00,0x00,0x00,0xF7,0x06,0x00,0x00,0x00,0xF6,0x06,0x00,0x00,
0x00,0xF6,0x06,0x00,0x00,0x00,0xF6,0x06,0x00,0x00,0x00,0xF6,0x0E,0x00,0x00,0x00,0xF6,0x0C,
0x00,0x00,0x00,0xF7,0x38,0x00,0x00,0x80,0xF3,0xF0,0xFF,0xFF,0xFF,0xF1,0xE0,0xFF,0xFF,0xFF,
0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,
0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
/*雪*/
{ 0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
0x00,0xF0,0x00,0x80,0x19,0x00,0xF0,0x00,0x80,0x1F,0x00,0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,
0x00,0x06,0x00,0xF0,0x00,0x00,0x06,0x00,0xF0,0x80,0x01,0x06,0x18,0xF0,0x80,0x01,0x06,0x18,
0xF0,0x80,0x01,0x06,0x18,0xF0,0xE0,0x83,0x1F,0x7E,0xF0,0xE0,0xFF,0xF9,0x7F,0xF0,0x00,0xFC,
0xF0,0x03,0xF0,0x00,0x70,0xE0,0x00,0xF0,0x00,0x30,0xC0,0x00,0xF0,0x00,0x30,0xC0,0x00,0xF0,
0x00,0x30,0xC0,0x00,0xF0,0x00,0x30,0xC0,0x00,0xF0,0x00,0x70,0xE0,0x00,0xF0,0x00,0xFC,0xF0,
0x03,0xF0,0xE0,0xFF,0xF9,0x7F,0xF0,0xE0,0x87,0x1F,0x7C,0xF0,0x80,0x01,0x06,0x18,0xF0,0x80,
0x01,0x06,0x18,0xF0,0x80,0x01,0x06,0x18,0xF0,0x00,0x00,0x06,0x00,0xF0,0x00,0x00,0x06,0x00,
0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,0x80,0x1F,0x00,0xF0,0x00,0x80,0x19,0x00,0xF0,0x00,0x00,
0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
/*雨*/
{ 0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
0x00,0xF0,0x00,0xC0,0x3F,0x00,0xF0,0x00,0xF0,0xFF,0x00,0xF0,0x00,0x38,0xC0,0x01,0xF0,0x00,
0x1C,0x80,0x03,0xF0,0x00,0x0C,0x00,0x03,0xF0,0x00,0x06,0x00,0x06,0xF0,0xE0,0x07,0x00,0x06,
0xF0,0xF0,0x03,0x00,0x04,0xF0,0x38,0x00,0x00,0x1C,0xF0,0x18,0x00,0x00,0xFC,0xF0,0x0C,0x00,
0x00,0xF8,0xF1,0x0C,0x00,0x00,0x80,0xF1,0x0C,0x00,0x00,0x00,0xF3,0x0C,0x00,0x00,0x00,0xF3,
0x0C,0x00,0x00,0x00,0xF3,0x18,0x30,0x0C,0x03,0xF3,0x38,0x30,0x0C,0x83,0xF1,0x70,0x30,0x0C,
0xC3,0xF1,0x60,0x18,0x86,0xC1,0xF0,0x00,0x18,0x86,0x01,0xF0,0x00,0x18,0x86,0x01,0xF0,0x00,
0x1C,0xC7,0x01,0xF0,0x00,0x0C,0xC3,0x00,0xF0,0x00,0x0C,0xC3,0x00,0xF0,0x00,0x00,0x03,0x00,
0xF0,0x00,0x80,0x01,0x00,0xF0,0x00,0x80,0x01,0x00,0xF0,0x00,0x80,0x01,0x00,0xF0,0x00,0x00,
0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
/*多云*/
{ 0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
0x00,0xF0,0x00,0x00,0x38,0x00,0xF0,0x80,0x03,0x30,0x00,0xF0,0x80,0x01,0x20,0x00,0xF0,0x80,
0x00,0x00,0x00,0xF0,0x00,0xE0,0x07,0x00,0xF0,0x00,0xF8,0x0F,0x00,0xF0,0x00,0x1C,0x1C,0x00,
0xF0,0x00,0x0E,0x30,0x00,0xF0,0x00,0x06,0x70,0x00,0xF0,0x00,0x07,0x60,0x08,0xF0,0x00,0x03,
0xC0,0x18,0xF0,0x08,0x03,0xC0,0x08,0xF0,0x0C,0xC3,0x7F,0x00,0xF0,0x08,0xE3,0xFF,0x00,0xF0,
0x00,0x7E,0xE0,0x00,0xF0,0x00,0x1E,0x80,0x01,0xF0,0x00,0x1C,0x80,0x03,0xF0,0x00,0x0E,0x00,
0x03,0xF0,0xC0,0x0F,0x00,0x03,0xF0,0xE0,0x07,0x00,0x03,0xF0,0x70,0x00,0x00,0x1F,0xF0,0x38,
0x00,0x00,0x7F,0xF0,0x38,0x00,0x00,0xFE,0xF0,0x38,0x00,0x00,0xE0,0xF1,0x38,0x00,0x00,0xC0,
0xF1,0x70,0x00,0x00,0xC0,0xF1,0xE0,0xFF,0xFF,0xFF,0xF0,0xC0,0xFF,0xFF,0x7F,0xF0,0x00,0xFE,
0xFF,0x1F,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
/*晴*/
{ 0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x06,0x00,0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
0xF0,0xC0,0x81,0x1F,0x38,0xF0,0xC0,0xC0,0x3F,0x30,0xF0,0x40,0xE0,0x70,0x20,0xF0,0x00,0x30,
0xC0,0x00,0xF0,0x00,0x38,0xC0,0x01,0xF0,0x00,0x18,0x80,0x01,0xF0,0x00,0x18,0x80,0x01,0xF0,
0x00,0x18,0x80,0x01,0xF0,0x00,0x18,0x80,0x01,0xF0,0x00,0x38,0xC0,0x01,0xF0,0x00,0x30,0xC0,
0x00,0xF0,0x40,0xE0,0x70,0x20,0xF0,0xC0,0xC0,0x3F,0x30,0xF0,0xC0,0x81,0x1F,0x38,0xF0,0x00,
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,0x00,0x06,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,
0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
/*雾霾*/
{ 0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x80,0x1F,0x00,0xF0,0x00,0xE0,0x7F,0x00,0xF0,0x00,
0x70,0xE0,0x00,0xF0,0x00,0x18,0x80,0x01,0xF0,0x00,0x0C,0x00,0x03,0xF0,0x00,0x04,0x00,0x02,
0xF0,0xC0,0x07,0x00,0x06,0xF0,0xE0,0x03,0x00,0x04,0xF0,0x70,0x00,0x00,0x04,0xF0,0x18,0x00,
0x00,0x7C,0xF0,0x1C,0x00,0x00,0xFC,0xF0,0x0C,0x00,0x00,0xC0,0xF1,0x0C,0x00,0x00,0x80,0xF3,
0x0C,0x00,0x00,0x00,0xF3,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0xF0,0xFF,0x8F,0xFF,0xF0,0xF0,0xFF,0x8F,0xFF,0xF0,0x00,
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
0xF0,0xF0,0xF8,0xFF,0xFF,0xF0,0xF0,0xF8,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,
0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
/*夜晚晴*/
{ 0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,
0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x18,0x00,0xF0,0x00,0x06,0x3C,0x00,0xF0,0x00,
0x0F,0xFF,0x00,0xF0,0x80,0x0F,0x7E,0x00,0xF0,0xC0,0x0D,0x3C,0x00,0xF0,0xC0,0x0C,0x7E,0x00,
0xF0,0x60,0x0C,0x66,0x00,0xF0,0x60,0x0C,0x00,0x00,0xF0,0x30,0x0C,0x00,0x00,0xF0,0x30,0x1C,
0x00,0x00,0xF0,0x30,0x18,0x00,0x00,0xF0,0x30,0x18,0x00,0x08,0xF0,0x30,0x30,0x00,0x3E,0xF0,
0x30,0x70,0x00,0x1C,0xF0,0x30,0xE0,0x00,0x14,0xF0,0x30,0xC0,0x01,0x00,0xF0,0x30,0x80,0x03,
0x00,0xF0,0x30,0x00,0x07,0x00,0xF0,0x60,0x00,0x3E,0x00,0xF0,0x60,0x00,0xF8,0x1F,0xF0,0xC0,
0x00,0xE0,0x3F,0xF0,0xC0,0x01,0x00,0x38,0xF0,0x80,0x03,0x00,0x1C,0xF0,0x00,0x07,0x00,0x0E,
0xF0,0x00,0x1E,0x80,0x07,0xF0,0x00,0xF8,0xFF,0x01,0xF0,0x00,0xE0,0x7F,0x00,0xF0,0x00,0x00,
0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0},
/*夜晚多云*/
{ 0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x0C,0x00,0xF0,0x00,0x00,0x0E,
0x00,0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,0x00,0x0F,0x00,0xF0,0x00,0x80,0x0F,0x00,0xF0,0x00,
0x80,0x1D,0x00,0xF0,0x00,0xC0,0x19,0x00,0xF0,0x00,0xC0,0x18,0x00,0xF0,0x00,0xC0,0x30,0x00,
0xF0,0x00,0xC0,0x70,0x00,0xF0,0x00,0xC0,0xE0,0x00,0xF0,0x00,0x80,0xC1,0x01,0xF0,0x00,0x80,
0x81,0x03,0xF0,0x00,0x80,0x07,0x1F,0xF0,0x00,0xC0,0x3F,0xFC,0xF3,0x00,0xE0,0x7F,0xF0,0xF3,
0x00,0x70,0xE0,0xE0,0xF1,0x00,0x38,0xC0,0xF9,0xF0,0x00,0x18,0x80,0x3F,0xF0,0x00,0x1E,0x80,
0x0F,0xF0,0xC0,0x0F,0x00,0x03,0xF0,0xE0,0x0F,0x00,0x03,0xF0,0x70,0x00,0x00,0x07,0xF0,0x30,
0x00,0x00,0x7F,0xF0,0x30,0x00,0x00,0xFE,0xF0,0x30,0x00,0x00,0xC0,0xF0,0x30,0x00,0x00,0xC0,
0xF0,0x70,0x00,0x00,0xC0,0xF0,0xE0,0xFF,0xFF,0xFF,0xF0,0xC0,0xFF,0xFF,0x7F,0xF0,0x00,0xFE,
0xFF,0x1F,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0xF0}
};
//天气图标列表[阴,雪,雨,多云,晴,雾霾,夜晚晴,夜晚多云]
void weatherData(const String & data){//更新天气数据
DynamicJsonDocument jsonBuffer(256);
//BLINKER_LOG("weather: ", data);
if(data=='{'){
//BLINKER_LOG("成功获取天气信息!");
first_label=false;
DeserializationError error = deserializeJson(jsonBuffer, data);
JsonObject doc = jsonBuffer.as<JsonObject>();
//Serial.print("sizeof(doc):");
//Serial.println(sizeof(doc));
if(error!= NULL){ //天气获取失败
//BLINKER_LOG("weatherData_error!");
delay(60000);
return;
}
else{
//BLINKER_LOG("分解天气信息");
//doc["city"] //城市或地区
//doc["province"] //
strcpy(w_weather,doc["weather"]); //天气现象 "阴"
strcpy(w_temp,doc["temp"]); //温度 "24"
strcat(w_temp," °C");
//doc["humi"] //湿度 "86"
//doc["wind"] //风向 "北"
//doc["power"] //风力 "≤3"
//doc["updateTime"]: //更新时间 "2020-06-21 18:26:00"
//天气图标列表[阴,雪,雨,多云,晴,雾霾,夜晚晴,夜晚多云]
//BLINKER_LOG("分解天气信息2");
if((ch=strstr(w_weather,"雪"))!=NULL){
weather_code=1;
}
else if((ch=strstr(w_weather,"雨"))!=NULL){
weather_code=2;
}
else if((ch=strstr(w_weather,"阴"))!=NULL){
weather_code=0;
}
else if((ch=strstr(w_weather,"云"))!=NULL){
if (Blinker.hour()<18){
weather_code=3;
}
else{
weather_code=7;
}
}
else if((ch=strstr(w_weather,"晴"))!=NULL){
if (Blinker.hour()<18){
weather_code=4;
}
else{
weather_code=6;
}
}
else if(((ch=strstr(w_weather,"雾"))!=NULL)or((ch=strstr(w_weather,"霾"))!=NULL)){
weather_code=5;
}
}
}
else{
//BLINKER_LOG("天气信息获取失败!请检查地址变量w_addr[]=",w_addr,",或获取天气数据次数用尽!");
//BLINKER_LOG("1分钟后重试");
delay(60000);
}
}
void airData(const String & data){ //更新空气数据
//BLINKER_LOG("AQI: ", data);
if(data=='{'){
DynamicJsonDocument jsonBuffer(512);
DeserializationError error = deserializeJson(jsonBuffer, data);
JsonObject doc = jsonBuffer.as<JsonObject>();
if(error != NULL){ //天气获取失败
//BLINKER_LOG("airData_error!");
//Serial.println(error.c_str());
delay(1000);
//return;
}
else{
strcpy(aqi_level,doc["level"]);
//Serial.println(strlen(doc["pm25"]));
if(strlen(doc["pm25"])<2){
strcpy(aqi_pm25," ");
}
strcat(aqi_pm25,doc["pm25"]);
strcpy(aqi_pm10,doc["pm10"]);
//Serial.println(strlen(doc["SO2"]));
if(strlen(doc["SO2"])<2){
strcpy(aqi_SO2," ");
}
strcat(aqi_SO2,doc["SO2"]);
strcpy(aqi_NO2,doc["NO2"]);
//Serial.println(strlen(doc["CO"]));
if(strlen(doc["CO"])<2){
strcpy(aqi_CO," ");
}
strcat(aqi_CO,doc["CO"]);
strcpy(aqi_O3,doc["O3"]);
//BLINKER_LOG("成功获取空气数据!");
//BLINKER_LOG("aqi_level=",aqi_level);
//BLINKER_LOG("aqi_pm25=",aqi_pm25);
//BLINKER_LOG("aqi_pm10=",aqi_pm10);
//BLINKER_LOG("aqi_SO2=",aqi_SO2);
//BLINKER_LOG("aqi_NO2=",aqi_NO2);
//BLINKER_LOG("aqi_CO=",aqi_CO);
//BLINKER_LOG("aqi_O3=",aqi_O3);
}
}
}
void dis_air_weather(){ //显示空气质量数据
char str_temp="";
do {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_wqy12_t_gb2312a); // 汉字 14*26
u8g2.setCursor(6, 15);
strcpy(str_temp,"空气质量:");
strcat(str_temp,aqi_level);
u8g2.print(str_temp);
//BLINKER_LOG(str_temp);
u8g2.setCursor(6, 31);
strcpy(str_temp,"pm2.5: ");
strcat(str_temp,aqi_pm25);
//strcat(str_temp, "μg/m³");
strcat(str_temp,"pm10: ");
strcat(str_temp,aqi_pm10);
// strcat(str_temp, "μg/m³");
u8g2.print(str_temp);
//BLINKER_LOG(str_temp);
u8g2.setCursor(5, 47);
strcpy(str_temp,"SO2: ");
strcat(str_temp,aqi_SO2);
//strcat(str_temp, "μg/m³");
strcat(str_temp,"NO2 : ");
strcat(str_temp,aqi_NO2);
//strcat(str_temp, "μg/m³");
u8g2.print(str_temp);
//BLINKER_LOG(str_temp);
u8g2.setCursor(5, 63);
strcpy(str_temp,"CO : ");
strcat(str_temp,aqi_CO);
//strcat(str_temp, "mg/m³");
strcat(str_temp,"O3: ");
strcat(str_temp,aqi_O3);
//strcat(str_temp, "μg/m³");
u8g2.print(str_temp);
//BLINKER_LOG(str_temp);
} while ( u8g2.nextPage() );
}
void dis_Time_weather(){ //显示时间及天气信息
//BLINKER_LOG("dis_Time_weather......");
char str_date="";
char str_big_Time="";
char str_temp="";
//BLINKER_LOG("format_str");
do {
u8g2.clearBuffer();
itoa(num_hour,str_temp,10); //时分
if(num_hour<10){
strcat(str_big_Time,"0");
}
strcat(str_big_Time,str_temp);
itoa(num_minute,str_temp,10);
strcat(str_big_Time,":");
if(num_minute<10){
strcat(str_big_Time,"0");
}
strcat(str_big_Time,str_temp);
u8g2.setFont(u8g2_font_logisoso28_tf ); // 大字 14*26
u8g2.setCursor(0, 34);
u8g2.print(str_big_Time);
//BLINKER_LOG("时间:",str_big_Time);
if(num_year<10){
strcat(str_date,"0");
}
itoa(num_year,str_temp,10); //日期
strcat(str_date,str_temp);
itoa(num_month,str_temp,10);
strcat(str_date,"-");
if(num_month<10){
strcat(str_date,"0");
}
strcat(str_date,str_temp);
itoa(num_mday,str_temp,10);
strcat(str_date,"-");
if(num_mday<10){
strcat(str_date,"0");
}
strcat(str_date,str_temp);
strcat(str_date,"星期");
switch(Blinker.wday()){
case 0:
strcat(str_date,"日");
break;
case 1:
strcat(str_date,"一");
break;
case 2:
strcat(str_date,"二");
break;
case 3:
strcat(str_date,"三");
break;
case 4:
strcat(str_date,"四");
break;
case 5:
strcat(str_date,"五");
break;
case 6:
strcat(str_date,"六");
break;
}
u8g2.setFont(u8g2_font_wqy12_t_gb2312a); // 汉字 14*26
u8g2.setCursor(0, 54);
u8g2.print(str_date);
//BLINKER_LOG("日期:",str_date);
u8g2.setCursor(96, 54);
u8g2.print(w_temp);
u8g2.drawLine(88, 2, 88, 61); //分割线
//BLINKER_LOG("分割线:");
u8g2.drawXBM(92,2,36,36,weather_icon); //天气图标
//BLINKER_LOG("天气图标:",weather_code);
} while ( u8g2.nextPage() );
}
void dataRead(const String & data){
//BLINKER_LOG("Blinker readString: ", data);
uint32_t BlinkerTime = millis();
Blinker.vibrate();
Blinker.print("millis", BlinkerTime);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
Blinker.aqi(w_addr);
delay(10000);
}
void setup(){
Serial.begin(57600);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Blinker.attachWeather(weatherData);
Blinker.attachAir(airData);
Blinker.setTimezone(8.0);
u8g2.begin(); //选择U8G2模式,或者U8X8模式
u8g2.enableUTF8Print(); //UTF8 输出(汉字显示不是很好,勉强够用)
first_label=true;
do {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_wqy12_t_gb2312a); // 汉字 14*26
u8g2.setCursor(36, 38);
u8g2.print("连接WIFI...");
} while ( u8g2.nextPage() );
}
void loop(){
Blinker.run();
if((first_label==true)){
delay(1000);
Blinker.run();
delay(1000);
if (Blinker.init()){ //开机第一次更新天气信息
delay(1000);
//BLINKER_LOG("开机第一次更新天气信息,w_addr=",w_addr);
num_second=Blinker.second();
num_minute=Blinker.minute();
num_hour=Blinker.hour();
num_year=Blinker.year()%100;
num_month=Blinker.month();
num_mday=Blinker.mday();
dis_Time_weather(); //先显示时间,再获取天气信息(获取天气时间相对比较长)
Blinker.weather(w_addr);
//BLINKER_LOG("请求天气数据完毕,first_label=",first_label);
delay(1000);
Blinker.aqi(w_addr);
//BLINKER_LOG("请求空气数据完毕");
dis_Time_weather(); //联网成功先显示1秒时间
delay(1000);
dis_air_weather(); //显示1秒空气信息
delay(1000);
}
}
else{
num_second=Blinker.second();
//BLINKER_LOG("正常工作,num_second=",num_second);
if(num_second==0){
num_minute=Blinker.minute();
dis_Time_weather(); //每分钟更新一次时间
if(num_minute==0){
num_hour=Blinker.hour();
Blinker.weather(w_addr); //每小时(整点)更新一次天气信息
if(num_hour=0){
num_year=Blinker.year()%100;//每天(零点)更新日期数据
num_month=Blinker.month();
num_mday=Blinker.mday();
}
}
if(num_minute==30){
Blinker.aqi(w_addr);//每小时(半点)更新一次天气信息
}
}
if(num_second==50){
dis_air_weather(); //显示空气信息
}
delay(1000);
}
}
--------2020-07-05更新-----最近工作太忙,赶上周日把之前的问题同意处理一下,问题主要出现在API访问次数限制上,由于调试反复重启,所以每天50次限制马上就使用没了,所以会获取不到天气信息。之前的程序没考虑那么多,原来是获取到天气信息后才显示时间天气画面所以会卡开机动画。新程序开机动画被删除了,增加空气质量数据画面,dis_air_weather(),看大家喜欢用哪个自己选吧。开机动画void dis_refresh()我放在附件里.目前还有点问题,就是刚开机会重启几次才能正常工作,目前还没找到问题,由于白天还得上班,大家谁有解决办法分享一下万分感谢
tnn0220 发表于 2020-6-26 10:26
我又认真地看了一下编译报错信息,发现很多错误都指向blinker,所以怀疑其版本有差异,我将blinker库从
l ...
有时间我要做个定时显示未来3天预报的:) 大佬,我想用1.3寸oled SH1106主控的 icon_top=temp_loop; 大佬: 这句没通过啊:'( 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 '
icon_logo=rand()%8;
^
LCD128X64TIANQI:186:18: error: incompatible types in assignment of 'int' to 'int '
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 '
上官嘉萱 发表于 2020-6-23 00:55
大佬,我想用1.3寸oled SH1106主控的
驱动参考https://www.arduino.cn/thread-41193-1-1.html
上面我也有说,我也是跟着一点一点学点的,布局方面我没用过,得你自己研究了。别叫我大佬,我也小白一个|(•_•) |,叫别人看到该笑话了 本帖最后由 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
我再研究一下您也看一下
那个位置应该有个【i】不知道为什么【i】不能发出来,我把【i】改成temp_i了,我白天在外面没办法试,你先试试,我晚上回去看 526598 发表于 2020-6-23 09:27
那个位置应该有个【i】不知道为什么【i】不能发出来,我把【i】改成temp_i了,我白天在外面没办法试,你 ...
您把您的程序那里截图发出来 或者上传压缩包 应该问题就解决了 i应该是触发了网页的某个函数 这次编译还是通不过.原因何在?
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 '
icon_logo=rand()%8;
^
blinker-weather:363: error: incompatible types in assignment of 'int' to 'int '
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&) ':
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