当前位置:网站首页>Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 4 --blinker_ DHT_ WiFi (lighting technology app control + temperature and humidity data app display)
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 4 --blinker_ DHT_ WiFi (lighting technology app control + temperature and humidity data app display)
2022-07-03 09:35:00 【Taodream】
First, build the development environment :https://blog.csdn.net/felix_tao/article/details/113092886
Second, finish Blinker_Hello_WiFi( Lighting technology - mobile phone APP Control routine ):https://blog.csdn.net/felix_tao/article/details/113359707
First step : download DHT11/22 Temperature and humidity sensor Library -DHT-sensor-library-master.
Download address :https://www.arduino.cn/thread-81585-1-1.html
The second step : After downloading , take DHT-sensor-library-master.zip unpack , Put it under this path C:\Users\felix\.platformio\packages\framework-arduinoespressif8266\libraries.

The third step : A copy of Blinker_Hello_WiFi engineering , And rename to Blinker_DHT_WiF.
Step four : open VSCODE-> file -> Add folder to workspace -> Select the project folder Blinker_DHT_WiF-> Add to VSCODE in .
In the open VSCODE In the process , It will load automatically PIO plug-in unit , as well as .vscode->c_cpp_properties.json Will automatically load DHT-sensor-library-master Inclusion path .
Step five : Copy the following code to VSCODE Medium src->main.cpp Inside .
/* *****************************************************************
* @author TaoDream
* @version V1.0
* @date 2021.01.31
* Program function :
* 1. Use the development board :nodemcu-ESP8266( modular ESP-12E)
* 2. Using sensors :DHT11 modular ( Data pins DAT Received from the development board D7,VCC Received from the development board 3V3,GND Received from the development board GND)
* 3. Program function : Use Blinker mobile phone APP Add devices and bind , adopt APP Remote control the light on the development board , And read DHTXX The temperature and humidity value of the sensor is APP Displayed on the
* 4. Routine documentation :https://www.diandeng.tech/doc/arduino-course, choice “2. Data feedback ”
* *****************************************************************/
//#define LED_BUILTIN 2 //ESP-12E The module itself LED, Corresponding GPIO2, Low level light
//#define LED_BUILTIN 16 //nodemcu-esp8266 The development board extends LED, Corresponding GPIO16, Low level light
#define BLINKER_WIFI
#define BLINKER_WITHOUT_SSL //blinker By default, encryption is used for remote communication , But communication encryption will consume a lot of RAM, If you have no requirements for communication security ,
// You can add macros BLINKER_WITHOUT_SSL To get more available RAM,BLINKER_WITHOUT_SSL At present, it can only be used for ESP8266, Other devices RAM Enough for encrypted communication
#include <Blinker.h> // Using third party libraries
#include <DHT.h> // Using third party libraries
char auth[] = "aabfdfc3b167";//Blinker APP Obtained in Secret Key( secret key )
char ssid[] = "Xiaomi_123"; //wifi name
char pswd[] = "felix1234"; //wifi password
// New component object
BlinkerButton Button1("btn-key");// Component object , Want to be with APP In the component “ Data key name ” Agreement
/// Read DHTXX Sensor related definitions and variables //
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");
#define DHTPIN D7 // Define the data pins transmitted by the single bus protocol
// Sensor type selection
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
float humi_read = 0, temp_read = 0;
///
// Heartbeat package function
void heartbeat()
{
// The temperature and humidity data collected at the device end , Synchronize data through heartbeat packets , According to the APP On
HUMI.print(humi_read);
TEMP.print(temp_read);
}
// Press the key to execute the function
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);//APP Medium Monitor Control print information
if (state=="on")
{
digitalWrite(LED_BUILTIN, LOW);// open LED The lamp
// Feedback switch status
Button1.print("on");
} else if(state=="off"){
digitalWrite(LED_BUILTIN, HIGH);// close LED The lamp
// Feedback switch status
Button1.print("off");
}
}
void setup()
{
// Initialize serial port
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
// Initialization has LED Of IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);// Default on LED
// initialization blinker
Blinker.begin(auth, ssid, pswd);
Button1.attach(button1_callback);// Bind key callback
// Register a heartbeat package
Blinker.attachHeartbeat(heartbeat);
dht.begin();//DTHXX Sensor initialization
}
void loop()
{
Blinker.run();
float h = dht.readHumidity();// Read the humidity value
float t = dht.readTemperature();// Read temperature value
// If there is no DHTXX sensor , Then use the following data to debug
// h = 60.1;// Debugging with , Simulated humidity value
// t = 25.2;// Debugging with , Analog temperature value
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;
}
// It should be noted that :blinker All delay operations under , You need to use Blinker.delay(val); replace , Otherwise, the device will be disconnected
Blinker.delay(2000);
}Step six : Modify the following code .
Modify the key 、wifi name 、wifi The password is your own .
char auth[] = "Your Device Secret Key";//Blinker APP Obtained in Secret Key( secret key )
char ssid[] = "Your WiFi network SSID or name";//wifi name
char pswd[] = "Your WiFi network WPA password or WEP key";//wifi password Step seven : take DHT11 Module and ESP8266 Connect to the development board .
DHT11 --- ESP8266
DAT --- D7
VCC --- 3V3
GND --- GNDStep eight : Compile 、 download , During the compilation process, we found that “ Yellow warning ”, Don't mind , The final compilation is “SUCCESS” Just OK.
After downloading successfully , You can see the LED It lights up , open VSCODE The serial monitor can see and print some information , When you see “MQTT Connected!” Then prove the connection wifi Was a success , When you see "state":"online" The device is online .
If there is a connection DHT11 or DHT22 modular , You can see the print humidity 、 temperature .
VSCODE Information printed by the serial monitor :
......
[11393129] Humidity: 93.00 %
[11393130] Temperature: 19.50 *C
[11395181] Humidity: 93.00 %
[11395181] Temperature: 19.50 *C
[11397230] Humidity: 93.00 %If there's no answer , It will say that the connection of the sensor failed , It doesn't matter if you don't answer , Just give a fixed value , Because our main purpose is to debug data in APP Displayed on the .
[18161] Failed to read from DHT sensor!
[20260] Failed to read from DHT sensor!
[22370] Failed to read from DHT sensor!
[24475] Failed to read from DHT sensor!Step nine :APP Add components to the interface , Perform key on control and display humidity 、 Temperature value .
1) add to “ Switch button ” Components .
Click on the “ Edit icon ”, Enter editing status , Delete all the original APP Components in , Click on “ Key icon ”, Then go to edit .

