nodemcu_latest.bin: 0x00000
for most esp8266 modules, just pull GPIO0 down and restart.
You can use the nodemcu-flasher to burn the firmware.
Or, if you build your own bin from source code.
0x00000.bin: 0x00000
0x10000.bin: 0x10000
Better run file.format() after flash
baudrate:9600
ip = wifi.sta.getip() print(ip) -- nil wifi.setmode(wifi.STATION) wifi.sta.config("SSID","password") ip = wifi.sta.getip() print(ip) -- 192.168.18.110
pin = 1 gpio.mode(pin,gpio.OUTPUT) gpio.write(pin,gpio.HIGH) print(gpio.read(pin))
-- A simple http client conn=net.createConnection(net.TCP, 0) conn:on("receive", function(conn, payload) print(payload) end ) conn:connect(80,"115.239.210.27") conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n" .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
<source lang=“lua”
>
srv=net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive",function(conn,payload) print(payload) conn:send("<h1> Hello, NodeMcu.</h1>") end) conn:on("sent",function(conn) conn:close() end) end)
</source>
=
<source lang=“lua”
>
m = mqtt.Client("clientid", 120, "user", "password") --setup Last Will and Testament (optional) --Broker will publish a message with qos = 0, retain = 0, data = "offline" --to topic "/lwt" if client don't send keepalive packet m:lwt("/lwt", "offline", 0, 0) m:on("connect", function(con) print ("connected") end) m:on("offline", function(con) print ("offline") end) --on publish message receive event m:on("message", function(conn, topic, data) print(topic .. ":" ) if data ~= nil then print(data) end end) --for secure: m:connect("192.168.11.118", 1880, 1) m:connect("192.168.11.118", 1880, 0, function(conn) print("connected") end) --subscribe topic with qos = 0 m:subscribe("/topic",0, function(conn) print("subscribe success") end) --or subscribe multiple topic (topic/0, qos = 0; topic/1, qos = 1; topic2 , qos = 2) --m:subscribe({["topic/0"]=0,["topic/1"]=1,topic2=2}, function(conn) print("subscribe success") end) --publish a message with data = hello, QoS = 0, retain = 0 m:publish("/topic","hello",0,0, function(conn) print("sent") end) m:close(); --you can call m:connect again
</source>
=
-- a udp server s=net.createServer(net.UDP) s:on("receive",function(s,c) print(c) end) s:listen(5683) -- a udp client cu=net.createConnection(net.UDP) cu:on("receive",function(cu,c) print(c) end) cu:connect(5683,"192.168.18.101") cu:send("hello")