Monday, 22 February 2021

Hacking Trendnet TV-IP422WN IP Camera to use with Linux program

There are many good IP Cameras now, and I can replace them at very reasonable prices, but my 11 year old Trendnet TV-IP422WN cameras just keep running. Which surprised me considering I mounted them outdoors and the resident zebra doves use them as a convenient potty/perch.

 

Trendnet TV-IP422WN IP Camera

Resolution is only 640x480, and worse, the webpage uses ActiveX. But if I can use it from Linux then I can make my own webpage. And even consolidate several of them into one page, just like those CCTV screens.

Or perhaps a passive infrared sensor can be used to trigger a spotlight and cause the camera to capture a short video. All via MQTT. I found this really useful as it reduces the time required to view alarm footage.

 

Webpage viewed with Microsoft Internet Explorer: the live video display needs ActiveX

TV-IP422WN webpage using Google Chrome

Getting it to work in Linux bash turned out to be surprisingly easy. From zoneminder, type this into your browser (I used Chrome):

http://192.168.10.30/cgi/mjpg/mjpg.cgi

Note if you did a factory reset the default IP address is 192.168.10.30 user is admin and password is admin. You will need to change all three for security reasons.

From Linux bash I used:

$curl -m 5 -u admin:admin -o cctv_video.mpg -k http://192.168.10.30/cgi/mjpg/mjpg.cgi

Now this gives me an output file which I can view with mplayer. The '-m 5' option is used to record a 5-second video; otherwise the curl command will never exit. This is especially useful if you trigger recording with another sensor, maybe a passive infrared sensor.

If, instead of video record, you just want a live view,

$mplayer -fps 20 -demuxer lavf -user admin -passwd admin http://192.168.10.30/cgi/mjpg/mjpg.cgi

If you want a still snapshot, you aim your browser at:

http://192.168.10.30/cgi/jpg/image.cgi

Or from bash, you can use lynx:

$lynx -dump -auth=admin:admin  http://192.168.10.30/cgi/jpg/image.cgi > image.jpg

Usually, you will need different video settings for night and day. I could not find the settings I need on the Internet, but I got lucky: if I used the 'Debug' (ie F12) feature in Google Chrome, under the menu 'Network' with filter 'All', I was able to discern the url:

http://192.168.10.30/cgi/setup.cgi?page=camera

The data is in a Form posted as:

brightness=8&contrast=32&saturation=36&flicker=0&osd_enable=1

Google Chrome Debug mode for Video Settings page

My curl command for day then becomes:

$curl  -X POST -H "Content-Type: application/x-www-form-urlencoded" -u admin:admin -d "brightness=8&contrast=32&saturation=36&flicker=0&osd_enable=1" http://192.168.10.30/admin/camera.cgi

And for night:

$curl  -X POST -H "Content-Type: application/x-www-form-urlencoded" -u admin:admin -d "brightness=100&contrast=80&saturation=64&flicker=0&osd_enable=1" http://192.168.10.30/admin/camera.cgi

There is also a 'Night Mode' radio button which in bash is replicated as:

curl --connect-timeout 2 -u admin:admin -k http://192.168.10.30/admin/ptctl.cgi?night=1

Conversely 'Day' Mode is:

curl --connect-timeout 2 -u admin:admin -k http://192.168.10.30/admin/ptctl.cgi?night=0

Using the same method, the pan commands are:

$curl --connect-timeout 2 -u admin:admin -k http://192.168.10.30/admin/ptctl.cgi?move=left

$curl --connect-timeout 2 -u admin:admin -k http://192.168.10.30/admin/ptctl.cgi?move=right

Tilt commands are:

$curl --connect-timeout 2 -u admin:admin -k http://192.168.10.30/admin/ptctl.cgi?move=up

$curl --connect-timeout 2 -u admin:admin -k http://192.168.10.30/admin/ptctl.cgi?move=down

To center the camera:

$curl --connect-timeout 2 -u admin:admin -k http://192.168.10.30/admin/ptctl.cgi?move=h

If you want to set a particular camera angle at for example position 1 and name it 'Left':

http://192.168.10.30/admin/ptctl.cgi?position=0&positionname=Left

Note the position '1' is numbered as '0'. Again the data is uploaded as a Form:

$curl -u admin:admin  -H "Content-Type: application/x-www-form-urlencoded" -d "position=0&positionname=Left" -k http://192.168.10.30/admin/ptctl.cgi

Thereafter to return to your preset position at '1' you need to

$curl --connect-timeout 2 -u admin:admin -k http://192.168.10.30/admin/ptctl.cgi?move=p0

To get audio, go to Menu 'Video/Audio' then 'Video' and select '3GPP with Audio'. You can get the audio (and video) using:

mplayer rtsp://192.168.10.30/mpeg4

There you have it, Trendnet TV-IP422WN hacked. Happy Trails.