Jump to content

Recommended Posts

Posted (edited)

Hi all - I have created a simple script that turn on cctv software (contacam)  when my phone does not ping back (when I'm out of range of home network)

#include <MsgBoxConstants.au3>
$iPing = 0

For $i = 5 To 1 Step -1 ; this 5 loops cycle is just for testing - please ignnore - when complete it will be an endless loop

Example()

Sleep(120000)

Next

Func Example()
    ; Ping the phone.
    $iPing = Ping("192.168.1.102")

    If $iPing Then ; If a value greater than 0 was returned then turn off camera.
        _endCCTV()
    Else
        _startCCTV() ; If a value of 0 was returned then turn on camera.
    EndIf
EndFunc   ;==>Example



Func _startCCTV()
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "on")
    Sleep(10000)
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "50")

EndFunc

Func _endCCTV()

    ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "0")
    Sleep(10000)
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "off")
EndFunc

 

 

the problem I have is that in this format the script run the bat file that turn on the camera (or off) everytime the ping runs but obviously once the ping returns 0 and the camera starts I only want to run the bat on ping NOT 0 (turn off camera) 

any ideas/advice?

Edited by mmoalem
  • Developers
Posted

Just keep track of the current status of the camera.
How do you run the script? is it scheduled each x minutes? In that case you could write that current status to an INI file and retrieve at the start of the script.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

thanks - guess that can work - but was wondering about splitting the loop into two - one looped function check ping for 0 when its true it turns camera on and than runs another looped function that check ping for NOT 0 and if thats true it turns camera off andf than runs the first function. this will avoid having ini files but not sure how best to execute interweaving loops that run each other...

Posted

Would have to agree with @Jos here, just do this, it’s not so bad.

#include <MsgBoxConstants.au3>
$iPing = 0, $bCamera=False

For $i = 5 To 1 Step -1 ; this 5 loops cycle is just for testing - please ignnore - when complete it will be an endless loop

Example()

Sleep(120000)

Next

Func Example()
    ; Ping the phone.
    $iPing = Ping("192.168.1.102")

    If $iPing Then ; If a value greater than 0 was returned then turn off camera.
        _endCCTV()
    Else
        _startCCTV() ; If a value of 0 was returned then turn on camera.
    EndIf
EndFunc   ;==>Example


Func _startCCTV()

If Not $bCamera Then    
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "on")
    Sleep(10000)
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "50")
    $bCamera=True
EndIf
    
EndFunc

Func _endCCTV()

If $bCamera Then
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "0")
    Sleep(10000)
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "off")
    $bCamera=False
EndIf
    
EndFunc

*Not tested - assumes endless looping - assumes the script is started locally (i.e. with camera off).

Code hard, but don’t hard code...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...