Что вызывает сброс моего Nodemcu/ESP 8266?

Я использую датчик, похожий на датчик Холла, для подсчета количества прерываний. Через какое-то случайное время, обычно после того, как он был включен в течение 1-2 часов, он сбрасывается, а затем следуют случайные сбросы через случайные промежутки времени.

counter = 0;
sampletime = 0;
lastrisetime = tmr.now()
pin = 2

do
  gpio.mode(pin, gpio.INT)

  local function rising(level)
    -- to eliminate multiple counts during a short period (.5 second) difference is taken
        if ((tmr.now() - lastrisetime) > 500000) then
        lastrisetime = tmr.now();
    end
    -- when tmr.now() resets to zero this takes into account that particular count 
    if ((tmr.now() - lastrisetime) < 0) then
        lastrisetime = tmr.now();
    end
  end

  local function falling(level)
    if ((tmr.now() - lastrisetime) > 500000) then
        -- Only counted when the pin is on falling
        -- It is like a sine curve so either the peak or trough is counted 
            counter = counter + 1;
        print(counter)
        lastrisetime = tmr.now();
        sampletime = lastrisetime;
    end
    -- when tmr.now() resets to zero this takes into account that particular count 
    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
> Connecting...
connected
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
> Connecting...
connected
 print(node.heap())
21216
> F.)ç˛.¶Ùå¶1.@H  .ÊÍ

NodeMCU 0.9.6 build 20150704  powered by Lua 5.1.4
> Connecting...
connected
H!໩.ä‚D.ã ¸å¶H.åb‘

NodeMCU 0.9.6 build 20150704  powered by Lua 5.1.4
> Connecting...
connected
 print(node.heap())
22904
> print(node.heap())
21216
> 

Спасибо, что нашли время, чтобы прочитать это. Цените ваш вклад.


person nik_11    schedule 02.12.2016    source источник
comment
Это решено? Если да, рассмотрите возможность проголосовать/принять ответы.   -  person Marcel Stör    schedule 04.01.2017


Ответы (2)


Возможна проблема со сторожевым таймером.

В вашей процедуре обслуживания прерываний похоже, что вы слишком много ждете.

Лучше удалить оттуда временные операции, просто установить флаг и в другом цикле проверить состояние флага и завершить свои временные операции.

person cagdas    schedule 02.12.2016

NodeMCU 0.9.6 сборка 20150704 на базе Lua 5.1.4

Прежде всего, нужно использовать последнюю версию прошивки NodeMCU. Версия 0.9.x устарела, содержит множество ошибок и больше не поддерживается. См. здесь https://github.com/nodemcu/nodemcu-firmware/#releases

lastrisetime = tmr.now()

Настоящая проблема в том, что tmr.now() переворачивается через 2147 секунд, я полагаю. Я узнал об этом, когда работал над правильная функция устранения отказов.

-- inspired by https://github.com/hackhitchin/esp8266-co-uk/blob/master/tutorials/introduction-to-gpio-api.md
-- and 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; -- proposed because of delta rolling over, https://github.com/hackhitchin/esp8266-co-uk/issues/2
        if delta < delay then return end;

        last = now
        return func(...)
    end
end

function onChange ()
    print('The pin value has changed to '..gpio.read(pin))
end

gpio.mode(pin, gpio.INT, gpio.PULLUP) -- see https://github.com/hackhitchin/esp8266-co-uk/pull/1
gpio.trig(pin, 'both', debounce(onChange))
person Marcel Stör    schedule 03.12.2016
comment
Спасибо за ваш ответ. У вас есть надежный источник, который продает последнюю версию прошивки NodeMCU? Я пытался прошить его, но это не сработало, а те, что я нашел, продают только старую версию Lolin. - person nik_11; 04.12.2016
comment
Я пытался прошить его, но это не сработало - тогда вам нужно (научиться) это исправить. Нецелесообразно заказывать новые комплекты разработчика всякий раз, когда вам нужна более новая прошивка: nodemcu.readthedocs. io/en/latest/en/flash - person Marcel Stör; 04.12.2016