Я работаю над настройкой WeMos D1 Mini с nodeMCU, чтобы он делал http-публикацию каждую минуту, а затем переходил в глубокий сон, повторяю. У меня есть контакты 32 и 8, подключенные кабелем-перемычкой, как указано в документации nodeMCU. Когда я запускаю следующий код (без глубокого сна), он работает нормально, но не когда я включаю код глубокого сна, тогда он не может сделать какой-либо HTTP-пост вместе, любая помощь будет оценена.
init.lua
-- configure network
dofile("credentials.lua")
-- dht22 sensor for humidity&temperature
dht22 = 5
status, temp, humi, temp_dec, humi_dec = dht.read(dht22)
if status == dht.OK then
-- for debugging, print to console
print("DHT Temperature: "..temp)
print("DHT Humidity: "..humi)
elseif status == dht.ERROR_CHECKSUM then
print( "DHT Checksum error." )
elseif status == dht.ERROR_TIMEOUT then
print( "DHT timed out." )
end
-- post request
http.post('url',
'Content-Type: application/json\r\n',
'{"humidity":'..humi..', "temperature":'..temp..', "moisture":'..adc.read(0)..', "sunlight":0}',
function(code, data)
if (code < 0) then
print("HTTP request failed")
else
print(code, data)
end
end)
-- small delay to allow the device to make http post before going into deep-sleep mode
tmr.delay(5000000)
print("enterning deep sleep mode for 60 seconds...goodbye")
node.dsleep(60000000)
credentials.lua
wifi.setmode(wifi.STATION)
wifi.sta.config("ssid","pwd")
tmr.alarm(1, 10000, 1, function()
if wifi.sta.getip()== nil then
print("Awaiting IP...")
else
tmr.stop(1)
print("IP: "..wifi.sta.getip())
print("Proceeding...")
dofile("init.lua")
end
end)