ESP8266-NodeMCU项目:将上一项目的空调控制接入小爱同学(Blinker_APP同步控制+DHT11温湿度模块数据接入)

Posted 错开呀!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ESP8266-NodeMCU项目:将上一项目的空调控制接入小爱同学(Blinker_APP同步控制+DHT11温湿度模块数据接入)相关的知识,希望对你有一定的参考价值。

错开の折腾经历:ESP8266 NodeMCU


前言

之前已经进行了项目二:DHT11接入小爱同学以及项目三:空调控制,接下来便是将二者合一,实现app控制,温湿度查看,以及小爱同学进行简单空调控制。


滴滴:以下是本篇文章正文内容

思路:

实现app+小爱双控制
将设备伪装为灯(就让小爱同学把咱设备定义为灯),然后自定义灯模式函数实现多状态控制空调。

官方参考链接:
接入小爱同学の帮助文档
官方示例文件

可以从以上资料中看见以下的模式函数,我们要做的就是将其进行魔改!

void miotMode(uint8_t mode)
{
    BLINKER_LOG("need set mode: ", mode);

    if (mode == BLINKER_CMD_MIOT_DAY) {
        // Your mode function
    }
    else if (mode == BLINKER_CMD_MIOT_NIGHT) {
        // Your mode function
    }
    else if (mode == BLINKER_CMD_MIOT_COLOR) {
        // Your mode function
    }
    else if (mode == BLINKER_CMD_MIOT_WARMTH) {
        // Your mode function
    }
    else if (mode == BLINKER_CMD_MIOT_TV) {
        // Your mode function
    }
    else if (mode == BLINKER_CMD_MIOT_READING) {
        // Your mode function
    }
    else if (mode == BLINKER_CMD_MIOT_COMPUTER) {
        // Your mode function
    }

    wsMode = mode;

    BlinkerMIOT.mode(mode);
    BlinkerMIOT.print();
}

Blinker_APP设备配置:

紧接着上一项目的空调控制器设备进行更改,增加新组建,实现更多功能


配置代码如下:

