当前位置:网站首页>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 --- GND
Step 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 daily question (1362. closest divisors)
- Flink学习笔记(九)状态编程
- Leetcode daily question (2232. minimize result by addressing parents to expression)
- Directory and switching operation in file system
- [kotlin learning] operator overloading and other conventions -- overloading the conventions of arithmetic operators, comparison operators, sets and intervals
- Go language - JSON processing
- [solution to the new version of Flink without bat startup file]
- Implementing distributed lock with redis
- Make the most basic root file system of Jetson nano and mount NFS file system on the server
- Jestson nano downloads updated kernel and DTB from TFTP server
猜你喜欢
图像修复方法研究综述----论文笔记
[set theory] order relation (chain | anti chain | chain and anti chain example | chain and anti chain theorem | chain and anti chain inference | good order relation)
CATIA automation object architecture - detailed explanation of application objects (I) document/settingcontrollers
一款开源的Markdown转富文本编辑器的实现原理剖析
Leetcode daily question (931. minimum falling path sum)
【Kotlin疑惑】在Kotlin类中重载一个算术运算符,并把该运算符声明为扩展函数会发生什么?
【Kotlin学习】高阶函数的控制流——lambda的返回语句和匿名函数
LeetCode每日一题(931. Minimum Falling Path Sum)
LeetCode每日一题(1162. As Far from Land as Possible)
Vscode Arduino installation Library
随机推荐
[CSDN] C1 training problem analysis_ Part III_ JS Foundation
[set theory] order relation (eight special elements in partial order relation | ① maximum element | ② minimum element | ③ maximum element | ④ minimum element | ⑤ upper bound | ⑥ lower bound | ⑦ minimu
Windows安装Redis详细步骤
Analysis of the implementation principle of an open source markdown to rich text editor
Quickly use markdown to edit articles
Common software open source protocols
Solve the problem of disordered code in vscode development, output Chinese and open source code
Hudi learning notes (III) analysis of core concepts
Detailed steps of windows installation redis
[kotlin learning] control flow of higher-order functions -- lambda return statements and anonymous functions
Filter comments to filter out uncommented and default values
Leetcode daily question (516. long palindromic subsequence)
Crawler career from scratch (I): crawl the photos of my little sister ① (the website has been disabled)
小王叔叔的博客目录【持续更新中】
CATIA automation object architecture - detailed explanation of application objects (III) systemservice
LeetCode每日一题(2212. Maximum Points in an Archery Competition)
IDEA 中使用 Hudi
Starting from 0, use pnpm to build a demo managed by monorepo
Django operates Excel files through openpyxl to import data into the database in batches.
Go language - IO project