ESP8266 first launch in Linux Mint

Автор | 15.11.2015

esp8266-01 pin

esp8266-01 pin


For flashing firmware you need connect GPIO0 to GND and CH_PD to VCC
I have this TTL converter

Bus 003 Device 026: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

But they have 5v output, so i used 5v to 3.3v converter

5v-to-3.3v

5v-to-3.3v

Prepare notebook for flashing
Go to https://github.com/themadinventor/esptool
and download esptool

wget https://github.com/themadinventor/esptool/archive/master.zip

install Python pip

apt-get -y install python-pip

Inzip our master.zip

unzip esptool-master.zip

Run installing dependency

python setup.py install

Go to https://github.com/nodemcu/nodemcu-firmware/releases/tag/0.9.6-dev_20150704 and download latest firmware

wget https://github.com/nodemcu/nodemcu-firmware/releases/download/0.9.6-dev_20150704/nodemcu_float_0.9.6-dev_20150704.bin

Connect USB-Serial controller and see how they discovered by Linux

dmesg
......
[26543.612344] usb 3-2: new full-speed USB device number 26 using xhci_hcd
[26543.741216] usb 3-2: New USB device found, idVendor=067b, idProduct=2303
[26543.741234] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[26543.741238] usb 3-2: Product: USB-Serial Controller
[26543.741241] usb 3-2: Manufacturer: Prolific Technology Inc.
[26543.741908] pl2303 3-2:1.0: pl2303 converter detected
[26543.742743] usb 3-2: pl2303 converter now attached to ttyUSB0
....

In my case this is /dev/ttyUSB0
Run esptool for flashing

python esptool.py --port /dev/ttyUSB0  write_flash 0x00000 nodemcu_float_0.9.6-dev_20150704.bin

....
Connecting...
Erasing flash...

Writing at 0x00000000... (0 %)
....

Reboot
Connect to console

screen /dev/ttyUSB0 9600

Let’s see how many memory we have

remaining, used, total = file.fsinfo()
print("\nFile system info:\nTotal: "..total.." Bytes\nUsed: "..used.." Bytes\nRemaining: "..remaining.." Bytes\n")

Or erase all local memory

file.format()

Now let install lua tools

mkdir -p /opt/esp/lua-tool/
cd /opt/esp/luatool

git clone https://github.com/4refr0nt/luatool.git

For start – connect to WiFi

screen /dev/ttyUSB0 9600
wifi.setmode(wifi.STATION)
wifi.sta.config("","")
ip, nm, gw=wifi.sta.getip()
print("\nIP Info:\nIP Address: "..ip.." \nNetmask: "..nm.." \nGateway Addr: "..gw.."\n")

In homedir luatool we have 2 files: init.lua and main.lua
init.lua

-- init.lua --


-- Global Variables (Modify for your network)
ssid = "reverse.kiev.ua"
pass = "superpass"


print('init.lua ver 1.2')
wifi.setmode(wifi.STATION)
print('set mode=STATION (mode='..wifi.getmode()..')')
print('MAC: ',wifi.sta.getmac())
print('chip: ',node.chipid())
print('heap: ',node.heap())
-- wifi config start
wifi.sta.config(ssid,pass)
-- wifi config end

tmr.delay(5000000)

-- Run the main file
dofile("main.lua")

$main.lua

tmr.alarm(0, 1000, 1, function()
   if wifi.sta.getip() == nil then
      print("Connecting to AP...")
   else
      print('IP: ',wifi.sta.getip())
      tmr.stop(0)
   end
end)

 -- Start a simple http server
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
  conn:on("receive",function(conn,payload)
    print(payload)
    conn:send("

Hello, NodeMCU!!!

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

Write this files to memory

python luatool.py --port /dev/ttyUSB0 --src init.lua --dest init.lua --verbose
python luatool.py --port /dev/ttyUSB0 --src main.lua --dest main.lua --verbose

On restart i have micro http-server that shows text
Hello, NodeMCU!!!

Thanks to http://www.allaboutcircuits.com/projects/how-to-make-an-interactive-tcp-server-nodemcu-on-the-esp8266/
and http://www.whatimade.today/flashing-the-nodemcu-firmware-on-the-esp8266-linux-guide/

Залишити відповідь