当前位置:网站首页>Cloud platform monitoring system based on stm32+ Huawei cloud IOT design

Cloud platform monitoring system based on stm32+ Huawei cloud IOT design

2022-06-26 16:20:00 InfoQ

1.  Preface

As an emerging industry, intelligent systems , It is one of the national key development industries . Abroad from the United States in 1984 The real intelligent building has been built since 30 Years of history . Due to the security of smart home 、 Efficient 、 Convenient to , And intelligence , Make the smart home industry in 2003 In, it gradually entered China's home furnishing market , But because our country started late , The smart home industry standards are not unified in China's home market . With the continuous reduction of global resources and the destruction of the environment ,“ Energy conservation and environmental protection ” It has become the primary requirement for the development of global science and technology , and “ Global intelligence ” The advantages in energy conservation and environmental protection make smart home the mainstream of development , Therefore, it has a very broad market prospect . meanwhile , With the progress of science and technology , Traditional architecture can no longer meet the needs of modern people for comfort in life , And intelligent systems are also imperceptibly infiltrating our lives .

Smart home (smart home) Take the residence as the platform , The embedded single chip microcomputer is used as the core controller to realize the non -   Line communication 、 System integration of smart home environment based on security and automatic control technology , To realize the smart home   Remote security monitoring of the environment , Environmental monitoring and control of each subsystem , Building efficient and intelligent residential facilities   And family safety management system , Home intelligence 、 Security , The convenience and comfort have been significantly improved , It has effectively improved people's quality of life .

Smart home not only provides comfortable, pleasant and high-grade family living space , Achieve a more intelligent home security system ; It also transforms the home environment from the original passive static structure into a tool with dynamic wisdom , Provide a full range of information interaction function . The application of wireless sensors in the Internet of things can provide intelligent disaster prevention for families , Light control , And home appliance networking provide a good solution . And use GPRS Communication module , It can inform the head of household of the emergency information in the family , And intelligent alarm . This greatly reduces the loss of family accident disaster .

This design combines the specific needs of modern life , Design a set based on Huawei cloud IOT Designed cloud platform monitoring system , You can view the light intensity in your home remotely and in real time 、 Temperature, humidity and other information , Support the control of home electrical equipment in the cloud , Realize remote control .

2.  Specific needs

It mainly realizes the illumination intensity 、 Real time monitoring of temperature, humidity and other information , Send relevant information 、 Real time display of equipment status information , adopt ESP8266wifi The module can realize remote data transmission through networking , Use Huawei cloud IOT Internet of things cloud platform ,MQTT Transfer protocol , Call Huawei cloud IOT The interface provided by the platform is designed to realize remote control and display .

Hardware option requirements :

(1)ESP8266  A serial port WIFI, Used with OneNet To communicate remotely .

(2)DHT11  Temperature sensor , Check the temperature and humidity information of the local environment .

(3) Relay , To simulate the control of home appliances .

(4)BH1750  Photosensitive sensors , Detect the ambient light intensity

(5)MQ135  Air quality sensors . Combustible gas can be detected 、 Smoke concentration , Realize fire alarm .

(6)OLED The display shows the parameters of the local sensor , Real time display

null
null
null
null
null
null
null
null
null

3.  Hardware selection

3.1  Relay

null

3.2 ESP8266 WIFI

(1) The module adopts serial port (LVTTL) And MCU( Or other serial devices ) signal communication , built-in TCP/IP Protocol stack , Can realize serial port and WIFI Conversion between (2) Module support LVTTL A serial port , compatible 3.3V and 5V Single chip system (3) The module supports serial port to WIFI STA、 Serial port to AP and WIFI STA+WIFIAP The pattern of , So as to build the serial port quickly -WIFI Data transmission scheme

null

3.3 MQ-135 Air quality sensors

MQ135 The sensor is sensitive to ammonia 、 Sulfide 、 Benzene steam has high sensitivity , Monitoring of smoke and other hazards is also ideal . This sensor can detect a variety of harmful gases , It is a low-cost sensor suitable for a variety of applications .

null
null
null

3.4 DHT11 Temperature and humidity sensor

DHT11 Digital temperature and humidity sensor is a temperature and humidity composite sensor with calibrated digital signal output . It uses special digital module acquisition technology and temperature and humidity sensing technology , Ensure that the product has reliability and excellent long-term stability , The cost is low 、 Relative humidity and temperature measurement 、 Fast response 、 Strong anti-interference ability 、 Long signal transmission distance 、 Digital signal output 、 Accurate calibration . The sensor consists of a capacitive humidity sensing element and a sensor NTC Temperature measuring element , And with a high performance 8 Bit single chip microcomputer connected . It can be used for HVAC 、 Dehumidifier 、 Testing and testing equipment 、 consumer goods 、 automobile 、 Auto-Control 、 data logger 、 weather station 、 Home appliance 、 Humidity regulator 、 Medical care 、 Other relevant humidity detection and control .

The characteristics are as follows :

1、 It can detect the humidity of the surrounding environment

2、 It can detect the temperature of the surrounding environment

3、 Humidity measurement range :20%-95%(0 degree -50 Degree range ) Humidity measurement error :+-5%4、 Temperature measurement range :o degree -50 Degree temperature measurement error :+-2 degree

4、 Working voltage 3.3V-5V

5、 Output form digital output

null
null

3.5 STM32 System board

master control CPU use STM32F103RCT6, This chip includes 48 KB SRAM、256 KB Flash、2 A basic timer 、4 A universal timer 、2 An advanced timer 、51 General purpose IO mouth 、5 A serial port 、2 individual DMA controller 、3 individual SPI、2 individual I2C、1 individual USB、1 individual CAN、3 individual 12 position ADC、1 individual 12 position DAC、1 individual SDIO Interface , Chips are of the large capacity type , High configuration , The overall design conforms to the hardware selection . The currently selected development board comes with a 1.4 " TFT-LCD Color screen , It can display the current sensor data and some operation status information .

null

3.6 OLED display

null
characteristic :

OLED Is an organic light emitting diode, also known as organic laser display 、OLED Display technology has the characteristics of self illumination 、 Very thin organic material coating 、 And glass substrates 、 When an electric current is passing through 、 These organic materials emit light 、 and OLED The display screen can be viewed from a large angle 、 Low power consumption 、OLED Because it has self illumination at the same time 、 No backlight ( It's just that the power supply won't light up 、 Only when the driver and wiring are correct will it light up ) High contrast 、 Thin thickness and wide viewing angle 、 Quick reaction 、 Can be used for flexure panels 、 It has a wide temperature range 、 Excellent properties such as structure and manufacturing process 、 First contact 1286 All the screens are LCD Of 、 Need backlight 、 High power consumption 、 and OLED Low power consumption 、 More suitable for small systems 、 Due to the difference between the two luminescent materials 、 In different environments 、OLED Good display effect 、 Module power supply can be 3.3v It can also be 5V、 There is no need to modify the module circuit 、OLED The screen has multiple control commands 、 Can be controlled oLED The brightness of 、 Contrast 、 Switch boost circuit and other instructions 、 It is easy to operate 、 Rich in functions 、 Chinese characters can be displayed 、ASCH、 Patterns, etc 、 At the same time, in order to facilitate its application in products 、 reserve 4 individual M3 Fixing holes 、 It is convenient for users to fix it on the casing .

3.7  Female to female DuPont line

null

3.8 BH1750 Photosensitive sensors

null

4.  Log in to Huawei cloud to create cloud products and devices

4.1  Create products

Huawei transport official website : https://www.huaweicloud.com/

null
null
null
null
MQTT (1883) a161a58a78.iot-mqtts.cn-north-4.myhuaweicloud.com 

