当前位置:网站首页>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
边栏推荐
- 文件系统中的目录与切换操作
- 【Kotlin学习】高阶函数的控制流——lambda的返回语句和匿名函数
- Desktop icon recognition based on OpenCV
- Equality judgment of long type
- IDEA 中使用 Hudi
- Flink学习笔记(八)多流转换
- PolyWorks script development learning notes (I) - script development environment
- The rise and fall of mobile phones in my perspective these 10 years
- Leetcode daily question (2212. maximum points in an archery competition)
- LeetCode每日一题(2115. Find All Possible Recipes from Given Supplies)
猜你喜欢

Spark 集群安装与部署

【Kotlin学习】高阶函数的控制流——lambda的返回语句和匿名函数

Spark cluster installation and deployment

LeetCode每日一题(2090. K Radius Subarray Averages)

Win10 install elk
![[kotlin learning] operator overloading and other conventions -- overloading the conventions of arithmetic operators, comparison operators, sets and intervals](/img/8d/938e232c1016cabe9ee0f72be87a22.png)
[kotlin learning] operator overloading and other conventions -- overloading the conventions of arithmetic operators, comparison operators, sets and intervals

Leetcode daily question (2212. maximum points in an archery competition)

Global KYC service provider advance AI in vivo detection products have passed ISO international safety certification, and the product capability has reached a new level
![[kotlin learning] control flow of higher-order functions -- lambda return statements and anonymous functions](/img/a3/b442508af9b059d279cffb34dee9bf.png)
[kotlin learning] control flow of higher-order functions -- lambda return statements and anonymous functions

LeetCode每日一题(2212. Maximum Points in an Archery Competition)
随机推荐
DSP data calculation error
The number of weak characters in the game (1996)
Uncle Wang's blog directory [constantly updating]
[set theory] order relation (eight special elements in partial order relation | ① maximum element | ② minimum element | ③ maximum element | ④ minimum element | ⑤ upper bound | ⑥ lower bound | ⑦ minimu
Django operates Excel files through openpyxl to import data into the database in batches.
Common formulas of probability theory
Hudi quick experience (including detailed operation steps and screenshots)
WARNING: You are using pip version 21.3.1; however, version 22.0.3 is available. Prompt to upgrade pip
Detailed steps of windows installation redis
Crawler career from scratch (3): crawl the photos of my little sister ③ (the website has been disabled)
Apply for domain name binding IP to open port 80 record
Call the contents of Excel cells opened at the same time - button line feed
Idea uses the MVN command to package and report an error, which is not available
Run flash demo on ECS
PolyWorks script development learning notes (I) - script development environment
Flink学习笔记(十一)Table API 和 SQL
Matlab dichotomy to find the optimal solution
Principles of computer composition - cache, connection mapping, learning experience
Esp32 at command does not respond
Usage of pandas to obtain MySQL data