This post was last edited by ylyfxzsx on 2020-2-16 13:02
I have studied ESP8266 for two days and recorded the process. I hope this post can be used as a teaching post for novices, so that you can get started quickly even if you have no programming foundation.
Many ESP8266s on the Internet are flashed with AT firmware, which uses AT commands to exchange information with the MCU. I think the load on the MCU is too heavy, and flashing the Node MCU firmware can completely free the MCU.
My idea is that MCU only needs to receive the serial port information sent by ESP8266, intercept the text, and display it. The pressure on MCU is small. Okay, let's stop talking nonsense and start the topic.
First you need an ESP8266 module. Mine looks like this
Next, customize the firmware, https://nodemcu-build.com/
Then you will receive the compiled firmware from the website in a while. The difference between float and integer is that it supports floating point numbers.
Then connect the node mcu ESP8266 module and open the ESP8266 firmware download tool flash_download_tools_v3.6.5
After the upgrade is completed, reset the module and you can see the serial port output information
The LUA version 5.1.4 SDK3.0.1 firmware website provides various API function interfaces, which are very detailed and can be used after a brief reading.
https://github.com/nodemcu/nodemcu-firmware/tree/master/docs/modules
OK, let's start LUA programming. First, download an Esplorer and then connect the module. Because we haven't written the application file yet, it will prompt
"lua: cannot open init.lua"
Then write the simplest LUA command to control GPIO to light up the LED, click Send to ESP to see the effect
Click Save to ESP to download into the ESP8266 internal module
At this point, the framework is set up. As for the syntax and programming of NodeMcu LUA, please read the API function document I gave above. I will not go into details. What should we do now? Find a service provider who provides weather interface functions for us to call. I use Xinzhi Weather here.
https://www.seniverse.com/
Register an account, then we can use the free one, and we will get a key
Http weather url of Xinzhi Weather
https://api.thinkpage.cn/v3/weather/now.json?key= &location= &language=en
Add -Hans&unit=c to display Chinese text
We use https://api.thinkpage.cn/v3/weather/now.json?key=&location=&language=en
That's it. In the above URL, fill in the key you applied for after key = and location= after your own city pinyin.
After entering, you can test it in the browser first:
For example: https://api.thinkpage.cn/v3/weather/now.json?key=24qbvr1mjsnukavo&location=beijing&language=en
If nothing goes wrong, the browser returns a string of weather information, as shown below. Some prefecture-level cities may not have data, so you can replace the location= with a city that is larger than your city and test it again.
OK, now that we have the weather data interface, the next step is to let the ESP8266 module automatically connect to the network via WiFi, request weather data via http, and then output it to the serial port.
After writing the LUA instruction, the serial port effect is as follows
Try it with the serial port assistant, the effect is perfect