The protocol choice of our device access MQTT, The port corresponds to 1883

Next, continue to create the product , Click on the product page , Click on the top right corner to create the product :

null
null
null

4.2  Create device

null
null

4.3  Product model definition

This step is to set the properties of the reporting device , That is, the data type definition of the device .

null
null
null
null

4.4  Generate MQTT Login key

After creating the product 、 After the device , Then you need to know how to pass MQTT Log in to the Huawei ECS according to the protocol .

The official details are here : https://support.huaweicloud.com/devg-iothub/iot_01_2127.html#ZH-CN_TOPIC_0240834853__zh-cn_topic_0251997880_li365284516112

null
null
MQTT Device login key generation address : https://iot-tool.obs-website.cn-north-4.myhuaweicloud.com/

null

4.5  Use MQTT Client software login

All the parameters have been , Next, use MQTT The client logs in to Huawei cloud for testing .

The following software is developed by ourselves , For testing purposes MQTT Protocol login .

The domain name of Huawei cloud Internet of things platform is : 
a161a58a78.iot-mqtts.cn-north-4.myhuaweicloud.com

Of Huawei's cloud Internet of things platform IP The address is : 
121.36.42.100

null
null

4.6  Report data

Official documents : https://support.huaweicloud.com/devg-iothub/iot_01_2127.html#ZH-CN_TOPIC_0240834853__zh-cn_topic_0251997880_li365284516112

In this document MQTT Format of reported data .

null
null
null
The format of the summary :

// Subscribe to topics :  The platform sends a message to the device
$oc/devices/61a580fad28ce3028832c2d8_esp8266_iot/sys/messages/down

// Equipment report data
$oc/devices/61a580fad28ce3028832c2d8_esp8266_iot/sys/properties/report

// Reported attribute message  ( Multiple attributes can be reported at a time , stay json Just add it to the )
{"services": [{"service_id": "dht11","properties":{"DHT11-C":50}}]}

null

5. STM32 Device code

STM32 Connecting Huawei cloud IOT Project code for Get: https://download.csdn.net/download/xiaolong1126626497/81993720

The serial port will output the status information of the current program , You can open the serial port debugging assistant to view .

null

5.1 LCD Chinese characters are modeled

LCD Chinese characters need to be displayed on the , Use dot matrix font mold taking software to take mold .

null

5.2  Hardware connection

null
1. ESP8266 WIFI connection
ATK-ESP8266 A serial port WIFI Module and STM32 Serial port 2 Connect .
PA2(TX)--RXD  Module receiving pin
PA3(RX)--TXD  Module sending pin
GND---GND  The earth
VCC---VCC  Power Supply (3.3V~5.0V)

2. TFT 1.44  Inch color screen wiring
GND  Power ground
VCC  Pick up 5V or 3.3v Power Supply
SCL  Pick up PC8(SCL)
SDA  Pick up PC9(SDA)
RST  Pick up PC10
DC  Pick up PB7
CS  Pick up PB8
BL  Pick up PB11

3. DHT11  Temperature and humidity
VCC--VCC
GND---GND
DAT---PA5 

4. LED The lamp - Simulate the lighting of the room
VCC--->5V
DAT--->PB12 
GND--->GND

5.  Smart curtains - Simulate the curtains at home
VCC--->5V
DAT--->PB13 
GND--->GND

6. MQ135 Air quality detection sensor
VCC--->5V
GND--->GND
DAT--->PA1

7. BH1750 Ambient light detection module :
SDA-----PB5
SCL-----PB6
GND---GND  The earth
VCC---VCC  Power Supply (3.3V~5.0V)

8.  On board LED Lamp wiring
LED1---PA8
LED2---PD2

9.  On board key wiring
K0---PA0 
K1---PC5 
K2---PA15

5.2 keil Project layout

engineering Get Address : https://download.csdn.net/download/xiaolong1126626497/81993720

