AberCam – Raspberry Pi Webcam

Bought a few more Raspberry Pis, and have got one gazing at the sea outside my window here in Aberystwyth. You can view it (if its on) here.

Pi Camera in its Poundland tupperware box

Pi Camera in its Poundland tupperware box

Changing Public IP address

With TalkTalk, at least every time our router reboots we get a new public IP address – which is difficult when the abercam webpage is looking for our router at a specific address. To combat this:

I used curl to get the webpage output of: http://ipecho.net/plain – which displays your public IP address. (Could use wget/lynx command line browser like: lynx –dump)

 curl  http://ipecho.net/plain > <filename>.php

Then put the result of this into a file, and uploaded it to my website

 curl -T <filename containing ip address>.php ftp://<ftp server name(.co.uk)>/public_html/ –user <username>:<password>

Where the filename is the name of the file where your IP address is written, ftp server name is your website name (matthewrobbins.co.uk), and the username and password are the ftp details for your website.

Now in the HTML page where the router address was used, I inserted a PHP include of the recently uploaded file containing the IP address. It now looks like:

<img style=”-webkit-user-select: none;” src=”http://<?php include(“<filename>.php”); ?>:<port>/?action=stream” />

Where the filename is the name of the file with the IP address in it, and the port is the one you have set your router to forward incoming connections to the Raspberry Pi (e.g 8080).

Last thing, set a cronjob to run the script every hour or so, bingo. Might be worth adding in an ‘if new_ip == old_ip, end. Else, continue and upload the new one..’ to save unneeded ftp connects and file overwrites. My end bash script looks like: (make sure to put in FULL file paths!)

curl http://ipecho.net/plain > /home/pi/Documents/code/static/ipaddress.php
curl -T /home/pi/Documents/code/static/ipaddress.php ftp://matthewrobbins.co.uk/public_html/ –user <username>:<password>

 

Update

The PiCam worked fine outside my window, but when I moved it sideways, the webcam stream became very jolty and stopped. Pings also stopped returning to the Pi. I believe this is due to the puny looking BT homehub that we have providing us WiFi (it doesn’t even have an external antenna!), so I’ve plugged in my trusty Tenda access point, which promptly set itself up and started working without any help needed. After changing it from WEP to WPA/WPA2 (I know, I know.. but some of the laptops in my house used to only support WEP…), I then had the fun challenge of not only getting one port forward working correctly, but two – as traffic had to be directed through the router (homehub) to the access point (Tenda), then to the Pi.

After setting this all up logically (Homehub forwards port 8080 to the external IP of the Tenda access point, then the Tenda forwards 8080 to the Pi), to my great surprise, everything started working after a couple of reboots (that both devices did NOT tell me I must do). I also found this great guide on portforward.com on double router port forwarding, which is a similar situation.

Update 2

Changed my IP address updater script to ensure that it will always upload an IP address (rather than a 404 or 503 error from the webpage):

(—- to indicate indentation)

#!/bin/bash
ip=$(curl http://ipecho.net/plain)

if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
—-echo ‘Good IP’
—-echo $ip
—-echo $ip > /home/pi/Documents/code/static/ipaddress.php
—-curl -T /home/pi/Documents/code/static/ipaddress.php ftp://matthewrobbins.co.uk/public_html/ –user <username>:<password>
else
—-echo ‘Bad IP. Exiting’
—-echo $ip
—-exit
fi

Also attached little rubber feet to the bottom of the tupperware box, as well as adding a safety rope tied to a bag of shoes in my room, as redundancy in case the wind gets stronger.

Matt

 

Google Chrome Saved Passwords Lock

Google Chrome very helpfully remembers your passwords for website logins, and for that, I am grateful. I also like the feature in settings (manage saved passwords) where you can view your saved usernames and passwords. I do not like, however, that there is no lock on this utility – as my friends sometimes use my computer, and whilst I tend to lock my computer when leaving it, I wouldn’t if other people were in the room watching something on it. They could very easily view all of my passwords, without having to input any credentials.

I’ve had a quick look at the problem – to see if I could make a little solution. I found the passwords are encrypted and stored in the file “Login Data” under ”C:\Users\<USERNAME>\AppData\Local\Google\Chrome\User Data\Default”  (Linux:  ~/.config/google-chrome/Default/Login\ Data ).

When in Windows…

Due to gaming demands and overall familiarity, I still use Windows as my main computer. What would have been a simple ‘chmod a-rw’ in Linux, turned out to be a lot more in Windows. Windows does have a permission altering command – icacls – but after spending too long trying to figure it out, I came up with a less elegant solution that works.

Lock the passwords script

Script is fairly self explanitory. Go to the folder (substitute in appropriate username), back up the old Login Data file, make a new one, and make it read only so Chrome doesn’t overwrite it.

cd “C:\Users\MaTT\AppData\Local\Google\Chrome\User Data\Default”

rename “Login Data” “Login Data-old”

echo.>”Login Data”

attrib +R “Login Data”

pause

 

Unlock the passwords script

Again very simple, change directory, remove the read-only attribute of the placeholder empty file, delete it, and restore the backup.

cd “C:\Users\MaTT\AppData\Local\Google\Chrome\User Data\Default”

attrib -R “Login Data”

DEL /F /S /Q /A “Login Data”

rename “Login Data-old” “Login Data”

pause

 

Saved these as .bat batch scripts, and they work, as long as Chrome isn’t running! Thats quite enough batch scripting for now..

Not very elegant, but I thought it was worth noting as I didn’t find any other solution out there on the interwebs (other than “don’t use the save password feature”). My idea was to have these both crafted into a little system tray program to toggle the lock on/off, however it is hindered somewhat by the fact Chrome cannot be running when you run either script (as it uses the Login Data file).