The script sometimes hangs on the curl statement - guess the wifi shield is not that stable.
When I have scheduled it in Cron indigo is fine - it does not know of the script, I guess.
When I have scheduled it from within Indigo, Indigo becomes unresponsive.
Any switches I should use and is there a way to timeout curl in less than 20 seconds (it normally takes 8 secs to run, 7 in curl)
And is there a way to find out if curl comes back successfully
Thanks
Karl
-- read data from wifi shield on-top of arduino Uno reading the alarm voltages of the inhouse alarm system of the doors and windows.
-- set variables in indigo, then send out emails in case "away" and (door is "open" or was "opened" )
set wdsData to ""
try -- read data from arduino alarm reader
set wdsData to (do shell script "curl 192.168.1.xxx -d curl=1") --- xxx is the local IP of the wifi shield
end try
set alarm_flag to (word 3 of paragraph 2 of wdsData) as text
set changed_flag to (word 4 of paragraph 2 of wdsData) as text
tell application "IndigoServer"
set value of variable "alarm_study_door" to alarm_flag
set value of variable "alarm_study_door_changed" to changed_flag
end tell
set alarm_flag to (word 3 of paragraph 3 of wdsData) as text
set changed_flag to (word 4 of paragraph 3 of wdsData) as text
tell application "IndigoServer"
set value of variable "alarm_motion_detection" to alarm_flag
set value of variable "alarm_motion_detection_changed" to changed_flag
end tell
-- etc..
When aplescript hangs indigo is slow - rainbow wheel
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
Re: When aplescript hangs indigo is slow - rainbow wheel
How are you executing the AppleScript from within Indigo? Which version of Indigo are you using?
Re: When aplescript hangs indigo is slow - rainbow wheel
as stated:
- when scheduled in crontab indigo is not impacted,
- when I schedule it with Indigo 6.0.0 b8 in / schedule / Actions / embedded Applescript
and the script hangs, Indigo becomes unresponsive
added some check at beginning of apple script to avoid running it twice:
tell application "Finder"
if POSIX file "$HOME/Documents/alarm_script_running" exists then
set hanging to "1"
else
set hanging to "0"
end if
end tell
if hanging = "1" then
tell application "IndigoServer"
set value of variable "applescript_read_alarm_hanging" to "1"
end tell
else
tell application "IndigoServer"
set value of variable "applescript_read_alarm_hanging" to "0"
end tell
do shell script "date > $HOME/Documents/alarm_script_running"
set wdsData to ""
try -- read data from arduino alarm reader
set wdsData to (do shell script "curl 192.168.1.xxx -d curl=1")
end try
set alarm_flag to (word 3 of paragraph 2 of wdsData) as text
set changed_flag to (word 4 of paragraph 2 of wdsData) as text
tell application "IndigoServer"
set value of variable "alarm_study_door" to alarm_flag
set value of variable "alarm_study_door_changed" to changed_flag
end tell
...
tell application "IndigoServer"
set value of variable "applescript_read_alarm_hanging" to "0"
end tell
end if
do shell script "rm $HOME/Documents/alarm_script_running"
- when scheduled in crontab indigo is not impacted,
- when I schedule it with Indigo 6.0.0 b8 in / schedule / Actions / embedded Applescript
and the script hangs, Indigo becomes unresponsive
added some check at beginning of apple script to avoid running it twice:
tell application "Finder"
if POSIX file "$HOME/Documents/alarm_script_running" exists then
set hanging to "1"
else
set hanging to "0"
end if
end tell
if hanging = "1" then
tell application "IndigoServer"
set value of variable "applescript_read_alarm_hanging" to "1"
end tell
else
tell application "IndigoServer"
set value of variable "applescript_read_alarm_hanging" to "0"
end tell
do shell script "date > $HOME/Documents/alarm_script_running"
set wdsData to ""
try -- read data from arduino alarm reader
set wdsData to (do shell script "curl 192.168.1.xxx -d curl=1")
end try
set alarm_flag to (word 3 of paragraph 2 of wdsData) as text
set changed_flag to (word 4 of paragraph 2 of wdsData) as text
tell application "IndigoServer"
set value of variable "alarm_study_door" to alarm_flag
set value of variable "alarm_study_door_changed" to changed_flag
end tell
...
tell application "IndigoServer"
set value of variable "applescript_read_alarm_hanging" to "0"
end tell
end if
do shell script "rm $HOME/Documents/alarm_script_running"
Re: When aplescript hangs indigo is slow - rainbow wheel
That was the information I was looking for.kw123 wrote:- when I schedule it with Indigo 6.0.0 b8 in / schedule / Actions / embedded Applescript...
When executing AppleScript as an embedded script, it's executed in the same thread as IndigoServer itself, so if the AppleScript hangs, so does the entire Indigo system. The best way to avoid server delays due to AppleScript delays is to put the AppleScript into an external AppleScript file and execute the external script rather than an embedded one. This results in a multi-threaded script execution.
Yes. Usekw123 wrote:Any switches I should use and is there a way to timeout curl in less than 20 seconds (it normally takes 8 secs to run, 7 in curl)
Code: Select all
curl -m 20 192.168.1.xxx -d curl=1Yes. Modify your "try" statement by adding an "on error" handler. The "do shell script" AppleScript verb will throw an error if curl returns with a non-zero exit status and you can catch both the error message (what you'd see in the terminal that's output to Standard Error) as well as the numerical exit status.kw123 wrote:And is there a way to find out if curl comes back successfully
Code: Select all
set wdsData to ""
set errorNumber to 0
set errorMessage to ""
try -- read data from arduino alarm reader
set wdsData to (do shell script "curl 192.168.1.xxx -d curl=1") -- xxx is the local IP of the wifi shield
on error aMessage number anError
set errorNumber to anError
set errorMessage to aMessage
end try