null
null

5.3 main.c Code

MQTT The protocol connects Huawei cloud IOT Source code engineering reference : https://download.csdn.net/download/xiaolong1126626497/81993720

#include "stm32f10x.h"
#include "led.h"
#include "delay.h"
#include "key.h"
#include "usart.h"
#include <string.h>
#include &quot;timer.h&quot;
#include &quot;esp8266.h&quot;
#include &quot;motor.h&quot;
#include &quot;oled.h&quot;
#include &quot;dht11.h&quot;
#include &quot;adc.h&quot;
#include <string.h>
#include <stdlib.h>
#include &quot;font.h&quot;
#include &quot;mqtt.h&quot;
#include &quot;iic.h&quot;
#include &quot;bh1750.h&quot;

/*

(1)ESP8266  A serial port WIFI, Used to communicate with Huawei cloud IOT To communicate remotely .

(2)DHT11  Temperature sensor , Check the temperature and humidity information of the local environment .

(3) Relay , To simulate the control of home appliances .

(4)BH1750  Photosensitive sensors , Detect the ambient light intensity

(5)MQ135  Air quality sensors . Combustible gas can be detected 、 Smoke concentration , Realize fire alarm .

(6)OLED The display shows the parameters of the local sensor , Real time display

*/


// Equipment information of Huawei Internet of things server
#define MQTT_ClientID &quot;61b9ba3a2b2aa20288c1e7f1_QQ1126626497_0_0_2021121510&quot;
#define MQTT_UserName &quot;61b9ba3a2b2aa20288c1e7f1_QQ1126626497&quot;
#define MQTT_PassWord &quot;385ce91dfe7da5b7431868d5d87e7998163c493344040935d5a00024d6324242&quot;

// Topics subscribed and published
#define SET_TOPIC &quot;$oc/devices/61b9ba3a2b2aa20288c1e7f1_QQ1126626497_0_0_2021121510/sys/messages/down&quot; // subscribe
#define POST_TOPIC &quot;$oc/devices/61b9ba3a2b2aa20288c1e7f1_QQ1126626497_0_0_2021121510/sys/properties/report&quot; // Release


// Set the connected router information
#define CONNECT_WIFI &quot;Xiaomi_meizi6&quot; // The name of the router to be connected  -- Do not appear in Chinese 、 Special characters such as spaces
#define CONNECT_PASS &quot;12170307yu&quot; // The password of the router to be connected

#define CONNECT_SERVER_IP &quot;121.36.42.100&quot; // The server IP Address
#define CONNECT_SERVER_PORT 1883 // Server port number

//JTAG Mode setting , Used for setting up JTAG The pattern of
//mode:jtag,swd Mode setting ;00, All enable ;01, Can make SWD;10, All closed ; 
#define JTAG_SWD_DISABLE 0X02
#define SWD_ENABLE 0X01
#define JTAG_SWD_ENABLE 0X00 
void JTAG_Set(u8 mode)
{
 u32 temp;
 temp=mode;
 temp<<=25;
 RCC->APB2ENR|=1<<0; // Turn on the auxiliary clock  
 AFIO->MAPR&=0XF8FFFFFF; // eliminate MAPR Of [26:24]
 AFIO->MAPR|=temp; // Set up jtag Pattern
}


u8 motor_flag=0; // The state of the curtain  0 Means closing  1 Means open
u8 led_flag=0; // Room lighting status  0 Means closing  1 Means open
u16 MQ135_data=0; //MQ135 Smoke sensor value
u8 DHT11_T=0; // ambient temperature
u8 DHT11_H=0; // ambient humidity
u8 BH1750_data=0; // Ambient light intensity

char request_id[100];
char mqtt_message[100];

//WIFI Send data storage area
char data_buff[300];

