shinji2009
Member
как я понял за кнопку отвечает скрипт sensor.lua. я расставил в нём команды вывода на печать текста lolNN чтобы понять где он зависает. выглядеть скрипт стал вот так
вот как выглядит нормальное срабатываение сенора в терминале
а вот как выглядит после зависания
я по всему скрипту расставил выводы на печать так чтобы при выполнении любой функции или программы что-то да печаталось. но при зависании ничего не печается. так где же он зависает-то? :с
Код:
--sensor.lua
print("lol03")
file.open( "sensorThreshold.lua", "r" )
sensorThreshold = file.read()
sensorThreshold = string.gsub(sensorThreshold, "%s+", "")
sensorThreshold = tonumber(sensorThreshold)
file.close()
--Set how many times you'd like the sensor to receive an input before sending an alert.
print("lol04")
file.open( "timerThreshold.lua", "r" )
timerThreshold = file.read()
timerThreshold = string.gsub(timerThreshold, "%s+", "")
timerThreshold = tonumber(timerThreshold)*1000
file.close()
--print("Timer Reset: "..timerThreshold)
--The interaction of these two variables above will determine your tolerance for false alarms.
--For example if this device is a panic button and you want to send a message after 3 button presses within 10 seconds, set countThreshold = 3 and TimerResetThreshold = 10000.
--If this device is a Smoke Alarm Sound Sensor, and you want to wait until the alarm has been sounding for ~30 seconds before sending an alert, set countThreshold = 60, TimerResetThreshold = 60000 (60 loud sounds within 60 seconds).
--If this device is a Baby Noise SMS Alert, set countThreshold = 5, TimerResetThreshold = 60000 (5 loud sounds/cries within 60 seconds). Keep in mind you will have to calibrate your microphone sensor to a lower threshold than a Smoke Alarm Sensor.
buttonPin = 2 -- this is ESP-01 pin GPIO4
gpio.mode(buttonPin,gpio.INT,gpio.PULLUP)
count = 0
print("lol05")
function resetCounter()
print("lol07")
count = 0
end
print("lol06")
function debounce (func)
print("lol08")
local last = 0
local delay = 10000
return function (bounceCheck)
local now = tmr.now()
if now - last < delay
then return
end
last = now
return func(bounceCheck)
end
end
print("lol09")
function onChange()
print("lol10")
if gpio.read(buttonPin) == 0
then count = count + 1
tmr.alarm(6,timerThreshold,0,function()
resetCounter()
print("Time limit reached. Restarting Counter...")
end)
if count == sensorThreshold
then
print("(" .. count .. ") sensor inputs counted! Sending Alert!")
dofile("ifttt.lua")
else print("(" .. count .. ") sensor inputs counted...")
end
end
end
print("lol01")
gpio.trig(buttonPin,"down", debounce(onChange))
print("lol02")
Код:
[28/10/16 - 21:59:20:059] You are connected to Wifi. IP Address:192.168.1.42
[28/10/16 - 21:59:20:061] Starting Sensor...
[28/10/16 - 21:59:23:065] Listening for Sensor Inputs...
[28/10/16 - 21:59:23:093] lol03
[28/10/16 - 21:59:23:099] lol04
[28/10/16 - 21:59:23:105] pin,mode,pullup= 2 2 1
[28/10/16 - 21:59:23:109] Pin data at mode: 2 6000083c, 4 0 0, fffffffe
Function platform_gpio_mode() is called. pin_mux:1610614844, fu[28/10/16 - 21:59:23:115] nc:0
[28/10/16 - 21:59:23:115] lol05
[28/10/16 - 21:59:23:116] lol06
[28/10/16 - 21:59:23:119] lol09
[28/10/16 - 21:59:23:119] lol01
[28/10/16 - 21:59:23:119] lol08
[28/10/16 - 21:59:23:123] Pin data: 2 2 6000083c, 4 0 0, 00000002
[28/10/16 - 21:59:23:123] lol02
[28/10/16 - 21:59:28:067] pm open,type:2 0
[29/10/16 - 01:31:00:076] ip:192.168.1.42,mask:255.255.255.0,gw:192.168.1.1
[29/10/16 - 04:24:32:161] pin:2, level:0 <-- НАЖАЛ КНОПКУ[COLOR=#ff0000] [/COLOR]
[29/10/16 - 04:24:32:162] Calling: 00000002
[29/10/16 - 04:24:32:163] lol10
[29/10/16 - 04:24:32:172] (1) sensor inputs counted! Sending Alert!
[29/10/16 - 04:24:32:399] IFTTT Event Name: ALARM
[29/10/16 - 04:24:32:407] Sensor Type: BLA
[29/10/16 - 04:24:32:506] Sensor Location: BLA
[29/10/16 - 04:24:32:514] Sensor Location: MEDIUM
[29/10/16 - 04:24:32:517] net_create is called.
[29/10/16 - 04:24:32:519] TCP server/socket is set.
[29/10/16 - 04:24:32:520] net_on is called.
[29/10/16 - 04:24:32:522] net_on is called.
[29/10/16 - 04:24:32:532] net_dns is called.
[29/10/16 - 04:24:32:533] pin:2, level:1
[29/10/16 - 04:24:32:535] Calling: 00000002
[29/10/16 - 04:24:32:536] lol10 <---- НЕ ПОНИМАЮ КАК ЭТО МОЖЕТ БЫТЬ ВЕДЬ СЕЙЧАС ВЫПОЛНЯЕТСЯ СОВЕРШЕННО ДРУГОЙ СКРИПТ
[29/10/16 - 04:24:32:779] net_dns_found is called.
[29/10/16 - 04:24:32:786] We can connect to 54.88.106.208
[29/10/16 - 04:24:32:788] net_start is called.
[29/10/16 - 04:24:32:790] TCP port is set: 80.
[29/10/16 - 04:24:32:792] TCP ip is set: 54.88.106.208
[29/10/16 - 04:24:32:794] socket_connect is called.
[29/10/16 - 04:24:32:985] net_socket_connected is called.
[29/10/16 - 04:24:32:989] Sending to IFTTT
[29/10/16 - 04:24:32:995] Alert sent to IFTTT.
[29/10/16 - 04:24:33:206] net_socket_received is called.
[29/10/16 - 04:24:35:169] lol07
[29/10/16 - 04:24:35:176] Time limit reached. Restarting Counter...
[29/10/16 - 04:24:36:416] alertDelay: 10 minutes.
[29/10/16 - 04:24:36:423] Waiting 10 minutes before sending another message.
Код:
[29/10/16 - 08:23:58:056] pin:2, level:1
[29/10/16 - 08:23:58:057] Calling: 00000002 <--- ЭТО МОУДУЛЬ ДЕЛАЕТ САМ ПО СЕБЕ
[29/10/16 - 08:23:58:057] lol10
[29/10/16 - 08:23:58:612] pin:2, level:1
[29/10/16 - 08:23:58:612] Calling: 00000002
[29/10/16 - 08:23:58:612] lol10
[29/10/16 - 08:36:49:933] pin:2, level:1
[29/10/16 - 08:36:49:933] Calling: 00000002
[29/10/16 - 08:36:49:933] lol10
[29/10/16 - 11:38:00:348] ip:192.168.1.42,mask:255.255.255.0,gw:192.168.1.1
[29/10/16 - 15:09:30:337] ip:192.168.1.42,mask:255.255.255.0,gw:192.168.1.1
[29/10/16 - 15:18:05:893] pin:2, level:1
[29/10/16 - 15:18:05:895] Calling: 00000002
[29/10/16 - 15:18:05:895] lol10 <--- ЭТО ОН САМ ТОЖЕ ЗАЧЕМ-ТО ДЕЛАЕТ
[29/10/16 - 15:25:10:730] pin:2, level:0 <--- А ВОТ ЭТО Я НАЧАЛ ЖАТЬ КНОПКУ
[29/10/16 - 15:25:10:732] Calling: 00000002
[29/10/16 - 15:25:10:734] pin:2, level:0 <--- НИ ОДНОГО ВЫВОДА lolNN
[29/10/16 - 15:25:10:736] Calling: 00000002
[29/10/16 - 15:25:23:752] pin:2, level:0
[29/10/16 - 15:25:23:753] Calling: 00000002
[29/10/16 - 15:25:23:891] pin:2, level:1
[29/10/16 - 15:25:23:891] Calling: 00000002
[29/10/16 - 15:25:23:999] pin:2, level:0
[29/10/16 - 15:25:24:000] Calling: 00000002
[29/10/16 - 15:25:24:002] pin:2, level:0
[29/10/16 - 15:25:24:003] Calling: 00000002
[29/10/16 - 15:25:24:141] pin:2, level:0
[29/10/16 - 15:25:24:142] Calling: 00000002
[29/10/16 - 15:25:24:217] pin:2, level:0
[29/10/16 - 15:25:24:218] Calling: 00000002
[29/10/16 - 15:25:24:220] pin:2, level:0
[29/10/16 - 15:25:24:221] Calling: 00000002
[29/10/16 - 15:25:24:332] pin:2, level:1
[29/10/16 - 15:25:24:333] Calling: 00000002