2) Add humidity 、 Temperature component .
Click on “ Data icon ”, Then go to edit .

3) Add debug components .
Click on “ Debug Icon ”, Then go to edit .

4) The final interface is shown in the figure below , Press... In the upper right corner “ Lock icon ” Preservation .

5) The saved interface is shown in the following figure , Press the open key to control the switch board LED The light is on and off , At the same time, humidity 、 The temperature component displays data normally .

thus , All operations complete .
Complete engineering documents :https://download.csdn.net/download/felix_tao/14978839
Reference documents :
Lighting technology :https://www.arduino.cn/thread-83176-1-1.html
边栏推荐
- LeetCode每日一题(985. Sum of Even Numbers After Queries)
- Find all possible recipes from given supplies
- 全球KYC服务商ADVANCE.AI 活体检测产品通过ISO国际安全认证 产品能力再上一新台阶
- Flink学习笔记(八)多流转换
- Beego learning - Tencent cloud upload pictures
- The server denied password root remote connection access
- [kotlin learning] operator overloading and other conventions -- overloading the conventions of arithmetic operators, comparison operators, sets and intervals
- Logstash+jdbc data synchronization +head display problems
- Please tell me how to set vscode
- 专利查询网站
猜你喜欢

Beego learning - Tencent cloud upload pictures

Spark overview

Learning C language from scratch -- installation and configuration of 01 MinGW

Principles of computer composition - cache, connection mapping, learning experience

Hudi 快速体验使用(含操作详细步骤及截图)

IDEA 中使用 Hudi

Utilisation de hudi dans idea

Windows安装Redis详细步骤
![[kotlin learning] classes, objects and interfaces - classes with non default construction methods or attributes, data classes and class delegates, object keywords](/img/ee/d982fd9e1f2283e09ad1a81d0b61b5.png)
[kotlin learning] classes, objects and interfaces - classes with non default construction methods or attributes, data classes and class delegates, object keywords

Vscode编辑器右键没有Open In Default Browser选项
随机推荐
WARNING: You are using pip ; however. Later, upgrade PIP failed, modulenotfounderror: no module named 'pip‘
Flask+supervisor installation realizes background process resident
About the configuration of vs2008+rade CATIA v5r22
LeetCode每日一题(1300. Sum of Mutated Array Closest to Target)
IDEA 中使用 Hudi
Esp32 at command does not respond
Jestson Nano自定义根文件系统创建(支持NVIDIA图形库的最小根文件系统)
WARNING: You are using pip version 21.3.1; however, version 22.0.3 is available. Prompt to upgrade pip
Hudi 集成 Spark 数据分析示例(含代码流程与测试结果)
Django operates Excel files through openpyxl to import data into the database in batches.
Go language - IO project
Flink学习笔记(十)Flink容错机制
Hudi学习笔记(三) 核心概念剖析
Using Hudi in idea
Idea uses the MVN command to package and report an error, which is not available
Spark cluster installation and deployment
Construction and test of TFTP server under unbuntu (Debian)
Failed building wheel for argon2 cffi when installing Jupiter
Win10 quick screenshot
[CSDN] C1 training problem analysis_ Part III_ JS Foundation