- Sat Jul 30, 2016 10:18 am
#51775
Hi, I usually get this error message when I run esp8266-01 for an hour, I always have to reflash nodemcu and then add 3 files again.
Can't autodetect firmware, because proper answer not received (may be unknown firmware).
Please, reset module or continue.I try connecting RST pin to GND and then remove, but It shows some strange characters.
I have built bin file from
http://nodemcu-build.com/, branch master
Here are 3 files I use:
init.lua
Code: Select alltmr.alarm(0, 10000, 0, function() dofile("uartDemo.lua") end)
mainIoTF.lua
Code: Select all
broker = "iot.eclipse.org" -- IP or hostname of IoTF service
mqttPort = 1883 -- MQTT port (default 1883: non-secure)
userID = "" -- blank for quickstart
userPWD = "" -- blank for quickstart
clientID = "xxx" -- Client ID
count = 0 -- Test number of mqtt_do cycles
mqttState = 0 -- State control
topic = "xxx"
t0 = tmr.time()
-- Wifi credentials
SSID = "xxx"
wifiPWD = "xxxxx"
function wifi_connect()
wifi.setmode(wifi.STATION)
wifi.sta.config(SSID,wifiPWD)
wifi.sta.connect()
end
function mqtt_do(dataUART)
count = count + 1 -- tmr.alarm counter
if mqttState < 5 then
mqttState = wifi.sta.status() --State: Waiting for wifi
wifi_connect()
elseif mqttState == 5 then
print("Starting to connect...")
m = mqtt.Client(clientID, 120, userID, userPWD)
m:on("offline", function(conn)
print ("Offline")
mqttState = 0 -- Starting all over again
end)
-- on receive message
m:on("message", function(conn, topic, data)
print(topic.." - " )
if data ~= nil then
print("data: "..data)
end
end)
m:connect(broker , mqttPort, 0,
function(conn)
print("Connected to " .. broker .. ":" .. mqttPort)
mqttState = 20 -- Go to publish state
m:subscribe(topic,0,
function(conn)
print("Subscribe topic: "..topic)
end)
end)
elseif mqttState == 20 then
mqttState = 25 -- Publishing...
t1 = tmr.time() - t0
if t1 > 100 then
t1 = 0
t0 = tmr.time()
end
-- t1 is used as emulated sensor data, real application will use GPIOx to sense external sensor
m:publish(topic , dataUART, 0, 1,
function(conn)
-- Print confirmation of data published
print("Sent message #"..count.." data:"..dataUART)
mqttState = 20 -- Finished publishing - go back to publish state.
end)
else print("Waiting..."..mqttState)
mqttState = mqttState - 1 -- takes us gradually back to publish state to retry
end
end
uartDemo.lua
Code: Select allrequire("mainIoTF")
function uartDemo()
uart.on("data", "\r",
function(data)
print("receive from uart:", data)
mqtt_do(data)
if data=="quit\r" then
uart.on("data") -- unregister callback function
end
end
, 0)
end