====== NodeMcu (ESP8266) ====== ** To be upgraded with future knowledge ** This module implements an ESP8266MOD that is Wifi hardware + microcontroller with flash memory + USB-uart interface (serial port) + GPIO lines. Its firmware is 3-layered: * Bootloader * Base Firmware: interprets user code and interfaces with hardware * User code in LUA language For the moment, we don't know how to install user code in memory and IF and HOW it would be possible to rewrite the whole firmware to user's needs. ===== Step-by-step guide to get the first example working. ===== - Compile the firmware - Upload the firmware - Connect to the serial terminal - Write and test an example code: connect to an existing WiFi network and start a simple HTTP server ==== 1. compile the firmware ==== ( [[http://nodemcu.readthedocs.io/en/dev/en/build/]] ) We used the cloud building service at [[http://nodemcu-build.com/]]. Once built an email will notify you and you can download the image ready to be uploaded in the nodemcu . ==== 2. upload the firmware ==== ( [[http://nodemcu.readthedocs.io/en/dev/en/flash/]] ) Download esptool.py and the needed requirements (python and python-serial module) from [[https://github.com/themadinventor/esptool|here]] . If your module is cheap it should be 512kB version so run: ''esptool.py --port write_flash -fm qio -fs 4m 0x00000 .bin''. ==== 3. Connect to the serial terminal ==== Open your preferred terminal (i just prefer [[http://cutecom.sourceforge.net/|cutecom]]) and set the serial port (like /dev/ttyUSB0) to 115200 baud 8n1. Reset the device and it should write something like: NodeMCU custom build by frightanic.com \0x09branch: master \0x09commit: cdaf6344457ae427d8c06ac28a645047f9e0f588 \0x09SSL: false \0x09modules: file,gpio,http,net,node,ow,tmr,uart,wifi build \0x09built on: 2016-06-07 19:06 powered by Lua 5.1.4 on SDK 1.5.1(e67da894) lua: cannot open init.lua > That ''>'' means it is ready to accept and interpret LUA code in console mode. ==== 4. Write and test an example code ==== ( [[http://nodemcu.com/]] , [[https://nodemcu.readthedocs.io]] , [[https://github.com/nodemcu/nodemcu-firmware]] ) === 4.1. connect to an existing WiFi network === To set the wifi module in client mode enter(+return): wifi.setmode(wifi.STATION) To list the wifi networks enter all the following lines and wait a little while after the last: function listap(t) for k,v in pairs(t) do print(k.." : "..v) end end wifi.sta.getap(listap) To join a wifi network enter: wifi.sta.config("SSID", "password") To check if it has joined and the IP obtained from the DHCP server: print (wifi.sta.getip()) === 4.2. start a simple HTTP server === srv = net.createServer(net.TCP) srv:listen(80, function(conn) conn:on("receive", function(sck, payload) print(payload) sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n

Hello folks this is NodeMCU!

") end) conn:on("sent", function(sck) sck:close() end) end)