Updating Dahua IPC-HFW4300S security camera settings
Post ReplyUpdating Dahua IPC-HFW4300S security camera settingsPosted: Thursday, January 15, 2015 [22:55:35] - 1
Dahua cameras are very good and wok flawlessly with SecuritySpy software. Although one thing in Dahua IPC-HFW4300S camera software requires constant update - camera schedule for switching from day to night mode and back. It has to be done manually by adjusting sliders in Camera -> Conditions -> Profile Management. AppleScrpt/Python/Perl/crontab help solving this little problem. Dahua software has a system Backup/Restore update form in System -> Import/Export section which can be used to change the camera settings by initially downloading system settings, updating Sunrise/Sunset data file (DeviceConfig.backup) and uploading it back to the camera VIA Web interface. To access Web interface my obvious weapon of choice was an AppleScript. Dahua uses Prototype extensively and accessing "Import" button turned out to be impossible VIA AppleScript as button is located in dynamically created iFrame -- therefore Python is used to click on a button while setting Safari window bounds to exactly the same coordinates every time program runs. Getting current Sunrise/Sunset data as well as updating DeviceConfig.backup file is easy enough to do using Perl. Dahua software information: Software Version: 2.420.0002.0.R, build : 2014-06-21 WEB Version: 3.2.4.184667 ONVIF Version: 2.4.1 AppleScript code: end tell delay 2 tell application "System Events" end tell delay 8 tell application "Safari" end tell delay 1 tell application "System Events" end tell delay 2 tell application "Safari" end tell delay 1 tell application "System Events" end tell delay 2 tell application "Safari" end tell delay 1 tell application "System Events" end tell delay 2 -- Safari window coordinates on the next line to be adjusted accordingly tell application "Safari" to set the bounds of the front window to {0, 22, 1650, 1024} delay 1 -- Below is a click coordinates and could be different on your system set Pcode to getPython("242, 245") do shell script "python -c " & quoted form of Pcode delay 1 tell application "System Events" end tell delay 2 on getPython(coord) import time from Quartz.CoreGraphics import * def mouseEvent(type, posx, posy): theEvent = CGEventCreateMouseEvent(None, type, (posx, posy), kCGMouseButtonLeft) CGEventPost(kCGHIDEventTap, theEvent) def mousemove(posx,posy): mouseEvent(kCGEventMouseMoved, posx,posy); def mouseclickdn(posx,posy): mouseEvent(kCGEventLeftMouseDown, posx,posy); def mouseclickup(posx,posy): mouseEvent(kCGEventLeftMouseUp, posx,posy); def mousedrag(posx,posy): mouseEvent(kCGEventLeftMouseDragged, posx,posy); ourEvent = CGEventCreate(None); currentpos = CGEventGetLocation(ourEvent); mouseclickdn(" & coord & "); mouseclickup(" & coord & "); " end getPython Save AppleScript as an APP to obfuscate code from kids. Please read Python issues notes below.. Next is a Perl script to get Sunrise/Sunset times for your region: unless($ENV{'SECURITYSESSIONID'}) { $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local:/usr/local/bin:/usr/bin/bin'; } $brids = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.3290)'; ## Replace YOUR_ZIP_CODE with your actual Zip Code $url = "/SecuritySpy/sunset.sunrise.raw.txt http://www.wunderground.com/cgi-bin/findweather/getForecast?query=YOUR_ZIP_CODE";; `curl --connect-timeout 30 -A '$brids' -o $url`; unless(-f "/SecuritySpy/sunset.sunrise.raw.txt" && -f "/SecuritySpy/DeviceConfig.backup") {print "no file: /SecuritySpy/sunset.sunrise.raw.txt or Camera file\n"; $settings = `cat /SecuritySpy/DeviceConfig.backup`; ## THIS IS A CAMERA BACK-UP FILE $vr = `cat /SecuritySpy/sunset.sunrise.raw.txt`; $bd = '<body'; $vr =~ s#<script>(.*?)</script>##gs; $vr =~ s#<(.*?)>##gs; $vr =~ s#(Sunrise / Set)(.*?)(\d{1,2}\:\d{2} \w{2})(.*?)(\d{1,2}\:\d{2} \w{2})##is; $rise=$3; $set=$5; ## Getting Hour and minutes for the sunrise. It works better if 20 minutes delay applied to the time. $rise =~ s/(\d{1,2}\:\d{2}) (\w{2})/$1/; if($min > 59) {$min -= 60; if($min < 1) {$min=1;} if($min > 55) {$min=55;} $hr++; $settings =~ s#("SunriseHour"\:)(\d{1,2})(,)#$1$hr$3#s; $settings =~ s#("SunriseMinute"\:)(\d{1,2})(,)#$1$min$3#s; if($min < 1 && $hr) {$min++;} if($ampm =~ m/pm/i) {$hr += 12;} open(TXT,">/SecuritySpy/sunset.sunrise.txt"); ## Getting Hour and minutes for the sunset. It works better if 20 minutes delay applied to the time. $set =~ s/(\d{1,2}\:\d{2}) (\w{2})/$1/; if($min > 59) {$min -= 60; if($min < 1) {$min=1;} if($min > 55) {$min=55;} $hr++; if($hr < 1 && $min) {$hr .= 'A';} if($min < 1 && $hr) {$min++;} if($ampm =~ m/pm/i) {$hr += 12;} print TXT "\$sethr=$hr;\t\$setmin=$min;\n"; close(TXT); open(TXB,">/SecuritySpy/DeviceConfig.backup"); `osascript /SecuritySpy/update.app`; ## Now run the AppleScript to upload updated back-up file ## Remove temporary data file to keep it cleaner - optional Replace "/SecuritySpy" directory with the one you will be using. Make sure curl is installed on your Mac. In Terminal window enter the following: which curl If you get path with curl program - you're fine. Last thing to do is to setup crontab to run Perl program once in 5 or 7 days. As an option Lingon could be used to do the crontab task. It is not a free software $5 and I am not affiliated with their website: http://www.peterborgapps.com/lingon it is very easy to use and worth every penny. Mac OS X Mavericks and Yosemite may require clearing AppleScript app in FireWall in order to gain Assistive devices access. I have no way of verifying it as newest OS I am running is Mountain Lion and have no plans on upgrading. |
RE: Updating Dahua IPC-HFW4300S security camera settingsPosted: Thursday, January 15, 2015 [23:01:04] - 2
Python may have issues with Quartz.CoreGraphics Apple removed it from Python distribution. To add Python Quartz and CoreGraphics support I used PyObjC. Getting PyObjC: http://pythonhosted.org/pyobjc/index.html Installing PyObjC: http://pythonhosted.org/pyobjc/install.html It works on Mountain Lion. Older Mac OS X versions (Tiger, Snow Leopard) work out of the box in my case. |