Category Archives: Computers

Hikvision Separate Day / Night Settings with Raspberry Pi

The Hikvision cameras I use for LPR don’t have the ability to manually control the gain of the sensor when the camera is set in “Auto” mode. “Auto” mode pushes the camera from night to day mode automagically by detecting the ambient light in the scene. This is normally fine, but for LPR the gain needs to be set very low to compensate for the bright reflections that come from license plates. Manually pushing the camera into night or day mode enables the control of gain, but making the camera switch automagically becomes impossible.

To get around this issue I use a Raspberry Pi to push configuration changes to the camera manually. It finds the local sunrise/sunset times based on latitude/longitude and uses those times to schedule the change. If you are using a NVR you need to enable remote camera management in the settings so you can reach each individual camera.

Place this first block of code into a file named

import requests
import json
import time
import subprocess
from dateutil import tz
from datetime import datetime

longitude = ''
latitude = ''
timezone = ''#America/New_York
ips = [] #['', '']
user = ''
password = ''
nightOrDayPath = '/home/pi/'

r = requests.get('' + latitude + '&lng=' + longitude + '&date=today')
json = json.loads(r.content.decode('utf-8'))

from_zone = tz.gettz('UTC')
to_zone = tz.gettz(timezone)

utcSunset = datetime.strptime(time.strftime("%Y-%m-%d") + " " + json['results']['sunset'], '%Y-%m-%d %I:%M:%S %p')
utcSunset = utcSunset.replace(tzinfo=from_zone)
utcSunrise = datetime.strptime(time.strftime("%Y-%m-%d") + " " + json['results']['sunrise'], '%Y-%m-%d %I:%M:%S %p')
utcSunrise = utcSunrise.replace(tzinfo=from_zone)
sunset = utcSunset.astimezone(to_zone)
sunrise = utcSunrise.astimezone(to_zone)

print("sunrise is " + sunrise.strftime('%H:%M %p'))
print("sunset is " +  sunset.strftime('%H:%M %p'))

for ip in ips:
        dayCommand = 'python3 ' + nightOrDayPath + ' --ip ' + ip + ' --user ' + user + ' --password ' + password + ' --dayornight day'
        nightCommand = 'python3 ' + nightOrDayPath + ' --ip ' + ip + ' --user ' + user + ' --password ' + password + ' --dayornight night'

        p = subprocess.Popen('at ' + sunrise.strftime('%H:%M') , stdin=subprocess.PIPE, shell=True)
        p = subprocess.Popen('at ' + sunset.strftime('%H:%M'), stdin=subprocess.PIPE, shell=True)

print('tasks are scheduled')

Create a cron job that will execute after midnight each day.

1 0 * * * /usr/bin/python3 /home/pi/

Put the second block in

#!/usr/bin/env python
import requests
from requests.auth import HTTPBasicAuth
import sys
import argparse

parser = argparse.ArgumentParser(description='Set day and night status on Hikvision cameras.')
parser.add_argument('--ip', help='IP address and port to send command to')
parser.add_argument('--user', help='Hikvision username')
parser.add_argument('--password', help='Hikvision password')
parser.add_argument('--dayornight', help='night or day', choices=['night', 'day'])


xml = '<ImageChannel version="2.0" xmlns=""><IrcutFilter version="2.0" xmlns=""><IrcutFilterType>' + args.dayornight + '</IrcutFilterType></IrcutFilter></ImageChannel>'
requests.put('http://' + args.ip + '/ISAPI/Image/channels/1', data=xml, auth=HTTPBasicAuth(args.user, args.password));

Overheating Lenovo W540

A Lenovo W540 was overheating, peaking at 99° before the Intel Core i7 4700MQ would automatically throttle down the speed to prevent permanent damage. A nasty side effect of this is reduced performance. A workstation-grade laptop should be able to handle this kind of heat without issue, what was going wrong!? This was obviously something hardware related since the fan would run at 100% while the air coming out of the fan was room temperature and the CPU was ready to boil water. After disassembling the machine I noticed the heat sink compound wasn’t “smooshed” against the CPU like it should be:


Take a closer look at the image above. What is that desiccant ball doing in there, keeping the heatsink from pressing against the CPU correctly??

Close up of the heat culprit:


I’m going to assume this mistakenly fell in during initial assembly and isn’t an intended feature. After removing the ball and securing the heatsink the compound spread much more evenly:


Prime95 was also happy with the results: