完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/* *****************************************************************
Download latest Blinker library here: Blinker is a cross-hardware, cross-platform solution for the IoT. It provides APP, device and server support, and uses public cloud services for data transmission and storage. It can be used in smart home, data monitoring and other fields to help users build Internet of Things projects better and faster. Make sure installed 2.5.0 or later ESP8266/Arduino package, if use ESP8266 with Blinker. Make sure installed 1.0.2 or later ESP32/Arduino package, if use ESP32 with Blinker. * ***************************************************************** Blinker 库下载地址: Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。 如果使用 ESP8266 接入 Blinker, 请确保安装了 2.5.0 或更新的 ESP8266/Arduino 支持包。 如果使用 ESP32 接入 Blinker, 请确保安装了 1.0.2 或更新的 ESP32/Arduino 支持包。 * *****************************************************************/ #define BLINKER_WIFI #include #include #include #include // Download Adafruit DHT-sensor-library library here: // #include int count = 0; bool WIFI_Status = true; char auth[] = "你的设备"; #define DHTPIN D5//nodemcu D5对应esp8266GPIO14 #define BUTTON_1 "ButtonKey" #define DHTTYPE DHT11// DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) BlinkerNumber HUMI("humi"); BlinkerNumber TEMP("温度"); BlinkerNumber HOUR("小时"); BlinkerNumber MIN("min"); //BlinkerNumber SEC("sec"); BlinkerNumber YEAR("年"); BlinkerNumber MONTH("月"); BlinkerNumber MDAY("mday"); BlinkerNumber WDAY("wday"); BlinkerButton Button1(BUTTON_1); DHT dht(DHTPIN, DHTTYPE); U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* 时钟=*/ 5, /* 数据=*/ 4, /* 复位=*/ U8X8_PIN_NONE); // 都是esp8266的GPIO uint32_t read_time = 0; 浮动 humi_read, temp_read; 布尔斯塔 = 0; int tem,嗡嗡声; 焦炭天气; bool first_weadher = true; BLINKER_LOG("Blinker readString: ", data); Blinker.vibrate(); uint32_t BlinkerTime = millis(); Blinker.print("millis", BlinkerTime); } void button1_callback(const String & state) { digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); BLINKER_LOG("get button state: ", state); if (state == BLINKER_CMD_BUTTON_TAP) { if (sta == 1) { BLINKER_LOG("Button tap!"); Button1.icon("fal fa-lightbulb-on"); Button1.color("#fddb00"); Button1.text("light on"); Button1.print(); } else { BLINKER_LOG("Button tap!"); Button1.icon("fal fa-lightbulb-on"); Button1.color("#F5F5F5"); Button1.text("light off"); Button1.print(); } sta = !sta; } } void dataStorage() { Blinker.dataStorage("humi", humi_read); Blinker.dataStorage("temp", temp_read); } void heartbeat() { HUMI.print(humi_read); TEMP.print(temp_read); } /*智能配网,推荐使用安信可公众号*/ void smartConfig()//配网函数 { WiFi.mode(WIFI_STA);//使用wifi的STA模式 Serial.println("rnWait for Smartconfig...");//串口打印 WiFi.beginSmartConfig();//等待手机端发出的名称与密码 //死循环,等待获取到wifi名称和密码 while (1) { //等待过程中一秒打印一个. Serial.print("."); digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); delay(1000); if (WiFi.smartConfigDone())//获取到之后退出等待 { Serial.println("SmartConfig Success"); //打印获取到的wifi名称和密码 Serial.printf("SSID:%srn", WiFi.SSID().c_str()); Serial.printf("PSW:%srn", WiFi.psk().c_str()); break; } } } bool autoConfig() { WiFi.begin(); for (int i = 0; i < 20; i++) { int wstatus = WiFi.status(); if (wstatus == WL_CONNECTED) { Serial.println("AutoConfig Success"); Serial.printf("SSID:%srn", WiFi.SSID().c_str()); Serial.printf("PSW:%srn", WiFi.psk().c_str()); WiFi.printDiag(串行); 返回真; //休息; } else { Serial.print("AutoConfig Waiting......"); Serial.println(wstatus); 延迟(1000); } } Serial.println("AutoConfig 失败!" ); 返回假; //WiFi.printDiag(Serial); } void weatherData(const String & data) { BLINKER_LOG("weather: ", data); Serial.println(数据); StaticJsonDocument<400> 文档; DeserializationError 错误 = deserializeJson(doc, data); 如果(错误) { first_weadher == true; 返回; } weath = doc["天气"]; tem = 文档 [" 哼=文档[“humi”]; } void setup() { Serial.begin(115200); BLINKER_DEBUG.stream(串行); pinMode(LED_BUILTIN,输出); 数字写入(LED_BUILTIN,低); Blinker.setTimezone(8.0);//时区 if (!autoConfig()) { Serial.println("启动模块"); 智能配置(); } Blinker.begin(auth, WiFi.SSID().c_str(), WiFi.psk().c_str());//运行blinker Blinker.attachData(dataRead); Button1.attach(button1_callback); Blinker.attachHeartbeat(心跳); Blinker.attachDataStorage(dataStorage, 60 , 1); Blinker.attachWeather(weatherData); dht.begin(); u8g2.begin(); u8g2.enableUTF8Print(); } 无效循环() { 字符 m_str[4]; 闪烁器.run(); int8_t 小时 = Blinker.hour(); int8_t min = Blinker.minute(); int8_t sec = Blinker.second(); int16_t 年 = Blinker.year(); int8_t 月 = Blinker.month(); int8_t mday = Blinker.mday(); int8_t wday = Blinker.wday(); HOUR.print(小时); MIN.print(min); // SEC.print(sec); YEAR.print(年); MONTH.print(月); MDAY.print(mday); WDAY.print(wday); u8g2.firstPage(); 做 { u8g2.setFont(u8g2_font_luIS08_tf); u8g2.setCursor(30, 15); u8g2.print(小时); // strcpy(m_str, u8x8_u8toa(hour, 2)); // u8g2.drawStr(30, 15, m_str); u8g2.drawStr(55, 15, ":"); // strcpy(m_str, u8x8_u8toa(min, 2)); // u8g2.drawStr(65, 15, m_str); u8g2.setCursor(65, 15); u8g2.print(min); // itoa(year, m_str, 10); //itoa() // u8g2.drawStr(20, 30, m_str); u8g2.setCursor(20, 30); u8g2.print(year); u8g2.drawStr(55, 30, "-"); // strcpy(m_str, u8x8_u8toa(month, 2)); // u8g2.drawStr(65, 30, m_str); u8g2.setCursor(65, 30); u8g2.print(month); u8g2.drawStr(90, 30, "-"); // strcpy(m_str, u8x8_u8toa(month, 2)); // u8g2.drawStr(100, 30, m_str); u8g2.setCursor(100, 30); u8g2.print(mday); u8g2.setFont(u8g2_font_luIS08_tf); u8g2.setFontDirection(0); u8g2.setCursor(40, 50); itoa(wday, m_str, 10); switch (wday) { case 0: u8g2.print("Sunday"); 休息; 案例一:u8g2.print("星期一"); 休息; 案例 2: u8g2.print("星期二"); 休息; 案例 3:u8g2.print("星期三"); 休息; 案例4:u8g2.print("星期四"); 休息; 案例 5:u8g2.print("星期五"); 休息; 案例 6:u8g2.print("星期六"); 休息; 默认值:u8g2.print("0"); } } 而 ( u8g2.nextPage() ); Blinker.delay(3000); read_time = millis(); float h = dht.readHumidity(); float t = dht.readTemperature(); if (isnan(h) || isnan(t)) { BLINKER_LOG("Failed to read from DHT sensor!"); return; } humi_read = h; temp_read = t; if (sec > 0) { if ((min > 58) || (first_weadher == true)) //每一小时获取一次天气信息,参考 { Blinker.weather("hebei-pingshanxian");//默认查询设备ip所属地区的当前时刻的天气情况 first_weadher = false ; //开机第一次更新默认查询设备ip所属地区的当前时刻的天气情况 } } u8g2.firstPage(); do { u8g2.setFont(u8g2_font_luIS08_tf); u8g2.drawStr(0, 15, "indoor-humi"); u8g2.drawStr(65, 15, ":"); strcpy(m_str, u8x8_u8toa(h, 2)); u8g2.drawStr(75, 15, m_str); u8g2.drawStr(90, 15, "%"); u8g2.drawStr(0, 30, "室内温度"); u8g2.drawStr(65, 30, ":"); strcpy(m_str, u8x8_u8toa(t, 2)); u8g2.drawStr(75, 30, m_str); u8g2.drawStr(90, 30, "C"); u8g2.setFont(u8g2_font_luIS08_tf); u8g2.drawStr(33, 45, "humi"); u8g2.drawStr(65, 45, ":"); u8g2.setCursor(75, 45); u8g2.print(哼); u8g2.drawStr(90, 45, "%"); u8g2.drawStr(33, 60, "temp"); u8g2.drawStr(65, 60, ":"); u8g2.setCursor(75, 60); u8g2.print(tem); u8g2.drawStr(90, 60, "C"); u8g2。 u8g2.setCursor(0, 53); u8g2.print("阴"); } while ( u8g2.nextPage() ); BLINKER_LOG("Humidity: ", h, " %"); BLINKER_LOG("Temperature: ", t, " *C"); Blinker.delay(3000); } } |
|
|
|
只有小组成员才能发言,加入小组>>
3310 浏览 9 评论
2991 浏览 16 评论
3492 浏览 1 评论
9055 浏览 16 评论
4086 浏览 18 评论
1174浏览 3评论
603浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
596浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2333浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1894浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 20:07 , Processed in 1.156303 second(s), Total 78, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号