{¨version¨¨2.0.0¨¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img/headerbg.jpg¨¨isFull¨«}}¨dashboard¨|{¨type¨¨tex¨¨t0¨¨空调控制器¨¨t1¨¨以指定状态运行¨¨size¨¨22¨¨bg¨Ê¨ico¨¨fad fa-air-conditioner¨¨cols¨Í¨rows¨Ë¨key¨¨tex-cnl¨´x´É´y´Î¨speech¨|÷¨lstyle¨Ì¨clr¨¨#076EEF¨}{ßC¨btn¨ßL¨fad fa-snowflakes¨¨mode¨ÉßE¨25℃、制冷、高凤¨ßG¨文本2¨ßKËßNÍßOÍßP¨btn-on¨´x´É´y´ÐßR|÷ßSËßTßU}{ßCßVßLßWßXÉßE¨25℃、制冷、自动风¨ßGßZßKËßNÍßOÍßP¨btn-on-auto¨´x´Í´y´ÐßR|÷ßSËßTßU}{ßCßVßLßWßXÉßE¨26℃、制冷、最大风¨ßGßZßKËßNÍßOÍßP¨btn-26¨´x´É´y´¤BßR|÷ßTßUßSË}{ßCßVßL¨fad fa-power-off¨ßXÉßE¨关机¨ßGßZßKËßNÍßOÍßP¨btn-off¨´x´Í´y´¤BßR|÷ßSËßTßU}{ßC¨deb¨ßXÉßKÉßNÑßOÌßP¨debug¨´x´É´y´ËßR|÷}{ßC¨num¨ßE¨温度¨ßL¨fad fa-thermometer-three-quarters¨ßTßU¨min¨É¨max¨¢1c¨uni¨´℃´ßKÊßNËßOËßP¨temp¨´x´Í´y´ÎßR|÷ßSÉ}{ßCßkßE¨湿度¨ßL¨fad fa-humidity¨ßTßUßnÉßoº0ßp´%´ßKÊßNËßOËßP¨humi¨´x´Ï´y´ÎßR|÷}÷¨actions¨|÷¨triggers¨|÷}

程序代码

代码如下:

#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT //小爱同学定义为灯

#include <IRremoteESP8266.h>
#include <IRsend.h>  //红外头文件      
#include <Blinker.h>  //点灯科技头文件
#include <DHT.h>         //DHT11传感器的头文件
 
#define DHTPIN 4      //定义DHT11模块连接管脚GPIO4(D2脚)
#define DHTTYPE DHT11   // 使用DHT11温度湿度模块

char auth[] = "";//这里面填写设备的密钥
char ssid[] = "";//这里填写你的wifi名字
char pswd[] = "";//这里填写你的WiFi密码

//定义红外发射的管脚
const uint16_t kIrLed = 14;  // 设置kIrLed为GPIO14,D5脚
IRsend irsend(kIrLed);  // 将kIrLed设置发送信息

//空调开:25、制冷、大风
uint16_t power_on[199] = {5998, 7318,  478, 1712,  540, 1622,  474, 1712,  542, 1622,  474, 1712,  542, 1620,  474, 1714,  542, 1622,  474, 596,  568, 532,  456, 618,  568, 532,  476, 598,  570, 532,  478, 596,  570, 532,  478, 1712,  542, 1622,  474, 1712,  542, 1622,  474, 1712,  542, 1622,  474, 1714,  542, 1622,  474, 598,  568, 532,  456, 618,  568, 532,  478, 598,  568, 532,  478, 596,  570, 532,  478, 1712,  544, 1622,  474, 1714,  542, 1622,  474, 1712,  544, 1622,  474, 1712,  544, 1622,  474, 598,  570, 532,  456, 618,  568, 532,  476, 600,  566, 532,  478, 602,  566, 530,  478, 1710,  546, 532,  456, 1732,  522, 556,  454, 1732,  546, 532,  526, 1660,  546, 1622,  526, 576,  514, 1650,  476, 626,  514, 1646,  478, 626,  548, 1612,  510, 594,  554, 522,  506, 596,  552, 1610,  506, 1660,  576, 524,  504, 1662,  572, 528,  502, 1664,  566, 1622,  502, 1664,  562, 536,  504, 574,  536, 1652,  504, 576,  534, 1654,  504, 596,  508, 570,  502, 598,  506, 1660,  502, 598,  506, 1660,  502, 598,  504, 1664,  498, 600,  502, 600,  476, 1692,  474, 626,  472, 1718,  448, 630,  470, 1720,  448, 630,  470, 1720,  448, 1720,  470, 7384,  446};  // GOODWEATHER D5292A000000
//空调开:25、制冷、自动风
uint16_t power_on_auto[199] = {6036, 7330,  476, 1716,  514, 1650,  474, 1716,  516, 1650,  474, 1716,  514, 1652,  520, 1670,  514, 1652,  524, 550,  542, 560,  456, 650,  514, 558,  476, 628,  514, 560,  478, 628,  514, 560,  476, 1718,  514, 1652,  474, 1716,  516, 1650,  476, 1716,  514, 1652,  474, 1716,  514, 1652,  474, 600,  540, 562,  456, 648,  514, 560,  476, 628,  512, 562,  478, 598,  540, 562,  456, 624,  538, 1654,  452, 622,  540, 1654,  452, 1738,  512, 1654,  452, 1738,  512, 1652,  454, 1738,  514, 562,  476, 1718,  514, 560,  456, 650,  514, 560,  476, 630,  512, 562,  476, 1718,  514, 560,  478, 1716,  514, 560,  478, 1718,  512, 1654,  454, 1738,  514, 1652,  454, 650,  510, 1654,  474, 630,  512, 1652,  504, 600,  514, 560,  508, 598,  514, 560,  506, 600,  512, 1652,  504, 1688,  514, 560,  508, 1686,  516, 560,  506, 1686,  516, 1652,  504, 1686,  518, 558,  506, 596,  542, 1624,  506, 596,  546, 1622,  528, 574,  552, 524,  558, 544,  580, 1586,  556, 548,  578, 1586,  562, 540,  578, 1586,  560, 546,  576, 500,  526, 1640,  602, 502,  552, 1614,  602, 500,  524, 1640,  602, 502,  498, 1668,  574, 1616,  502, 7332,  456}; // GOODWEATHER D5290A050000
//空调开:26、制冷、大风
uint16_t power_on_26[199] = {6062, 7302,  476, 1718,  538, 1628,  474, 1716,  540, 1626,  454, 1740,  514, 1650,  472, 1718,  516, 1650,  452, 620,  542, 560,  528, 546,  544, 560,  456, 620,  544, 560,  458, 618,  544, 558,  478, 1716,  516, 1650,  452, 1740,  514, 1650,  454, 1738,  516, 1650,  474, 1718,  514, 1652,  454, 618,  544, 558,  458, 620,  542, 560,  456, 620,  544, 560,  456, 620,  544, 560,  528, 1668,  516, 558,  476, 1718,  540, 1626,  476, 1716,  516, 1650,  454, 1738,  516, 1650,  474, 600,  544, 1650,  476, 598,  544, 560,  476, 602,  542, 560,  476, 604,  540, 560,  456, 1740,  514, 560,  476, 1718,  538, 536,  456, 1740,  538, 536,  456, 1738,  516, 1650,  476, 628,  514, 1652,  454, 648,  514, 1652,  454, 648,  514, 1652,  476, 626,  516, 562,  506, 1684,  546, 532,  532, 1660,  552, 524,  556, 1634,  582, 496,  560, 1634,  580, 1584,  562, 542,  580, 1584,  560, 544,  578, 1586,  530, 574,  576, 1588,  530, 576,  548, 526,  504, 602,  546, 1618,  504, 576,  568, 1620,  502, 578,  564, 1624,  504, 576,  562, 536,  502, 1666,  538, 562,  504, 1666,  536, 564,  504, 1666,  534, 566,  502, 1690,  510, 1658,  504, 7332,  502};  // GOODWEATHER D52A2A020000
//空调关:
uint16_t power_off[199] = {6022, 7290,  476, 1714,  510, 1650,  472, 1714,  512, 1650,  518, 1668,  510, 1652,  472, 1714,  512, 1650,  474, 626,  510, 560,  454, 648,  512, 562,  474, 598,  542, 562,  476, 598,  540, 560,  476, 1714,  512, 1650,  472, 1714,  512, 1648,  474以上是关于ESP8266-NodeMCU项目:将上一项目的空调控制接入小爱同学(Blinker_APP同步控制+DHT11温湿度模块数据接入)的主要内容,如果未能解决你的问题,请参考以下文章

基于ESP8266 NodeMCU + DHT22 记录室内温湿度

基于ESP8266 NodeMCU + DHT22 记录室内温湿度

基于ESP8266 NodeMCU + DHT22 记录室内温湿度

ESP-NOW ESP8266 NodeMCU单板双向通信

Arduino杀手在此!!ESP 8266 NodeMCU小白手把手入门(解惑篇)

ESP8266(nodemcu)引脚和I2C的坑!!!