NodeMCU is a firmware that allows you to program the ESP8266 modules with LUA script. And you’ll find it very similar to the way you program your Arduino. With just a few lines of code you can establish a WiFi connection, control the ESP8266 GPIOs, turning your ESP8266 into a web server and a lot more.
2. 原理图 (3.3V FTDI编程器)
RX -> TX
TX -> RX
CH_PD -> 3.3V
GPIO 0 -> GND
VCC -> 3.3V
GND -> GND
3. 下载NodeMCU Flasher软件
After wiring your circuit, you have to download the NodeMCU flasher. It's a .exe file that you can download using one of the following links:
You can click here to find all the information about NodeMCU flasher.
Open the flasher that you just downloaded and a window should appear (as shown in the following figure).
Press the button “Flash” and it should start the flashing process immediately (You might have to change some of the settings on the Advanced tab). After finishing this process, it should appear a green circle with a check icon.
Now follow the schematics bellow to create your web server to control two LEDs.
I recommend using the ESPlorer program created by 4refr0nt to create and save LUA files into your ESP8266. Follow these instructions to download and install ESPlorer:
Click here to download ESPlorer下载ESPlorer软件
Unzip that folder
Go to the dist folder (here's the path: ESPlorer-master\ESPlorer\dist)
Run ESPlorer.jar. It's a JAVA program, so you need JAVA installed on your computer.
Open the ESPlorer
You should see a window similar to the preceding Figure, follow these instructions to upload a LUA file:
Connect your FTDI programmer to your computer
Select your FTDI programmer port
Select NodeMCU+MicroPtyhon tab
Create a new file called init.lua
Press Save to ESP
Everything that you need to worry about or change is highlighted in red box.
Upload the following code into your ESP8266 using the preceding software. Your file should be named “init.lua". 点击下载文件
Don't forget to replace your WiFi Station details in that code above (Network Name and Password).
When your ESP8266 restarts it prints in your serial monitor the IP address of your ESP8266. If you type your ESP8266 IP address in your web browser, you can access your web server. In my case it's http://192.168.1.95.
9. 延伸 编写安卓APP访问8266服务器
在App Inventor中创建安卓APP（国内直接访问：http://app.gzjkw.net，有不明白的就加qq群交流吧 214461008）
MIT App Inventor is a drag-and-drop software that allows you to create a basic, but fully functional Android app within an hour or less.
Here’s how to edit the ESP8266 Controller app:
Click here to download .zip folder that contains .aia file
Unzip the folder
Go to MIT App Inventor
Click the “Create Apps” button on the top right corner
Go to the “Projects” tab and select “Import project (.aia)”
After importing the .aia file, you'll be able to edit the app and see how the app was built.
The designer tab is where you can edit how the app looks. Feel free to change the text, change the colors, add buttons or add more features.
The blocks section is where you can add what each button does and add logic to your app.
After finishing editing the app you can click the “Build” app tab and install the .apk file in your Android. I personally recommend that you first upload the app provided below to ensure that everything works as expected (later you can edit the app).
Follow these instructions to install the default app that I've created:
Click here to download .zip folder that contains the .apk file 由于国内网络的限制，访问谷歌需要特殊方式，你懂的
Unzip the folder
Move the .apk file to your Android phone
Run the .apk file to install the app
Here’s how the ESP8266 Controller app looks when you to open it.
It's very easy to configure. Click the button“Set IP Address” on the bottom of the screen and type your IP address (in my case 192.168.1.95).
Now you can turn the GPIOs high and low with your smartphone.
This is a basic example that shows you how easy it is to integrate an Android app with the ESP8266. You can take this example and modify it.
You could add multiple screens to the app, so you can other ESPs or add buttons to control more GPIOs.