本帖最后由 上官嘉萱 于 2020-6-24 23:51 编辑
添加小爱和APP按键控制背光 而且 在添加之前 我 的 又 开 始 无 限 重 启 了 我要崩溃了 我觉得 我的是重启带的请求次数超限制了
项目使用了 849512 字节,占用了 (88%) 程序存储空间。最大为 958448 字节。
全局变量使用了40488字节,(49%)的动态内存,余留41432字节局部变量。最大为81920字节。
温湿度传感器我研究不明白 别指望我了 尤其还要往屏幕添加
[mw_shl_code=arduino,true]#define BLINKER_MIOT_LIGHT
#define BLINKER_WIFI
#include <Blinker.h>
#include <Arduino.h>
#include <Arduino_JSON.h>
#include <SPI.h>
#include <U8g2lib.h>
char auth[] = "***";
char ssid[] = "***";
char pswd[] = "***";
BlinkerButton Button1("Q");
bool oState = false;
int counter = 3;
void button1_callback(const String & state)
{
BLINKER_LOG("app操作了!: ", state);
if (digitalRead(3) == HIGH) {
BLINKER_LOG("灭灯!");
digitalWrite(3, LOW);
Button1.color("#999999");
Button1.text("灭");
Button1.print("off");
}
else if (digitalRead(3) == LOW) {
BLINKER_LOG("亮灯!");
digitalWrite(3, HIGH);
Button1.color("#0066FF");
Button1.text("亮");
Button1.print("on");
}
}
void miotPowerState(const String & state)
{
BLINKER_LOG("小爱语音操作!");
if (state == BLINKER_CMD_ON) {
digitalWrite(3, HIGH);
BlinkerMIOT.powerState("on");
BLINKER_LOG("亮灯!");
BlinkerMIOT.print();
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(3, LOW);
BlinkerMIOT.powerState("off");
BLINKER_LOG("灭灯!");
BlinkerMIOT.print();
}
}
void heartbeat()
{
BLINKER_LOG("状态同步!");
if (digitalRead(3) == HIGH)
{ Button1.print("on");
Button1.color("#0066FF");
Button1.text("亮");
}
else
{
Button1.print("off");
Button1.color("#999999");
Button1.text("灭");
}
}
char w_addr[] = "shanxi-jixian";
char str_week[8] = "";
char str_date[10] = "";
char str_big_Time[7] = "";
int num_temp = 0;
char str_temp[6] = "";
int weather_code = 0;
char w_weather[10] = "";
char w_temp[5] = "";
char week_str[8][4] = {{"日"}, {"一"}, {"二"}, {"三"}, {"四"}, {"五"}, {"六"}, {"日"}};
char* ch;
bool first_label = false;
//U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI u8g2(U8G2_R2, /* clock=*/D4, /* data=*/ D3, /* cs=*/ D0, /* dc=*/ D1, /* reset=*/ D2);
U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 0, /* data=*/ 2, /* CS=*/ 1, /* reset=*/ 16);
static unsigned char weather_icon[8][180] = {
{ 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) {
BLINKER_LOG("weather: ", data);
StaticJsonDocument<400> doc;
DeserializationError error = deserializeJson(doc, data);
if (error) {
return;
}
else if (sizeof(data) > 10) {
first_label = false;
strcpy(w_weather, doc["weather"]);
strcpy(w_temp, doc["temp"]);
strcat(w_temp, "℃");
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;
}
}
}
void dis_refresh() {
int icon_top[20] = {0, 0, 0, 0, 0, 0, 0, 0};
int icon_left[20] = {0, 0, 0, 0, 0, 0, 0, 0};
int icon_logo[20] = {0, 0, 0, 0, 0, 0, 0, 0};
for (int temp_i = 0; temp_i < 20; temp_i++) {
icon_logo[temp_i] = rand() % 8;
}
for (int temp_i = 0; temp_i < 20; temp_i++) {
int temp_loop = rand() % 40;
for (int j = 0; j < 10; j++) {
if (temp_loop == icon_top[j]) {
temp_i--;
break;
}
if (j = 10) {
icon_top[temp_i] = temp_loop;
}
}
}
do {
u8g2.clearBuffer();
} while (u8g2.nextPage());
int icon_max = 0;
for (int i = 0; i < 8; i++) {
for (int k = 0; k < 7; k++) {
do {
u8g2.clearBuffer();
for (int j = 0; j <= icon_max; j++) {
if (icon_left[j] < 128) {
icon_left[j] += 6;
u8g2.drawXBM(icon_left[j], icon_top[j], 36, 36, weather_icon[icon_logo[j]]);
}
}
} while (u8g2.nextPage());
delay(5);
}
icon_max++;
}
}
void dis_Time_weather() {
strcpy(str_week, "");
strcpy(str_date, "");
strcpy(str_big_Time, "");
num_temp = 0;
strcpy(str_temp, "");
if (Blinker.second() >= 0) {
do {
u8g2.clearBuffer();
num_temp = Blinker.hour();
itoa(num_temp, str_temp, 10);
if (Blinker.hour() < 10) {
strcat(str_big_Time, "0");
}
strcat(str_big_Time, str_temp);
num_temp = Blinker.minute();
itoa(num_temp, str_temp, 10);
strcat(str_big_Time, ":");
if (Blinker.minute() < 10) {
strcat(str_big_Time, "0");
}
strcat(str_big_Time, str_temp);
//Serial.print("时分:");
//Serial.print(str_big_Time);
u8g2.setFont(u8g2_font_logisoso28_tf );
num_temp = Blinker.year() % 100;
if (num_temp < 10) {
strcat(str_date, "0");
}
itoa(num_temp, str_temp, 10);
strcat(str_date, str_temp);
num_temp = Blinker.month();
itoa(num_temp, str_temp, 10);
strcat(str_date, "-");
if (Blinker.month() < 10) {
strcat(str_date, "0");
}
strcat(str_date, str_temp);
num_temp = Blinker.mday();
itoa(num_temp, str_temp, 10);
strcat(str_date, "-");
strcat(str_date, str_temp);
num_temp = Blinker.wday();
strcat(str_date, "星期");
strcat(str_date, week_str[Blinker.wday()]);
u8g2.setCursor(0, 34);
u8g2.print(str_big_Time);
u8g2.drawLine(88, 2, 88, 61);
u8g2.setFont(u8g2_font_wqy12_t_gb2312a);
u8g2.setCursor(0, 54);
u8g2.print(str_date);
u8g2.drawXBM(92, 2, 36, 36, weather_icon[weather_code]);
u8g2.setFont(u8g2_font_wqy16_t_gb2312b );
u8g2.setCursor(96, 55);
u8g2.print(w_temp);
} 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));
}
void setup() {
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Button1.attach(button1_callback);
BlinkerMIOT.attachPowerState(miotPowerState);
Blinker.attachHeartbeat(heartbeat);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Blinker.attachWeather(weatherData);
Blinker.setTimezone(8.0);
u8g2.begin();
u8g2.enableUTF8Print();
first_label = true;
dis_refresh();
}
void loop() {
Blinker.run();
if ((first_label == true) and (Blinker.second() >= 0)) {
delay(10000);
Serial.print("开机第一次更新天气信息");
//Serial.println();
Blinker.weather(w_addr);
}
if (Blinker.minute() % 10 == 0) { /
if ((Blinker.second() > 10) and (Blinker.second() <= 20)) {
dis_refresh();
if (Blinker.minute() == 0) {
Blinker.weather(w_addr);
}
}
}
dis_Time_weather();
delay(5000);
}[/mw_shl_code]
附上我单独的温湿度传感器代码
[mw_shl_code=arduino,true]#define BLINKER_WIFI
#define BLINKER_MIOT_SENSOR //小爱同学定义为传感器设备
#include <Blinker.h>
#include <DHT.h>
char auth[] = "***"; //设备key
char ssid[] = "***"; //wifi ssid
char pswd[] = "***"; //wifi 密码
BlinkerNumber HUMI("humi"); //定义湿度数据键名
BlinkerNumber TEMP("temp"); //定义温度数据键名
#define DHTPIN 2 //定义DHT11模块连接管脚io2
#define DHTTYPE DHT11 // 使用DHT 11温度湿度模块
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE); //定义dht
float humi_read = 0, temp_read = 0;
void heartbeat()
{
HUMI.print(humi_read); //给blinkerapp回传湿度数据
TEMP.print(temp_read); //给blinkerapp回传温度数据
}
void miotQuery(int32_t queryCode) //小爱同学语音命令反馈
{
BLINKER_LOG("MIOT Query codes: ", queryCode);
int humi_read_int = humi_read; //去掉湿度浮点
BlinkerMIOT.humi(humi_read_int); //小爱接收湿度
BlinkerMIOT.temp(temp_read); //小爱接收温度
BlinkerMIOT.print();
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);
dht.begin();
BlinkerMIOT.attachQuery(miotQuery);
}
void loop()
{
Blinker.run();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
BLINKER_LOG("Failed to read from DHT sensor!");
}
else
{
BLINKER_LOG("Humidity: ", h, " %");
BLINKER_LOG("Temperature: ", t, " *C");
humi_read = h;
temp_read = t;
}
Blinker.delay(500);
}[/mw_shl_code]
|