Page 1 of 1

Lua / bash script running longer than 10 seconds (log)

Posted: Thursday 21 January 2016 0:38
by Chakkie
Can some one tell me why this simple bash script will results the system hanging for 10 seconds and causes an error log Error: Warning: lua script /home/pi/domoticz/scripts/lua/script_device_deurbel.lua has been running for more than 10 seconds

Bash script calls Voordeur.sh This simple script just turn the light on
First attempt:

Code: Select all

#!/bin/sh

/usr/bin/curl "http://$192.XXX.X.XX:XXXX/json.htm?type=command&param=switchlight&idx=54&switchcmd=On"
Second attempt:

Code: Select all

#!/bin/sh
Server=192.XXX.X.XX:XXXX
Port=XXXX
  curl -s "http://$Server:$Port/json.htm?type=command&param=switchlight&idx=54&switchcmd=On"
My lua script:

Code: Select all

commandArray = {}
  if (devicechanged['Deurbel voordeur']=='On') then
    os.execute('/home/pi/domoticz/scripts/Voordeur.sh')
    os.execute('/home/pi/domoticz/scripts/SentSnapshot.sh')
    os.execute('/home/pi/domoticz/scripts/SentSnapshot.sh')
    os.execute('/home/pi/domoticz/scripts/SentSnapshot.sh')
    os.execute('/home/pi/domoticz/scripts/SentSnapshot.sh')
      print('Script Deurbel is ingedrukt')
  end
return commandArray
As soon as I remove os.execute('/home/pi/domoticz/scripts/Voordeur.sh') everything works just fine. So the problem does not seems to be the SentSnapshot.sh

The reason why os.execute('/home/pi/domoticz/scripts/SentSnapshot.sh') is repeat is because I want to take 4 snapshots. The repeating action works just fine.

Re: Lua / bash script running longer than 10 seconds (log)

Posted: Thursday 21 January 2016 8:23
by jvdz
Not sure why it happens but I've seen this behavior before. You could add a & at the end to of the line to have the OS return right away without waiting for the bash script to end:

Code: Select all

 os.execute('/home/pi/domoticz/scripts/Voordeur.sh &')
Jos

Re: Lua / bash script running longer than 10 seconds (log)

Posted: Friday 22 January 2016 7:31
by jannl
I think the 4 osexecutes take too much time. Lua scripts must have a limited execution time. Why not handle all the sentsnapshots from 1 shellscript and may indeed use & to execute the script in the background.

Re: Lua / bash script running longer than 10 seconds (log)

Posted: Tuesday 26 January 2016 21:38
by Chakkie
The & does helpt a little. However the light on action still only executed after the four snapshots are taken while I put the light on action before the four snapshots script. This is kind of a strange behaviour. I have tested several time and it seems this issue occur only to switch on command.

The 4 osexecutes seems work fine without the switch on os.executes. And you are right Jannl, may be it is better to include this actions in 1 shell script but I have know idea how to do that at this moment. May be someone has any idea

Code: Select all

#!/bin/sh
today=`/bin/date '+%d-%m-%Y__%H-%M-%S'`;    #Used to generate filename
IP="172.19.3.7"                       # IP address Camera

#Ping IP-address of camera to see if it's online, otherwise we don't have to grab a snapshot
if ping -c 1 $IP > /dev/null ; then  #Grab snapshot

#Get Snapshot from camera
wget "http://172.19.3.7:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=user&pwd=password" -O /volume1/Data/Deurbel_Snapshots/deurbel-$today.jpeg

#Send pushnotification with snapshot
/usr/bin/curl -s -X POST "https://api.telegram.org/bot123456789:yourcode/sendPhoto" -F chat_id=123456789 -F photo="@/volume1/Data/Deurbel_Snapshots/deurbel-$today.jpeg"

#Delete previous taken snapshots older than 7 days
find /volume1/Data/Deurbel_Snapshots/ -name '*.jpeg' -mtime +7 -delete
else
 /usr/bin/curl --data chat_id=138165201 --data-urlencode "text=Camera is offline, so no image can be sent"  "https://api.telegram.org/bot123456789:yourcode/sendMessage"
fi