venerdì, ottobre 11, 2013

Secure backup on cloud with raspberry

Yesterday my usb drive connected to the raspberry is dead and I lost about 20 gigabytes of data. This morning I implemented a system of automatic backup cloud to prevent these problems.

I used will have access to 50gb and the webdav protocol


  1. sudo apt-get update && sudo apt-get install davfs2

Now we create a mount point to access the cloud

  1. mkdir /media/box

Check if the connection to box. works

  1. sudo mount -o uid=pi -o gid=pi -t davfs /media/box

The system will ask user name and password, if they are correct we could browse through our account in the folder /media /box

  1. ls /media/box

If the test is ok, close all opened file and digit

  1. sudo umount /media/box

ok perfect, so that we can mount the disk manually but every time we have to enter your username and password, we eliminate this "problem"

  1. sudo nano /etc/davfs2/secrets

and add this line

  1.   yourusername   yourpassword

Now mount without credentials, but a mount command is very long, we eliminate this "problem"

  1. sudo nano /etc/fstab

and add this line

  1. /media/box davfs rw,noexec,noauto,user,async,_netdev,uid=pi,gid=pi 0 0

reboot system and you can simply mount the folder with

  1. sudo mount /media/box

Now we use rsync to make a backup with the command

  1. rsync -arHu --delete folderyouwantosave/ /media/box

The first backup will be slow (depending on your connection upload) and the next will be faster (incremental)

You can put the script in crontab every day/week even at night

Good backup

mercoledì, settembre 18, 2013

Timelapse video with raspberry and raspberry pi camera module

Today I did some tests with the raspberry camera module

First you need to decide how many photos you take and how often, in my test I've took a photos per minute for fours hours.
To do this, the command is very simple:

  1. raspistill -o name_%04d.jpg -tl 60000 -t 14400000

-tl = timelapse mode, takes a picture every <t>ms (60.000 is 1x60x1000ms) = 1 minute
-t = time before taking picture (14.400.000 is 4x60x60x1000ms) = 4 hours
name_%04d = will result filenames with sequential number.

See man raspistill for more options

When taking photos is over we need to merge them into a video:

  1. avconv -r 10 -i name_%04d.jpg -r 10 -vcodec libx264 -crf 20 -g 15 videoname.mp4

-r = is a fps
-crf = is a quality video, lowers value = best quality = large file size, I think that 20 is a good value

With this parameters the file size result is 140 Mb (original size 2592x1944). If you want to resize a video use this option during video creation:

  1. avconv -r 10 -i name_%04d.jpg -r 10 -vcodec libx264 -crf 20 -g 15 -vf crop=2592:1944,scale=1280:720 videoname.mp4

With crop option the file size result is 15 Mb, perfect for youtube

venerdì, settembre 13, 2013

Wired remote control Canon homebuilt

Today I wanted to buy the wired remote control Canon but then I asked myself ... why not build it yourself?

A quick search on the internet to find the pinout ( and this is the result:

black button: meter
red button: shutter
red switch: bulb mode

material: jack stereo 2,5, three wire cable of the desired length, n. 2 button, n. 1 switch, 1 plastic box, welder and lots of patience :)

Connections details:

Final result:

Cost original remote control in the internet: 25 $ approximately
Cost for this project: 2 $ approximately

Thx to my friend Luca Soltoggio for help of the welding

giovedì, settembre 05, 2013

How to display the status of the torrent from the terminal

Today I need to see the status of torrents from the terminal on the raspberry. After obtaining this information, you can implement a lot of things (turn on an LED when a torrent is finished, send an email, write something on the lcd monitor etc ...).
The solution is the following:

transmission-remote --auth=username:password -l

but if, as in my case the transmission is non-standard port or host is different just use the command

transmission-remote host:port --auth=username:password -l

After obtaining the status of the torrent you can do the "parsing" of the result to be able to implement in a script (send mail, php page, lcd, led etc ...)

For more information and options read the man transmission-remote

lunedì, agosto 12, 2013

Page for monitor real-time values ​​that uses graphs gauge with Google api

Hello everyone, here I will explain how to have a php page on some raspberry to monitor real-time values ​​that uses graphs gauge with Google api:

Requirements: php and apache2 without any particular configuration

This will be the final result with a marker that moves in real time:

The project is based on two files: data.php and index.html

data.php: collects the values ​​returning a standard json string with "tags" (example: temp, memory, cpu …). The name of the tag is important because it is used to retrieve the values ​​of the graphics


  1. <?php
  2. $data["mem_used"]=intval(exec('free -m | grep Mem | awk \'{print $3}\''));
  3. $data["temperature"]=floatval(exec('/opt/vc/bin/vcgencmd measure_temp | cut -c6-9'));
  4. $data["cpu"]=floatval(exec('vmstat | egrep -v \'cpu|us\' | awk \'{ print $13 }\''));
  5. $json=json_encode($data);
  6. echo $json;
  7. ?>

launching “php data.php” from terminal