int main()
{
 u8 esp8266_state=0;
 u8 key;
 u8 i;
 u32 time_cnt=0;
 u32 timer_hour_cnt=0; // Record the timing
 
 JTAG_Set(JTAG_SWD_DISABLE); // Release PA15
 LED_Init();
 KEY_Init();
 USART1_Init(115200);
 Moto_Init(); // Fan 、 Heating rod initialization
 USART2_Init(115200);// A serial port -WIFI
 TIMER2_Init(72,20000); // Timeout time 20ms
 DHT11_Init(); // initialization DHT11
 Lcd_Init(); //LCD initialization
 Lcd_Clear(0); // The screen is black
 LCD_LED_SET;// adopt IO Control back light  
 AdcInit(); //ADC initialization -- testing MQ2 Smoke sensor data
 IIC_Init();
 printf(&quot; Initializing WIFI One moment please .\r\n&quot;);
 
 for(i=0;i<5;i++)
 {
 if(ESP8266_Init()==0)
 {
 esp8266_state=1;
 break;
 }
 else
 {
 esp8266_state=0;
 printf(&quot;ESP8266 Hardware detection error .\n&quot;); 
 }
 }
 
 if(esp8266_state)
 {
 printf(&quot; Ready to connect to the server ....\r\n&quot;);
 // Unencrypted port
 printf(&quot;WIFI:%d\n&quot;,ESP8266_STA_TCP_Client_Mode(CONNECT_WIFI,CONNECT_PASS,CONNECT_SERVER_IP,CONNECT_SERVER_PORT,1));
 
 //2. MQTT Protocol initialization  
 MQTT_Init(); 

 //3.  Connect to server  
 for(i=0;i<5;i++)
 {
 if(MQTT_Connect(MQTT_ClientID,MQTT_UserName,MQTT_PassWord)==0)
 {
 esp8266_state=1;
 break;
 }
 esp8266_state=0;
 printf(&quot; Server connection failed , Retrying ...\n&quot;);
 delay_ms(500);
 }
 printf(&quot; Server connection successful .\n&quot;);

 //3.  Subscribe to topics
 if(MQTT_SubscribeTopic(SET_TOPIC,0,1))
 {
 printf(&quot; Topic subscription failed .\n&quot;);
 }
 else
 {
 printf(&quot; Topic subscription succeeded .\n&quot;);
 } 
 }
 
 
 // ambient temperature
 LCD_ShowChineseFont(0,0,16,HZ_FONT_16[0],RED,0);
 LCD_ShowChineseFont(16*1,0,16,HZ_FONT_16[1],RED,0);
 LCD_ShowChineseFont(16*2,0,16,HZ_FONT_16[2],RED,0);
 LCD_ShowChineseFont(16*3,0,16,HZ_FONT_16[3],RED,0);
 
 // ambient humidity
 LCD_ShowChineseFont(0,16*1,16,HZ_FONT_16[4],RED,0);
 LCD_ShowChineseFont(16*1,16*1,16,HZ_FONT_16[5],RED,0);
 LCD_ShowChineseFont(16*2,16*1,16,HZ_FONT_16[6],RED,0);
 LCD_ShowChineseFont(16*3,16*1,16,HZ_FONT_16[7],RED,0);
 
 // Light intensity
 LCD_ShowChineseFont(0,16*2,16,HZ_FONT_16[8],RED,0);
 LCD_ShowChineseFont(16,16*2,16,HZ_FONT_16[9],RED,0);
 LCD_ShowChineseFont(16*2,16*2,16,HZ_FONT_16[10],RED,0);
 LCD_ShowChineseFont(16*3,16*2,16,HZ_FONT_16[11],RED,0);
 
 // Air quality
 LCD_ShowChineseFont(0,16*3,16,HZ_FONT_16[12],RED,0);
 LCD_ShowChineseFont(16,16*3,16,HZ_FONT_16[13],RED,0);
 LCD_ShowChineseFont(16*2,16*3,16,HZ_FONT_16[14],RED,0);
 LCD_ShowChineseFont(16*3,16*3,16,HZ_FONT_16[15],RED,0);
 
 // Intelligent lighting
 LCD_ShowChineseFont(0,16*4,16,HZ_FONT_16[16],RED,0);
 LCD_ShowChineseFont(16,16*4,16,HZ_FONT_16[17],RED,0);
 LCD_ShowChineseFont(16*2,16*4,16,HZ_FONT_16[18],RED,0);
 LCD_ShowChineseFont(16*3,16*4,16,HZ_FONT_16[19],RED,0);
 
 // Smart curtains
 LCD_ShowChineseFont(0,16*5,16,HZ_FONT_16[20],RED,0);
 LCD_ShowChineseFont(16,16*5,16,HZ_FONT_16[21],RED,0);
 LCD_ShowChineseFont(16*2,16*5,16,HZ_FONT_16[22],RED,0);
 LCD_ShowChineseFont(16*3,16*5,16,HZ_FONT_16[23],RED,0);
 
 while(1)
 {
 // Press the key to manually control the opening of curtains and LED The lamp
 key=KEY_Scan();
 if(key)printf(&quot;key=%d\r\n&quot;,key);
 
 // control LED The lamp
 if(key==2)
 {
 led_flag=!led_flag;
 if(led_flag)
 {
 LED_OUT=1;
 }
 else
 {
 LED_OUT=0;
 }
 } 
 
 // Control relay
 if(key==1)
 {
 motor_flag=!motor_flag; 
 if(motor_flag)
 {
 MOTOR_OUT=1;
 }
 else
 {
 MOTOR_OUT=0;
 }
 } 
 
 // Polling time arrives
 if(time_cnt>=100)
 {
 time_cnt=0;
 LED1=!LED1;
 
 // Read the light intensity
 BH1750_data=Read_BH1750_Data();
 printf(&quot; Ambient light intensity :%d\r\n&quot;,BH1750_data);
 
 // Obtain the ambient temperature and humidity
 if(DHT11_Read_Data(&DHT11_T,&DHT11_H))
 {
 printf(&quot; Temperature reading failed .\r\n&quot;);
 }
 printf(&quot; ambient temperature :%d\r\n ambient humidity :%d\r\n&quot;,DHT11_T,DHT11_H);
 
 // Obtain air quality
 MQ135_data=GetAdcCHxDATA(1);
 printf(&quot; Air quality :%d\r\n&quot;,MQ135_data);
 
 //LCD The screen displays the temperature and humidity in real time 、 Air quality , System working status, etc .
 
 // ambient temperature
 sprintf(data_buff,&quot;%d&quot;,DHT11_T);
 Gui_DrawFont_GBK16(72,16*0,RED,0,(u8*)data_buff);
 
 // ambient humidity
 sprintf(data_buff,&quot;%d&quot;,DHT11_H);
 Gui_DrawFont_GBK16(72,16*1,RED,0,(u8*)&quot; &quot;);
 Gui_DrawFont_GBK16(72,16*1,RED,0,(u8*)data_buff);
 
 // Ambient light intensity
 sprintf(data_buff,&quot;%d&quot;,BH1750_data);
 Gui_DrawFont_GBK16(72,16*2,RED,0,(u8*)&quot; &quot;);
 Gui_DrawFont_GBK16(72,16*2,RED,0,(u8*)data_buff);
 
 // Air quality
 sprintf(data_buff,&quot;%d&quot;,MQ135_data);
 Gui_DrawFont_GBK16(72,16*3,RED,0,(u8*)&quot; &quot;);
 Gui_DrawFont_GBK16(72,16*3,RED,0,(u8*)data_buff);
 
 // Intelligent lighting
 sprintf(data_buff,&quot;%d&quot;,led_flag);
 Gui_DrawFont_GBK16(72,16*4,RED,0,(u8*)&quot; &quot;);
 Gui_DrawFont_GBK16(72,16*4,RED,0,(u8*)data_buff);

 // Smart curtains
 sprintf(data_buff,&quot;%d&quot;,motor_flag);
 Gui_DrawFont_GBK16(72,16*5,RED,0,(u8*)&quot; &quot;);
 Gui_DrawFont_GBK16(72,16*5,RED,0,(u8*)data_buff);

 // Report data
 sprintf(data_buff,&quot;{\&quot;services\&quot;:{\&quot;BH1750\&quot;:[{\&quot;v\&quot;:%d}],\&quot;DHT11_H\&quot;:[{\&quot;v\&quot;:%d}],\&quot;DHT11_T\&quot;:[{\&quot;v\&quot;:%d}],\&quot;MQ135\&quot;:[{\&quot;v\&quot;:%d}],\&quot;motor\&quot;:[{\&quot;v\&quot;:%d}],\&quot;LED\&quot;:[{\&quot;v\&quot;:%d}]}}&quot;,
 BH1750_data,DHT11_H,DHT11_T,MQ135_data,motor_flag,led_flag);
 
 MQTT_PublishData(POST_TOPIC,data_buff,0);
 printf(&quot; Update data .\r\n&quot;);
 }
 
 //  receive WIFI Returned data
 if(USART2_RX_FLAG)
 {
 USART2_RX_BUFFER[USART2_RX_CNT]='\0';
 
 printf(&quot;WIFI Receive the data :\r\n&quot;);
 // The data returned to the serial port print server
 for(i=0;i<USART2_RX_CNT;i++)
 {
 printf(&quot;%c&quot;,USART2_RX_BUFFER[i]);
 }
 
 /*
 LED_ON  The smart light is on
 LED_OFF  The intelligent lamp is off
 MOTOR_ON  Smart curtains open
 MOTOR_OFF  Intelligent curtain closing
 */
 
 // If the attribute is distributed
 if(USART2_RX_CNT>5)
 {
 // Answer to the server
 if(strstr((char*)&USART2_RX_BUFFER[5],&quot;cmd/request/&quot;))
 { 
 char *p=NULL;
 p=strstr((char*)&USART2_RX_BUFFER[5],&quot;cmd/request/&quot;);
 if(p)
 { 
 // Parsing data
 strncpy(request_id,p+12,36); 
 }
 
 
 // Data reported to the server
 sprintf(mqtt_message,&quot;success&quot;);
 
 // Answer subject
 sprintf(data_buff,&quot;$sys/501579/dev1/cmd/response/%s&quot;,request_id);
 
 MQTT_PublishData(data_buff,mqtt_message,0);
 
 printf(&quot; Release theme :%s\r\n&quot;,data_buff);
 printf(&quot; Release data :%s\r\n&quot;,mqtt_message);
 }
 
 //LED:0 LED:1 MOTOR:0 MOTOR:1
 
 // turn on the light
 if(strstr((char*)&USART2_RX_BUFFER[5],&quot;LED:0&quot;))
 {
 LED_OUT=0;
 led_flag=0;
 }
 // Turn off the lights
 else if(strstr((char*)&USART2_RX_BUFFER[5],&quot;LED:1&quot;))
 {
 LED_OUT=1;
 led_flag=1;
 }
 // Open the curtains
 else if(strstr((char*)&USART2_RX_BUFFER[5],&quot;MOTOR:0&quot;))
 {
 MOTOR_OUT=0;
 motor_flag=0;
 }
 // Close the curtains
 else if(strstr((char*)&USART2_RX_BUFFER[5],&quot;MOTOR:1&quot;))
 {
 MOTOR_OUT=1;
 motor_flag=1;
 }
 }
 
 USART2_RX_CNT=0;
 USART2_RX_FLAG=0;
 }
 
 DelayMs(10);
 time_cnt++;
 timer_hour_cnt++;
 }
}

原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261603165367.html