Category Archives: PHP

Webtool for managing Motion on Raspberry Pi

Raspberry PI Morion Webtool

A few months ago I setup a small surveillance system at home with motion detection using a Rapsberry Pi, Motion detection software and a webcam, following roughly these instructions for a low cost Raspberry Pi surveillance camera.

For a while I managed the surveillance system via SSH on my smartphone. It worked great but I was getting tired of SSH, so I finally got my act together and developed a small web-tool to do the work for me. It’s a very simple tool and all it does is check the status of the system and allow me to switch it on or off via the browser on my phone.

Here is how you can install my web tool.

(For installing Motion and setting up your Raspberry Pi, please follow the instructions on the link posted above)

  • Install Apache ( sudo apt-get install apache2 )
  • Install PHP5 (sudo apt-get install php5)
  • Install PHP5-gd (sudo apt-get install php5-gd) – this will enable PNG support, used by the function that displays the On/Off buttons depending on the status of Motion.

Download and install the web-tool

  1. At the Raspberry PI console type these commands, pressing “Enter” after each of them.
  2. cd /var/www
  3. sudo mkdir motion
  4. cd motion
  5. sudo wget
  6. sudo tar zxvf motion-webtool.tar.gz
  7. Allow web server user www-data to run sudo commands for motion and pkill (pkill is used to kill processes by their names) – this is probably a little unsecure and lazy, but your RasPi should be only accessible within you network so it’s not a big deal – suggestions are welcome though.

Permissions – How to.

  • sudo visudo (to edit sudoers)
  • and add the following lines:

www-data ALL=(root) NOPASSWD:/usr/bin/motion
www-data ALL=(root) NOPASSWD:/usr/bin/pkill

  • To save press shift+o, Enter to confirm overwrite, shift+x to exit
  • Start Apache: sudo service apache2 start

Then access the tool via your browser: http://<ip>/motion (where <ip> is the ip address of your Raspberry Pi, which should have been setup as a static IP).

It is not safe to rely on the system’s timezone settings

Recently I have been having the following error on my PHP code every time I call the PHP function date();  Mostly when running it on my local test server.

Warning: date(): It is not safe to rely on the system’s timezone settings

Cause: Since PHP5.1.0 the E_RESTRICT setting causes PHP to report error for every call
to a date/time function, if no default time is set.

There are 2 approaches to  resolving this.

  1. Set time setting to your PHP script with the function date_default_timezone_set();  with the intended time zone/location eg: for GMT one can use date_default_timezone_set(‘Europe/London’);
  2. Set time setting to your php.ini file by editing the line ;date.timezone = to date.timezone = “Europe/London” or you required location. This is good for setting a server wide time setting.

Technorati Tags: , , , , ,

Automatically display form data with PHP

This is a simple PHP  script to automatically display (dump output)  data submited from a html form.

The form setup

  • all inputs (form fields) need to have the same name with [] at the end to turn it into an array,  e.g <input type=text name=formdata[]>

formq.html content

<form method=post action=showme.php>
Name: <input type=text name=formdata[]><br>
Email: <input type=text name=formdata[]><br>

<input type=submit value=ok>

The Script setup

showme.php content

$data = $_POST[‘formdata’]; # get value from the form fields

foreach ( $data as $key => $value ) { # loop through array collecting the results

echo  “$value<br>”;  # output the data  – print to page

Technorati Tags: , , , ,