The functions implemented:led_1and theled_2can be used simultaneouslyAPPand theKEY1and theKEY2button (short press) controlsuitable for entry-level Meng Xin, big guy please skip, thank you!
Features: Led_1 and led_2 can be controlled simultaneously with app and KEY1 and KEY2 keys (Short press)
First, the hardware circuit and the development environment construction
1. Hardware circuit
First is from a treasure purchase WiFi module ESP8266 NODEMCU, I bought this, 4 m memory is not able to connect the antenna, should be 13.5 yuan mail. Now has been used, the feeling is still relatively stable, the kind of the antenna can be connected to small memory is not used to know how. Other components, there are two LEDs, two Microswitch, Breadboard, DuPont Line several, 5v DC power supply.
There is a situation to explain that the WiFi module has two, a normal operation of the upper right-hand corner of the blue led does not blink, only when the power is flashing, and the other is normal operation and power-up will flash. I bought two pieces, just to meet the two cases, began to think is bad, haha.
(1) Circuit diagram
(2) Circuit physical diagram
2. Building the development environment
If you are a Windows 64-bit operating system, you can download the following integrated development environment
Link: Https://pan.baidu.com/s/1CdruAWopdVWMEzxKOEJ4uA Extraction code: 12CT
If not, can be in Baidu "Le Xin Integrated Development Environment", should be easy to find.
Download good after pressure to a place you like, I used to press on the D-plate, after the pressure is good. The desktop also appears with the Aithinker_ide and configtool two shortcut icons.
Open this aithinkeride_v0.5 folder, the blue box inside EXE file corresponding to the two icons on the desktop
Open the blue box where the configtool.exe,1,2 path corresponds to the contents of the red box. If your computer has already installed Eclipse, you can choose the path to the installation of Eclipse. Then click on Register 3, then click Save 4, the window will automatically exit. The development environment is well-configured.
You can enter the development environment by clicking on the Aithinker_ide.exe in the blue box or by clicking the shortcut icon on the desktop.
Second, the Smart Cloud Developer Center
Next is the action on the Smart Cloud Developer Center. Registering an account should be a basic operation and will not be time-consuming to write. It mainly focuses on data points and automatically generated programs and downloads test apps. Enter the developer Center
- Create a product
- Product Classification: Self-determined, small impact;
Product Name: Self-determined, small impact;
Technical solution: wi-fi/mobile network solution;
Mode of communication: Wi-Fi
Data transmission method: fixed length
3. After the product is created
4. Open the Created product
5. Click Show Full key, enter the login password product secret will be fully displayed, copy the black hidden product key and the displayed product secret into a notepad, which will be useful later.
6. Click on the left data point to create a data point. I created a good data point as follows
The following two data points do not need to create, I intend to use DHT11 temperature and humidity sensor to obtain temperature temperature and humidity humidity, may be the module is broken, has not read the value, so here does not introduce.
I use two writable Boolean data points, Led_1 and led_2, to control the LEDs ' switches. (The conditional can buy relays, through the control relay to control the home of the 220v lamp or socket switch.) Nonsense, haha).
Tips: The identity name can be customized, but it is better to be easy to understand, create a good post-point application.
7. Point left MCU development, select right SOC scheme
Paste on the copy in Notepad in the product Secret, click on the Production code package, generate well, click Download
8. Download the test app and click on the top Download Center
After entering the Download center, click on the left "smart Cloud wi-fi/Mobile communication product debugging App"
Optional scan code to download, installed on the phone for later use.
Third, modify the automatically generated code, compile and burn
1. Modify the Code
Press the 7th step to download the compression package to the desktop (location customization, according to personal habits), open the development environment software, that is, this
That's it when it opens.
And then the code package that imports the pressure.
Click File in the upper-left corner, then import
Click c + +, and then click Existing Code as Makefile Project
At number 1, select the location where the code is pressed, and the number 2 selects the 3rd
When you are finished, expand the folder and double-click the file in the red box on the left to modify it according to the Red box content on the right.
About the 22nd line: Change boot?=new, change app?=1, if only two data points to change spi_size_map?=2.
If you expand a folder, you want to modify the following 5 files in the red box
First open gizwits_product.h, define a matrix extern bool Sta[2], to store the state of the data points led_1 and led_2.
Then open gizwits_product.c, initialize the defined matrix bool sta[2]={0};
Find int8_t icache_flash_attr gizwitseventprocess (eventinfo_t *info, uint8_t *data, uint32_t len) about 47 lines, The name of the data point defined in the black box for the wit cloud, and the content added in red light.
Tips: This board is not the same as our common board (51, STM32), its IO port 1 o'clock, the actual output low level.
Our LED is a common-Yang machine connection method, see the circuit diagram.
Then the state of the scan data points led_1 and led_2, and escalate, add two codes in the Red box
#define USER_TIME_MS 100
#define LED_TIMEOUT (100/user_time_ms) definition 100ms
These two are added to the user_main.c to avoid errors when compiling
In addition, the GIZWITS_PROTOCOL.C is changed
#define USER_TIME_MS 100 to reduce control delay
find void Icache_flash_attr userhandle (void) in gizwits_protocol.c, this escalation procedure
Add the following code
Gpio_output_set (Gpio_id_pin (4),! Sta[0]);
Gpio_output_set (Gpio_id_pin (5),! STA[1]);
Static uint8_t ledtime=0; Data point status reported every 100ms
ledtime++;
if (led_timeout<ledtime)
{
ledtime=0;
CURRENTDATAPOINT.VALUELED_1=STA[0];
CURRENTDATAPOINT.VALUELED_2=STA[1];
}
Locate the following void Icache_flash_attr userInit (void), which is the data point initialization
Modify the following
currentdatapoint.valueled_1 = 0;
currentdatapoint.valueled_2 = 0;
Then change the user_main.c file and find the approximate 55th line.
Modify as follows
#define GPIO_KEY_NUM 2//define the total number of keys
#define KEY_0_IO_MUX Periphs_io_mux_gpio0_u//
#define KEY_0_IO_NUM 0
#define KEY_0_IO_FUNC Func_gpio0
#define KEY_1_IO_MUX Periphs_io_mux_gpio2_u
#define KEY_1_IO_NUM 2
#define KEY_1_IO_FUNC Func_gpio2
Next, change the KEY1, which is the GPIO0 corresponding switch.
LOCAL void icache_flash_attr key1shortpress (void)//key1 Short Press
{
if (sta[0]=! STA[0])//reverse, determine whether the switch is pressed
Gizwits_log ("# # GPIO0 Short Press, Led_1 on\n"); Log Elsegizwits_log ("# # GPIO0 Short Press, Led_1 off\n"); Log
}
/**
- Key1 key presses a long press
- @param None
- @return None
*/
LOCAL void icache_flash_attr key1longpress (void)//key1 long Press
{
Gizwits_log ("# # GPIO0 Long Press, SOFTAP on\n"); Log
Gizwitssetmode (Wifi_softap_mode); Set to LAN mode
Next, change the KEY2, which is the GPIO2 corresponding switch.
LOCAL void icache_flash_attr key2shortpress (void)//key2 Short Press
{
if (sta[1]=! STA[1])//reverse, determine whether the switch is pressed
Gizwits_log ("# # GPIO2 Short Press, led_2 on \ n"); Log
Elsegizwits_log ("# # GPIO2 Short Press, led_2 OFF \ n"); Log
}
/**
- Key2 Button Long Press
- @param None
- @return None
*/
LOCAL void icache_flash_attr key2longpress (void)//key2 long Press
{
Gizwits_log ("# # GPIO2 Long Press, Airlink on\n"); Log
Gizwitssetmode (Wifi_airlink_mode); Set to Networking mode
}
}
Port initialization
LOCAL void icache_flash_attr keyinit (void)
{
Singlekey[0] = Keyinitone (Key_0_io_num, Key_0_io_mux, Key_0_io_func,
Key1longpress, key1shortpress);
SINGLEKEY[1] = Keyinitone (Key_1_io_num, Key_1_io_mux, Key_1_io_func,
Key2longpress, key2shortpress);
Keys.singlekey = Singlekey;
Keyparainit (&keys);
Pin_func_select (Periphs_io_mux_gpio4_u,func_gpio4);//configuration led_1 PIN for output
Gpio_dis_output (Gpio_id_pin (4));
Pin_func_select (PERIPHS_IO_MUX_GPIO5_U,FUNC_GPIO5);//configuration led_2 PIN for output
Gpio_dis_output (Gpio_id_pin (5));
Gpio_output_set (Gpio_id_pin (4), 0);//output High level
Gpio_output_set (Gpio_id_pin (5), 0);//output High level
}
All the code has been modified, start compiling, right-click the project name, click Build Projects
Compilation succeeded
Burn, burn tool can download me this
Links: https://pan.baidu.com/s/1_Bhds-uE9GreQpfVwJ2m7g
Extract code: E0KR
After downloading, open Espflashdownloadtool_v3.6.4.exe this program and click the first one.
Select the compiled file, path, COM for reference only, according to the actual situation set. The following settings are as follows
C:\Users\Administrator\Desktop\SoC_ESP8266_32M_source\bin\boot_v1.6.bin
0x00000
C:\Users\Administrator\Desktop\SoC_ESP8266_32M_source\bin\upgrade\user1.4096.new.4.bin
0x01000
C:\Users\Administrator\Desktop\SoC_ESP8266_32M_source\bin\esp_init_data_default.bin
0x3fc000
C:\Users\Administrator\Desktop\SoC_ESP8266_32M_source\bin\blank.bin
0x3fe000
Finally finished hardware and software, finally to see the results of the time, is not very excited.
There is one step not finished, distribution network.
First of all, your phone will be connected to your home WiFi.
Open the downloadable smart Cloud mobile app, click Skip, don't log in
Click on the + sign in the top right corner and click on one button to configure
Fill in your home WiFi account and password
Select Espressif, click OK
Chang ' an KEY2 key, 3S above release, click on the phone "I have done the above"
Distribution Network Success
Led_1 and led_2 can be controlled with both the app and the KEY1 and KEY2 keys (short press).
Wish you success!!!
That's all, thanks for your reading.
Write a bit more, big guy please skip ...
Not to be continued ...
ESP8266 NODEMCU Smart Cloud SOC solution development experience sharing