nodeMCU深度睡眠配置

我正在配置运行nodeMCU的WeMos D1 Mini,使其每分钟进行一次http post,然后进入深度睡眠,重复此过程。我按照nodeMCU文档的说明,使用跳线电缆将pin32和pin8连接在了一起。当运行以下代码(省略deepsleep)时,它可以正常工作,但当包含deepsleep代码时,它无法进行任何http post,需要帮助。

init.lua
-- 配置网络
dofile("credentials.lua")

-- 温湿度传感器dht22
dht22 = 5
status, temp, humi, temp_dec, humi_dec = dht.read(dht22)

    if status == dht.OK then
        -- 调试时打印到控制台
        print("DHT温度: "..temp)
        print("DHT湿度: "..humi)
    elseif status == dht.ERROR_CHECKSUM then
        print( "DHT校验和错误。" )
    elseif status == dht.ERROR_TIMEOUT then
        print( "DHT超时。" )
    end

-- post请求
http.post('url',
  'Content-Type: application/json\r\n',
  '{"湿度":'..humi..', "温度":'..temp..', "湿度":'..adc.read(0)..', "光照":0}',
  function(code, data)
    if (code < 0) then
      print("HTTP请求失败")
    else
      print(code, data)
    end
  end)

-- 稍等片刻,以便设备在进入深睡眠模式之前进行http post
tmr.delay(5000000)
print("进入60秒的深度睡眠模式...再见")
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("等待IP...")
    else
        tmr.stop(1)
        print("IP: "..wifi.sta.getip())
        print("继续...")
        dofile("init.lua")
    end
end)
点赞
用户131929
用户131929

当我运行以下代码(省略deepsleep),它可以正常工作,但当我包含deepsleep代码时,它完全无法进行任何http post请求。

我不明白...在您的代码示例中,您并没有省略深度睡眠,是吧?

不管怎样,tmr.delay不行,特别是在50微秒以上的任何事情上。为什么不在HTTP请求返回时进入深度睡眠呢?就像这样:

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)
      print("进入60秒的深度睡眠模式...再见")
      node.dsleep(60000000)
    end
  end)
2017-04-15 20:05:34