Esp8266 nodemocu project: connect the air conditioning control of the previous project to Xiaoai classmate (Blinker_APP synchronous control + DHT11 temperature and humidity module data access)

Stagger tossing experience: esp8266 nodemocu

preface

It has been done before Project 2: DHT11 access to Xiaoai students as well as Item 3: air conditioning control The next step is to combine the two to realize app control, temperature and humidity viewing, and simple air conditioning control for Xiaoai.

Didi: the following is the main body of this article

Idea:

Realize app + Xiaoai dual control
Disguise the equipment as a lamp (let Xiao AI define our equipment as a lamp), and then customize the lamp mode function to realize multi-state control of air conditioning.

Official reference link:
Access Xiaoai's help document
Official sample file

You can see the following mode functions from the above data. What we need to do is magic change them!

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 equipment configuration:

Then the air conditioning controller equipment of the previous project was changed to add new components and realize more functions


The configuration code is as follows:

{¨version¨¨2.0.0¨¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img/headerbg.jpg¨¨isFull¨«}}¨dashboard¨|{¨type¨¨tex¨¨t0¨¨Air conditioning controller¨¨t1¨¨Run in the specified state¨¨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 ℃, refrigeration, Gaofeng ¨ g ¨ text 2 ¨ K ¨ n ¨ o ¨ P ¨ btn on ¨ x ´ y ´ Ð ß r|S Ë T ß u}{ß C ß V ß L ß w ß x É E ¨ 25 ℃, refrigeration, automatic air ¨ g ß Z ß K Ë n Í o ß P ¨ btn on auto ¨ x ´ y ´ Ð In the meantime, the author is still a person who has made a great effort to make an effort to face the country. The U}{{{{{{{a C C is still in the middle of the country. I'd like to make a score. The W is still a big one. I '''yet yet yet yet yet yet yet yet yet, the country is still in the middle of the country. The country is still in the middle of the country. The country is still in the middle of the country. Yet, the country is still in the middle of the country. The U is still in the middle of the country. Yet yet, the country is still in the middle of the country. Yet yet, the country '' '' '' '''S still still still still a country. The U, refrigeration, and the most galegalegale is the most big wind. G g is a G? G? G? G? G223isa g223yetyet yet, Z is a great document is still still still a great and the country '' '' '' '' '''What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'S the point? What'the point? What'S the point? What'S the point? What'the point? What'S the point? What'the point? What'S the point? What'the point? What'the point? What'S the point? What is the point? What is the point? The point? What is the point? What is the point of the point of the point?? what Ñ o Ì P ¨ deb ug ¨´ x ´ y ´ R ÷} In the end, the city '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''one one of the two' '''yet yet yet yet yet yet yet yet yet yet yet yet yet a temperature is a temperature, and yet yet yet yet yet yet yet yet, a temperature is still a temperature, and yet yet yet yet yet yet yet yet yet, one one of the one '' '' '' '' '' '' '''yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet yet to a one one '' '' '' '' '' '' '' '' '' '' '' '''223 K ß E ¨ humidity ¨ L ¨ fad FA humidity ¨ T ß u ß n É o º 0 ß P ´% ´ K Ê n Ë o ß P ¨ humi ´ x ´ 207 ´ y ´ 206ß R ÷} ÷ actions ÷ triggers ÷ ÷}

Program code

The code is as follows:

#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT / / Xiaoai is defined as light

#include <IRremoteESP8266.h>
#Include < irsend. H > / / infrared header file      
#Include < blinker. H > / / Lighting Technology header file
#Include < DHT. H > / / header file of DHT11 sensor
 
#define DHTPIN 4 / / define the DHT11 module connection pin GPIO4 (D2 pin)
#define DHTTYPE DHT11 / / use the DHT11 temperature and humidity module

char auth[] = "";//Fill in the device key here
char ssid[] = "";//Fill in your wifi name here
char pswd[] = "";//Fill in your WiFi password here

//Defines the pin for infrared emission
const uint16_t kIrLed = 14;  // Set kIrLed to GPIO14, D5 pin
IRsend irsend(kIrLed);  // Set kIrLed to send message

//Air conditioning on: 25, refrigeration, strong wind
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
//Air conditioning on: 25, refrigeration, automatic air
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
//Air conditioning on: 26. Refrigeration, strong wind
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
//Air conditioning off:
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, 1712,  512, 1650,  474, 1712,  512, 1650,  474, 598,  538, 560,  508, 568,  538, 560,  476, 596,  542, 560,  476, 628,  510, 562,  476, 1714,  512, 1650,  474, 1714,  510, 1650,  474, 1714,  512, 1650,  474, 1714,  512, 1650,  474, 626,  510, 562,  506, 596,  512, 560,  476, 628,  512, 560,  500, 602,  512, 562,  476, 1714,  514, 1648,  502, 1686,  512, 560,  502, 1688,  514, 560,  508, 1682,  514, 1648,  506, 594,  514, 560,  504, 598,  514, 1650,  502, 596,  516, 1648,  502, 598,  516, 556,  508, 596,  514, 1650,  504, 1682,  518, 558,  506, 1682,  520, 556,  504, 1684,  522, 1644,  504, 1682,  550, 528,  504, 596,  550, 1614,  530, 570,  578, 1586,  558, 544,  578, 498,  560, 542,  576, 1586,  562, 542,  576, 1586,  560, 544,  576, 1586,  558, 546,  576, 502,  552, 1612,  600, 502,  520, 1644,  598, 532,  470, 1664,  572, 530,  500, 1664,  570, 1620,  500, 7328,  456};  // GOODWEATHER D52928000000

// New Blinker component object
BlinkerButton Button1("btn-on");
BlinkerButton Button2("btn-on-auto");
BlinkerButton Button3("btn-26");
BlinkerButton Button4("btn-off");

BlinkerNumber HUMI("humi");    //Define humidity data key name
BlinkerNumber TEMP("temp");    //Define temperature data key name

DHT dht(DHTPIN, DHTTYPE);    //Define dht
float humi_read = 0, temp_read = 0;  //Initialize read data

void heartbeat()
{
    HUMI.print(humi_read);        //Send humidity data back to blinkerapp
    TEMP.print(temp_read);        //Send back temperature data to blinkerapp
}

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

    if (mode == BLINKER_CMD_MIOT_DAY) {//daylight mode 
        BLINKER_LOG("Dormitory air conditioner on:25,Refrigeration, strong wind");
        irsend.sendRaw(power_on, 199, 38);
        delay(100);
    }
    else if (mode == BLINKER_CMD_MIOT_NIGHT) {//Moon mode 
        BLINKER_LOG("Dormitory air conditioner on:25,Refrigeration, automatic air");
        irsend.sendRaw(power_on_auto, 199, 38);
        delay(100);
    }
    else if (mode == BLINKER_CMD_MIOT_COLOR) {//Color light mode
        BLINKER_LOG("Dormitory air conditioner on:26,Refrigeration, strong wind");
        irsend.sendRaw(power_on_26, 199, 38);
        delay(100);
    }
    else if (mode == BLINKER_CMD_MIOT_WARMTH) {//Warm mode
        BLINKER_LOG("Dormitory air conditioner off");
        irsend.sendRaw(power_off, 199, 38);
        delay(100);
    }
    BlinkerMIOT.mode(mode);
    BlinkerMIOT.print();
}

void setup()
{
  BLINKER_DEBUG.stream(Serial);
  //Initialize serial port
  Serial.begin(115200);
  //Register callback function/
  Button1.attach(Button1_callback);
  Button2.attach(Button2_callback);
  Button3.attach(Button3_callback);
  Button4.attach(Button4_callback);
 //Distribution network steps: WIFI access
  Blinker.begin(auth,ssid,pswd); 
  //Infrared initialization
  irsend.begin();
  Blinker.attachHeartbeat(heartbeat);//Register heartbeat function: return data to app
  dht.begin();
  BlinkerMIOT.attachMode(miotMode);//Register custom mode functions

}

void loop()
{
  Blinker.run(); 
    float h = dht.readHumidity();    //Read the humidity data collected by DHT11
    float t = dht.readTemperature(); //Read the temperature data collected by DHT11
 
    if (isnan(h) || isnan(t))//Judge whether the temperature and humidity value is empty
    {
        BLINKER_LOG("Failed to read sensor data");
    }
    else
    {
        BLINKER_LOG("Humidity: ", h, " %");//Print out debugging information
        BLINKER_LOG("Temperature: ", t, " *C");
        humi_read = h;
        temp_read = t;
    }
    Blinker.delay(500);
}

//Callback function 1
void Button1_callback(const String &state)
{

  BLINKER_LOG("get button state: ", state);
  //Normal button press detected (BTN on)
  if (state == BLINKER_CMD_BUTTON_TAP)
  {
    //Send infrared command
    irsend.sendRaw(power_on, 199, 38);
    Button1.print("Dormitory air conditioner on:25,Refrigeration, strong wind");
  
  }

}

//Callback function 2
void Button2_callback(const String &state)
{
  BLINKER_LOG("get button state: ", state);
  //BTN on Auto button press detected
  if (state == BLINKER_CMD_BUTTON_TAP)
  {
    irsend.sendRaw(power_on_auto, 199, 38);
    Button2.print("Dormitory air conditioner on:25,Refrigeration, automatic air");
  }

}

//Callback function 3
void Button3_callback(const String &state)
{

  BLINKER_LOG("get button state: ", state);
  //Button btn-26 press detected
  if (state == BLINKER_CMD_BUTTON_TAP)
  {
    //Send infrared command
    irsend.sendRaw(power_on_26, 199, 38);
    Button1.print("Dormitory air conditioner on:26,Refrigeration, strong wind");
  
  }

}

//Callback function 4
void Button4_callback(const String &state)
{
  BLINKER_LOG("get button state: ", state);
  //BTN off button pressed detected
  if (state == BLINKER_CMD_BUTTON_TAP)
  {
    irsend.sendRaw(power_off, 199, 38);
    Button2.print("Dormitory air conditioner off");
  }

}

Then, wiring shall be carried out according to the pin of the board corresponding to the GPIO defined by the code:
As shown in the figure:

Infrared module: data pin connected to D5 (GPIO14)
DHT11 module: data pin connected to D2 (GPIO4)
Just find the positive and negative pins and connect the 3v and G (grounding) on the board

Xiaoai training & Testing

After uploading the code, enter the MI home and synchronize the device:

You can see that the app already has data

Then we will train Xiao AI's classmates:



Training is configured according to the actual situation of the mode function you define. You only need to train the wake-up word, and then select the execute action

The custom name here is the air conditioning controller. In fact, Xiaoai defines the light equipment to control different air conditioning states according to the last mode

hey!
The last is the test

The wake-up word here is: turn on the dormitory air conditioner

PS: all the effects have been achieved. It's too cumbersome to record the video. It's not difficult to improve the air conditioning control based on the last project. It's just a little imperfect. Xiaoai can't read the temperature and humidity and can only view it on the app. DIY device Xiaoai can only be defined as one device type, and Blinker official only provides five device types for free users, But it's enough. Nice

summary

Basically improved, the functions you want, the next thing to consider is a set of applicable power supply scheme, as well as optimizing code and reducing power consumption. After all, most Internet of things devices focus on low power consumption!

emmm, it rained all day today, and the weather turned much cooler. It seems that you can't use the air conditioner. Gee, forget it. I'd better believe in the weather in Guangdong! ╮(╯﹏╰)╭

Project directory:
Stagger esp8266 nodemocu project I
Stagger esp8266 nodemcu Project II
Stagger esp8266 nodemcu project III
Stagger esp8266 nodemocu project IV

Tags: Single-Chip Microcomputer IoT MCU

Posted on Fri, 08 Oct 2021 15:12:10 -0400 by evmace