You can add almost all the commands of the terminal (remember that the commands will be launched with www-data user), if the result of json string is 0 for one parameter, check this command from the terminal with user www-data and check error or permission denied

example: If you add this code (vmstat | egrep -v \'cpu|us\' | awk \'{ print $13 }\') for check cpu percentage you must add www-data user to “video” and “plugdev” linux groups

index.html: if data.php is correct display a gauge graph :)

in the documentation on the internet I have not found a way to dynamically change the graphics so I created a function


  1. <!--
  2. You are free to copy and use this sample in accordance with the terms of the
  3. Apache license (
  4. -->
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
  6. <html xmlns="">
  7.   <head>
  8.     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  9.     <title>
  10.       standard title page
  11.     </title>
  12. <!--
  13. google api don’t change
  14. -->
  15.  <script type="text/javascript" src=""></script>
  16.         <script src="//"></script>
  17.     <script type="text/javascript">
  18.       google.load('visualization', '1', {packages: ['gauge']});
  19.           google.setOnLoadCallback(drawVisualization);
  20.           $(document).ready(function() {
  21.                 chart = new google.visualization.Gauge(document.getElementById('visualization'));
  22.                 chart2 = new google.visualization.Gauge(document.getElementById('visualization2'));
  23.                 chart3 = new google.visualization.Gauge(document.getElementById('visualization3'));
  24. // first graph (temperature proc)
  25.         data = google.visualization.arrayToDataTable([
  26.           ['Label', 'Value'],
  27.           ['Temp', 0],
  28.         ]);
  29.                 options = {
  30.           width: 250, height: 250,
  31.           max:100, min:0,
  32.                   animation:{duration: 500},
  33.                   redFrom:70, redTo:100,
  34.                   yellowFrom:50, yellowTo:70,
  35.                   greenFrom:0, greenTo:50,
  36.           minorTicks: 10,
  37.           majorTicks: ["0",,20,,40,,60,,80,,100]
  38.         };
  39. // second graph (ram used)
  40.         data2 = google.visualization.arrayToDataTable([
  41.           ['Label', 'Value'],
  42.           ['Memory', 0],
  43.         ]);
  44.                 options2 = {
  45.           width: 250, height: 250,
  46.           max:512, min:0,
  47.                   animation:{duration: 500},
  48.                   redFrom:400, redTo:512,
  49.                   yellowFrom:300, yellowTo:400,
  50.                   greenFrom:0, greenTo:300,
  51.           minorTicks: 10,
  52.           majorTicks: ["0",,128,,,256,,,384,,512]
  53.         };
  54. // third graph (cpu percentage used)
  55.         data3 = google.visualization.arrayToDataTable([
  56.           ['Label', 'Value'],
  57.           ['Cpu', 0],
  58.         ]);
  59.                 options3 = {
  60.           width: 250, height: 250,
  61.           max:100, min:0,
  62.                   animation:{duration: 500},
  63.                   redFrom:60, redTo:100,
  64.                   yellowFrom:30, yellowTo:60,
  65.                   greenFrom:0, greenTo:60,
  66.           minorTicks: 10,
  67.           majorTicks: ["0",,20,,,50,,,80,,100]
  68.         };
  69.           });
  70. // function to update data automatically
  71.       function drawVisualization() {
  72.                 chart.draw(data,options);
  73.                 chart2.draw(data2,options2);
  74.                 chart3.draw(data3,options3);
  75.       }
  76.           function test(ajaxdata) {
  77.                         var memused=ajaxdata.mem_used;
  78.                         var temperature=ajaxdata.temperature;
  79.                         var cpu=ajaxdata.cpu;
  80.                         console.log(ajaxdata);
  81.                         data.setValue(0,1,temperature);
  82.                         data2.setValue(0,1,memused);
  83.                         data3.setValue(0,1,cpu);
  84.                         chart.draw(data,options);
  85.                         chart2.draw(data2,options2);
  86.                         chart3.draw(data3,options3);
  87.           }
  88.           function status_update() {
  89.                  var jqxhr = $.getJSON('data.php?' + 'random=' + Math.random(), function() {
  90.                 })
  91.                 .fail(function() {
  92.                 })
  93.                 .done(function(ajaxdata) {
  94.                 test(ajaxdata);
  95.                 });
  96.           }
  97.       var refreshId = setInterval('status_update()', 1000);
  98.           $.ajaxSetup({ cache: false });
  99.     </script>
  100.   </head>
  101. <!--
  102. html standard for view a graph
  103. -->
  104. <body style="font-family: Arial;border: 0 none;">
  105. <div id="visualization" style="float: left; width: 250px; height: 250px;"></div>
  106. <div style="clear:both"></div>
  107. <div id="visualization2" style="float: left; width: 250px; height: 250px;"></div>
  108. <div id="visualization3" style="float: left; width: 250px; height: 250px;"></div>
  109.   </body>
  110. </html>

I hope I have been helpful, in the future will add the code to save the values in line chart for historical values (temperature e humidity sensor...) and button to take actions through gpio only via php page. Thx to my friend Luca Soltoggio ( for the code support