Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.

Link a questa pagina di confronto

Prossima revisione
Revisione precedente
talks:nodemcu-esp8266 [16/06/2016 13:15]
alez created
talks:nodemcu-esp8266 [16/06/2016 17:18] (versione attuale)
alez
Linea 1: Linea 1:
 ====== NodeMcu (ESP8266) ====== ====== NodeMcu (ESP8266) ======
  
-Step-by-step guide to the first example.+** 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 <​USB-port-with-ESP8266>​ write_flash -fm qio -fs 4m 0x00000 <​nodemcu-firmware>​.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: 
 +<​code>​ 
 +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 
 +
 +</​code>​ 
 + 
 +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):​ 
 + 
 +<​code>​ 
 +wifi.setmode(wifi.STATION) 
 +</​code>​ 
 + 
 +To list the wifi networks enter all the following lines and wait a little while after the last: 
 + 
 +<​code>​ 
 +function listap(t) 
 +    for k,v in pairs(t) do 
 +        print(k.."​ : "​..v) 
 +    end 
 +end 
 +wifi.sta.getap(listap) 
 +</​code>​ 
 + 
 +To join a wifi network enter: 
 +<​code>​ 
 +wifi.sta.config("​SSID",​ "​password"​) 
 +</​code>​ 
 + 
 +To check if it has joined and the IP obtained from the DHCP server: 
 +<​code>​ 
 +print (wifi.sta.getip()) 
 +</​code>​ 
 + 
 +=== 4.2. start a simple HTTP server === 
 +<​code>​ 
 +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<​h1>​ Hello folks this is NodeMCU!</​h1>"​) 
 +    end) 
 +    conn:​on("​sent",​ function(sck) sck:close() end) 
 +end) 
 +</​code>​
Navigazione

Table of contents

Contact

For any info you can write to:
Per qualunque info potete scrivere a:
info[at]maetech[dot]it

Ads

Stampa/Esporta
QR Code
QR Code talks:nodemcu-esp8266 (generated for current page)