Chat freely about anything...

User avatar
By Franz Patzal
#14728 Hello and good evening ( current time in Germany, I beg your pardon for my English).

I am new in this forum, in ESP8266 and Lua but experienced in VB(A) and ABAP.
I want to build a small Homeautomation to rise the security of my home.

Now, I wrote a program for testing GPIO-Input, see below.

The Program tests the GPIO00 and if a button – connected to GPIO00 - is pressed, then it stops

--------------------------------------------
pinValue = 1
gpioPin00 = 3

gpio.mode(gpioPin00, gpio.INPUT)

function readgpio( _pin )
local _pinValue

_pinValue = gpio.read( _pin )

return _pinValue

end

function wait( _tics )
local _i = 0

for _i = 1, _tics do

end

return
end

while pinValue == 1 do

pinValue = readgpio( gpioPin00 )

if pinValue == gpio.LOW then
print('GPIO is low - I stop working')
else
print ('GPIO is high'..' - Heap: '..node.heap())
end

wait( 204800 )

end

--------------------------------------------

If I not press the button the ESP reboots after a few seconds
See the program output, first with pressed button then without.

1) With button pressed

>dofile("read_gpio.lua")
GPIO is high - Heap: 12592
GPIO is high - Heap: 12480
GPIO is high - Heap: 12480
GPIO is high - Heap: 12480
GPIO is low - I stop working
<- Button is pressed :)

2) Leave button unpressed

> dofile("read_gpio.lua")
GPIO is high - Heap: 12208
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
GPIO is high - Heap: 12488
bBÊǦÿSb]þÙ¦HgÙ¦¤ŽØ¦ÿá
<- reboot after a few seconds (4) :(

the following comes from init.lua:
NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4
WIFI control
ESP8266 mode is: 3
create Server
establishing server
nil
>


Other programs e.g. two blinking LEDs working overnight without stopping.

Is it a problem with the memory or the callstack?

Please can anybody tell me what is wrong and how can I solve it.

Best regards
Franz
User avatar
By jankop
#14735 Hi Franz,
here is solution:
Code: Select allwhile pinValue == 1 do

pinValue = readgpio( gpioPin00 )

if pinValue == gpio.LOW then
print('GPIO is low - I stop working')
else
print ('GPIO is high'..' - Heap: '..node.heap())
end
tmr.wdclr() -- !!! clear WDT !!!
wait( 204800 )

end
User avatar
By Franz Patzal
#14766 Thank You Byjankop and Byulumu for Your help.

I don’t know about watchdog and I found out, that the “blink”-program (from a tutorial) uses tmr.alarm.

After editing my test program, it runs overnight without stopping.

I see I have to learn about tmr and watchdog.

Thank you again and best regards
Franz