当前位置:网站首页>Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 2 --blinker_ Hello_ WiFi (lighting technology - Mobile App control routine)
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 2 --blinker_ Hello_ WiFi (lighting technology - Mobile App control routine)
2022-07-03 09:29:00 【Taodream】
First, build the development environment :https://blog.csdn.net/felix_tao/article/details/113092886
Secondly, complete the establishment of the project template :https://blog.csdn.net/felix_tao/article/details/113282760
First step : A copy of template engineering , And rename to Blinker_Hello_WiFi.
The second step : open VSCODE-> file -> Add folder to workspace -> Select the project folder Blinker_Hello_WiFi-> Add to VSCODE in .
The third step : Download lighting technology blinker Arduino library , And copy it to platformio arduino esp8266 Under the Library Directory of .
1) Open the url https://www.diandeng.tech/doc/getting-start-8266, find “ Download and install blinker Arduino library ”, Click download .
2) decompression blinker-library-master.zip after , Copy blinker-library-master To directory C:\Users\felix\.platformio\packages\framework-arduinoespressif8266\libraries Next .
Step four : Copy Hello_WiFi The code in the routine goes to VSCODE Medium src->main.cpp Inside .
1) Open Directory C:\Users\felix\.platformio\packages\framework-arduinoespressif8266\libraries\blinker-library-master\examples\Blinker_Hello\Hello_WiFi.
2) use NotePad++ open Hello_WiFi.ino, Copy the code inside to src->main.cpp Inside ( All the original codes are deleted ).
3) Discovery tips #include <Blinker.h> Not included , close VSCODE, Open it again , I found that just now “ Prompt not included ” Vanished , This is because reopening VSCODE after , In the project .vscode->c_cpp_properties.json It automatically loads the header file containing , namely "C:/Users/felix/.platformio/packages/framework-arduinoespressif8266/libraries/blinker-library-master/src".
4) So you can adjust the order of the above steps , First copy the library file blinker-library-master, Reuse VSCODE Open the project , There is no need to close VSCODE Reopen , No matter what , remember :.vscode->c_cpp_properties.json There is no need to make any changes to the documents inside , The software will automatically help us complete the addition of header files .
5)Hello_WiFi The routine code is as follows :
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "Your Device Secret Key";
char ssid[] = "Your WiFi network SSID or name";
char pswd[] = "Your WiFi network WPA password or WEP key";
// New component object
BlinkerButton Button1("btn-abc");
BlinkerNumber Number1("num-abc");
int counter = 0;
// Press the key to execute the function
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
// If unbound components are triggered , Then the content will be executed
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
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, HIGH);
// initialization blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
}
void loop() {
Blinker.run();
}
Step five : stay app Add devices to , obtain Secret Key.
1) download APP And install , Open the url https://www.diandeng.tech/doc/getting-start-8266, find “ Download and install blinker APP“, According to different mobile platforms , Download the corresponding APP And install .
2) Get into App, Click on the “+” Number , And then choose Add equipment .
3) Click Select Arduino( Independent equipment )-> WiFi Access .
4) Select the service provider you want to access ( Alibaba cloud 、 Lighting technology 、 Tencent cloud 、OneNet), Choose here ” Alibaba cloud “, It's mainly to connect with Xiao AI in the future ,“ Lighting technology ” I don't support Xiao AI .
5) Copy the application to Secret Key Go to the key column in the code .
Step six : Modify the following code .
1) 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
2) Modifying initialization LED Default level .
//digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(LED_BUILTIN, LOW);// Default on LED
3) The modified and sorted code is as follows :
/* *****************************************************************
* Program function :
* 1. Use the development board :nodemcu-ESP8266( modular ESP-12E)
* 2. Program function : Use Blinker mobile phone APP Add devices and bind , adopt APP Remote control the light on the development board
* 3. Routine documentation :https://www.diandeng.tech/doc/getting-start-8266
* *****************************************************************/
//#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
char auth[] = "a3c936aa1b16";//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-abc");// Component object , Want to be with APP In the component “ Data key name ” Agreement
BlinkerNumber Number1("num-abc");
int counter = 0;// Counter
// 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
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));// control LED The light is on and off , Low level light , High level off
}
// If unbound components are triggered , Then the content will be executed
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
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, HIGH);
digitalWrite(LED_BUILTIN, LOW);// Default on LED
// initialization blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);// Bind key callback
}
void loop() {
Blinker.run();
}
Step seven : After modification , 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 .
Step eight : Using mobile phone APP Carry out remote control in the development board LED The lamp .
1) open APP, Due to unpaid , So I entered APP The interface is DIY Interface .
2) On the device list page , Click on the device icon , Enter the device control panel .
3) Enter the device control panel for the first time , The wizard page will pop up .
4) On the wizard page, click Load examples , You can load the sample assembly .
5) Make sure the device is online , And then click ” Light me on ” You can control LED Light on and off .
6) because “ Let me count ” Unbound in code , So it triggers dataRead() function .
thus , All processes are completed , Have fun !
Complete engineering documents :https://download.csdn.net/download/felix_tao/14975814
Reference documents :
1. Lighting technology :https://www.diandeng.tech/doc/getting-start-8266
边栏推荐
- Send mail using WP mail SMTP plug-in
- PowerDesigner does not display table fields, only displays table names and references, which can be modified synchronously
- Flink学习笔记(十)Flink容错机制
- Hudi data management and storage overview
- [point cloud processing paper crazy reading classic version 9] - pointwise revolutionary neural networks
- 解决Editor.md上传图片获取不到图片地址问题
- Crawler career from scratch (I): crawl the photos of my little sister ① (the website has been disabled)
- Liteide is easy to use
- 1922. Count Good Numbers
- Word segmentation in full-text indexing
猜你喜欢
[point cloud processing paper crazy reading frontier edition 13] - gapnet: graph attention based point neural network for exploring local feature
[point cloud processing paper crazy reading classic version 8] - o-cnn: octree based revolutionary neural networks for 3D shape analysis
Beego learning - Tencent cloud upload pictures
【毕业季|进击的技术er】又到一年毕业季,一毕业就转行,从动物科学到程序员,10年程序员有话说
PolyWorks script development learning notes (II) -treeview basic operations
IDEA 中使用 Hudi
图像修复方法研究综述----论文笔记
Liteide is easy to use
The rise and fall of mobile phones in my perspective these 10 years
[point cloud processing paper crazy reading classic version 10] - pointcnn: revolution on x-transformed points
随机推荐
LeetCode每日一题(1856. Maximum Subarray Min-Product)
【Kotlin学习】高阶函数的控制流——lambda的返回语句和匿名函数
Flink学习笔记(十)Flink容错机制
Install third-party libraries such as Jieba under Anaconda pytorch
用Redis实现分布式锁
Crawler career from scratch (V): detailed explanation of re regular expression
LeetCode每日一题(968. Binary Tree Cameras)
Modify idea code
Jenkins learning (III) -- setting scheduled tasks
[kotlin puzzle] what happens if you overload an arithmetic operator in the kotlin class and declare the operator as an extension function?
Temper cattle ranking problem
Usage of pandas to obtain MySQL data
LeetCode每日一题(2305. Fair Distribution of Cookies)
LeetCode每日一题(1300. Sum of Mutated Array Closest to Target)
Hudi 集成 Spark 数据分析示例(含代码流程与测试结果)
Go language - JSON processing
LeetCode每日一题(2090. K Radius Subarray Averages)
Alibaba cloud notes for the first time
On February 14, 2022, learn the imitation Niuke project - develop the registration function
Filter comments to filter out uncommented and default values