什么导致我的Nodemcu/ESP8266重启?
2016-12-2 8:14:4
收藏:0
阅读:103
评论:2
我正在使用类似霍尔效应传感器的传感器来统计中断的数量。在一些随机时间之后,通常在开机1-2小时后,它会重置,然后在随机的时间间隔内随机重置
counter = 0;
sampletime = 0;
lastrisetime = tmr.now()
pin = 2
do
gpio.mode(pin, gpio.INT)
local function rising(level)
-- 为了消除短时间内的多次计数(.5秒),需要取差
if ((tmr.now() - lastrisetime) > 500000) then
lastrisetime = tmr.now();
end
-- 当tmr.now()归零时,需要考虑该特定计数
if ((tmr.now() - lastrisetime) < 0) then
lastrisetime = tmr.now();
end
end
local function falling(level)
if ((tmr.now() - lastrisetime) > 500000) then
-- 只有在引脚下降时才计算
-- 它就像正弦曲线,所以峰值或谷值都会被计数
counter = counter + 1;
print(counter)
lastrisetime = tmr.now();
sampletime = lastrisetime;
end
-- 当tmr.now()归零时,需要考虑该特定计数
if ((tmr.now() - lastrisetime) < 0) then
lastrisetime = tmr.now();
counter = counter + 1;
print(counter)
end
end
gpio.trig(pin, "up", rising)
gpio.trig(pin, "down", falling)
end
这是我在CoolTerm上得到的错误信息,我每隔几个小时检查一次内存,你可以在那里看到结果。
NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4
> 连接...
已连接
print(node.heap())
22920
> print(node.heap())
22904
> print(node.heap())
22944
> print(node.heap())
22944
> 2. .print(node.heap())
22944
> print(node.heap())
22944
> ∆.)ç˛.䂸 æ ¸@H7.àåË‘
NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4
> 连接...
已连接
print(node.heap())
21216
> F.)ç˛.¶Ùå¶1.@H .ÊÍ
NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4
> 连接...
已连接
H!໩.ä‚D.æ ¸å¶H.åb‘
NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4
> 连接...
已连接
print(node.heap())
22904
> print(node.heap())
21216
>
感谢您抽出时间阅读此文。期待您的宝贵意见。
点赞
用户131929
NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4
使用最新版本的NodeMCU固件是首要的事情。0.9.x版本已经过时,存在许多错误,并且不再受支持。请参考这里 https://github.com/nodemcu/nodemcu-firmware/#releases
lastrisetime = tmr.now()
真正的问题是,我认为tmr.now()在2147秒时会翻转。我在编写适当的去抖函数时学到了这个知识点。
-- 参考 https://github.com/hackhitchin/esp8266-co-uk/blob/master/tutorials/introduction-to-gpio-api.md
-- 和 http://www.esp8266.com/viewtopic.php?f=24&t=4833&start=5#p29127
local pin = 4 --> GPIO2
function debounce (func)
local last = 0
local delay = 50000 -- 50ms * 1000 as tmr.now() has μs resolution
return function (...)
local now = tmr.now()
local delta = now - last
if delta < 0 then delta = delta + 2147483647 end; -- 因为delta翻转提出,https://github.com/hackhitchin/esp8266-co-uk/issues/2
if delta < delay then return end;
last = now
return func(...)
end
end
function onChange ()
print('引脚值已更改为 '..gpio.read(pin))
end
gpio.mode(pin, gpio.INT, gpio.PULLUP) -- 参见 https://github.com/hackhitchin/esp8266-co-uk/pull/1
gpio.trig(pin, 'both', debounce(onChange))
2016-12-03 07:54:05
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

可能是看门狗定时器问题。
在你的中断服务例程中,看起来你等待的时间太长了。
最好从中删除计时操作,只需设置一个标志,在另一个循环中检查标志状态并完成计时操作。