With the ESP-12 modules on a breadboard adapter I was finally ready for some tinkering. The plan for today was very simple: flash NodeMcu firmware, start programming the ESP8266 in Lua and try deep sleep mode.
I put an ESP-12 on a breadboard, used a FTDI-ish thing to connect the ESP-12 to my Windows PC and used a 3.3/5V breadboard power supply (set to 3.3V) to power the ESP-12.
Flash!
Time to flash the thing! I knew that sometime in January MQTT was added to the NodeMCU firmware so I searched for a recent firmware version that contained the MQTT code. I read some rumors that MQTT seemed to be broken in the latest NodeMcu firmware releases – on the ESP8266 forum I read that v20150127 was the latest release where MQTT still worked; yesterday I read that it was due to the addition of MQTT v3.1.1 support.
Tools and other things I downloaded to get started with the ESP-12 were:
– NodeMcu firmware
– NodeMcu flasher
– LuaUploader
– LuaLoader
The latter 2 have some overlap in functionality – it looks like LuaLoader will be my favorite. OK; now that I have a flash tool and the v20150127 firmware – what’s next? After some trial and error I found out that I had to change something on the ‘Config’ page of the flash tool:
I unchecked items 2, 3 and 4 and let the first item point to the right firmware image I wanted to use. Figuring this out took me longer than soldering the breadboard adapter … A wire from GPIOØ to GND followed by a cold boot set the ESP-12 in firmware upload mode, clicking “Flash” on the Operation tab was enough to flash the firmware.
After some playing around with “Hello World”- and “Blink”-like Lua scripts it was time to do something that would be a bit more exciting – things like interrupts, deep sleep and some MQTT of course.
First I wanted to know everything about deep sleep; I found this forum post and read about another mode the ESP8266 could be in – zombie mode. I wanted to avoid that mode of course so I took the suggested zombie counter measures which is pulling up GPIOØ & GPIO2 to VCC with ~5kΩ. And for using the deep sleep mode RST & GPIO16 have to be connected to each other and also pulled up to VCC; and of course CH_PD as usual.
Boot loop protection!
And of course, the first script I made with a node.dsleep() in it didn’t work .. well, it did what it was supposed to do, but not what I meant it to do! Some error in the code caused a reboot within a few seconds and there was no way I could stop this boot loop; nothing helped. Only after re-flashing the firmware I regained control over my ESP-12… So the first thing I did was searching for a workaround/solution for this and found one here, so now my init.lua (the NodeMcu autoexec.bat