Wednesday, May 18, 2016

RASPBERRY PI BACKUP: THE BEST BACKUP TUTORIAL

 
Raspberry Pi Backup Tutorial DIY hacking
Raspberry Pi Backup
For all those who have worked on a raspberry pi, you might have experienced the frustration associated with having a corrupted SD card. Especially, when all the work you have done is stored in it. But, it doesn’t have to be that way. Using a couple of really simple commands in Linux , you will be easily able to backup your Raspberry Pi SD card. And, when required, to restore the raspberry pi backup on to a new SD card.
The process is really simple and straight forward. Once you have restored the image of your raspberry pi backup to your new SD card, you will be able to just plug it in and use it like your old system. This post also covers general dilemmas such as: how to backup a raspberry pi SD card having multiple partitions and also the solution to the infamous dd command error: “dd: writing to `/dev/sdc’: Input/output error”. It also addresses the problem of not being able to use your full memory capacity of your raspberry pi SD card after restoring an image file onto it. So, use this DIY Hacking tutorial to safeguard all your precious work on a raspberry pi. Get started with this Raspberry Pi Backup tutorial!
What are the stuff required to do this ?
  1. Raspberry Pi model B or Raspberry pi 2 with memory card preloaded with an OS.
  2. A new SD card having a memory capacity equal to or greater than the SD card you would like to backup.
  3. A linux pc with a memory card reader.
How does it work?
Here, we are using simple dd commands to create an image (.img) of the SD card we want to backup. This image can then be zipped and stored in your pc for future. While restoring the raspberry pi backup , you again use the dd command in the reverse order and prepare the new SD card. However, please note that restoration of an .img file can only be done on to a memory card having equal or greater memory capacity than the original backed up SD card. Take extra precaution while performing the dd command , as it can cause you to corrupt your hard disk if you enter improper destination or source addresses in it.
Raspberry Pi Backup Tutorial DIY hacking
Raspberry Pi Backup

Step 1 : Backing up your SD card

First of all, insert your raspberry pi SD card into the memory card reader / slot of your PC. Next, use the dd command to create an image file of the SD card. To correctly identify your card, perform “df -h” before and after inserting the SD card and observe the new paths . These, new paths represent your SD card. You might notice that you have more than one partition for the memory card, for example: when you perform “df -h” , it might list your SD card as /dev/sdc1 and /dev/sdc2. In this case, use just “/dev/sdc” while performing the dd command, to include both partitions. Like so :
sudo dd if=/dev/sdc of=/home/ars/backup.img
The memory card should be specified under “if” and the destination of the backup under “of”.You can use “bs=1M” or “bs=4M” to specify writing speed with the command too.
However, after performing the above command some of you might experience an error like : dd: writing to `/dev/sdc’: Input/output error. For those haven’t got this error, please proceed to step two. This error is usually caused due to some errors encountered while reading the SD card. It is normally experienced by people who see a warning while booting the pi , saying that they should perform an fsck operation manually. It is caused due to improper unmounting of the SD card. To get over this error, you have to perform the fsck operation on the SD card. Before doing it, unmount the SD card as so :
  • umount /dev/sdc1
  • umount /dev/sdc2
Next, perform the “fsck” operation to rectify the errors in the memory card. Like so:
  • sudo fsck -C /dev/sdc1
  • sudo fsck -C /dev/sdc2
Now, remove the card reader or the SD card and re insert it. And again perform the dd command like below, it should work without any errors. If it again shows dd errors , repeat the above steps.
sudo dd if=/dev/sdc of=/home/ars/backup.img

Step 2: Restoring your Raspberry Pi backup to a new SD card

Now, we will restore the Raspberry Pi backup from the first step. If you have a used SD card having some data in it, then you would have to format it first. If you have a brand new card, it might not be necessary to format, even though it wouldn’t hurt to. Insert the new card to the card reader. Use “df -h” command to identify your new memory card. If you have multiple partitions on the card like /dev/sdc1 and /dev/sdc2 , format the card by using /dev/sdc to include both partitions.
Before formatting the card, unmount the SD card. Like so, for an SD card with no partitions:
  • umount /dev/sdc
Like so, for a used SD card having multiple partitions:
  • umount /dev/sdc1
  • umount /dev/sdc2
Next , format the card using this command :
sudo mkdosfs -I -F32 /dev/sdc
After this, you will have a completely blank and formatted SD card. Now, remove the card reader or the SD card and re insert it into the PC. Next , perform the dd command to restore your raspberry pi backup on this new card. Use the location of the image file created using the first step under the “if” section and the new SD card location under the “of” section. Like so:
sudo dd if=/home/ars/backup.img of=/dev/sdc
Now, you have created an identical copy of your original raspberry pi SD card. Plug it in your raspberry pi and it will be just like how it used to be before :)
In cases, when you are using a new SD card of greater memory capacity than the original card. You will notice that, when you perform “df -h” command, the size of the new card is identical to the original SD card even though it is actually a bigger SD card. In order to utilize the entire space of the new SD card, simply plug in the card into your raspberry pi and start it up. Enter the command “sudo raspi-config” and select “Expand root partition” option. It will ask to reboot when you exit by selecting “Finish”. After rebooting, perform “df -h” command, you will notice now that the maximum size of the SD card is its full capacity.
In any case , if you experience the dd error : dd: writing to `/dev/sdc’: Input/output error , in the second step. Please perform the fsck operation like in the first step and perform the dd command again after removing and re inserting the raspberry pi SD card or the memory card reader onto the PC. Having a Raspberry Pi backup will make your life a lot easier :)

BEST VOICE RECOGNITION SOFTWARE FOR RASPBERRY PI

 232
 
Best Voice Recognition Software for Raspberry Pi DIY Hacking
Best Voice Recognition Software for Raspberry Pi
This tutorial is about the best voice recognition software for Raspberry Pi and how to use it. I was able to install and test three different voice recognition systems for Raspberry Pi. Two of these softwares were dependent on the internet and were online , however the third one was offline.The three softwares which were tested were :
  1. Jasper – Voice Recognition Software.
  2. Raspberry Pi Voice Recognition by Oscar Liang.
  3. Raspberry Pi Voice Control by Steven Hickson.
Out of these three, I rate the Voice Control software created by Steven Hickson to be the most precise and potent. The Jasper system, even though it works offline , it compromises on accuracy and speed. This would be useful for systems that have no access to the internet, but a small caveat, the system takes up almost a whole 4GB memory card, so use at least an 8GB card with it.Some of its services are cumbersome and takes a lot of effort from the user to pronounce repeatedly until the system picks it up.
The softwares presented by Oscar and Steven use google voice APIs, they are very accurate and precise. Both of them also use google speech , so that the system can be manipulated to talk back and respond to your commands and queries.But, I prefer the third software because it has a simple and straight forward interface. Here, you will be able to define each of your voice commands and link them to particular tasks in the form of bash commands.These are defined inside a configuration file. A detailed tutorial explaining the installation and use of this voice recognition software for raspberry pi is given below by DIY Hacking and the video at the bottom lets you get a feeling of the voice control software before you install it.
What are the stuff required to do this project?
Hardware:
  1. Raspberry Pi model B with memory card preloaded with an OS.
  2. WiFi dongle (Optional) : Edimax EW 7811UN / LAN network cable.
  3. A USB webcam with microphone / USB microphone.
You cannot use normal microphones with audio jacks because the raspberry pi does not have a sound card. Hence, only use USB webcams with inbuilt mic or USB microphones. I am using a cheap USB webcam with an inbuilt mic.
Best Voice Recognition Software for Raspberry Pi DIY Hacking
USB Webcam with inbuilt mic
How does it work?
The software being described here uses Google Voice and speech APIs. The voice command from the user is captured by the microphone.This is then converted to text by using Google voice API. The text is then compared with the other previously defined commands inside the commands configuration file. If it matches with any of them, then the bash command associated with it will be executed. You can also use this system as an interactive voice response system by making the raspberry pi respond to your commands via speech. This is be achieved by using the Google speech API, which converts the text into speech. Here’s a block diagram showing you the basic working of the voice recognition software for raspberry pi:
Best Voice Recognition Software for Raspberry Pi DIY Hacking
Voice Recognition Software for Raspberry Pi – Working

Step 1: Checking your microphone

You need to first check whether your microphone records properly and if the mic volumes, etc are high. First check if your webcam or microphone is listed using the command “lsusb“. Check if your mic/webcam comes up in the list.
Next we need to set the mic recording volume high. To do this, enter the command “alsamixer” in the terminal. A neat graphical interface shows up, press the up/down arrow keys to set the volume. Press F6 (all), then select the webcam or mic from the list. Then again use the up arrow key to set the recording volume to high.
Best Voice Recognition Software for Raspberry Pi DIY Hacking
Alsamixer for raspberry pi
Now, you need to check if the recording takes place properly. Use the command “arecord -l” to check if your mic/webcam is listed. Then, use the command “arecord -D plughw:1,0 test.wav” to record sound. The sound will be recorded in the file “test.wav”. To listen to it, plug in your headphones to the pi and enter the command “aplay test.wav” in the terminal. If your able to hear the sound, your microphones works perfectly, else try adjusting the volumes and repeat the previous steps.

Step 2:Installing the voice recognition software for raspberry pi

This software was created by Steven Hickson and utilises Google voice API. To install this software , execute the following commands one after the other:
  • wget –no-check-certificate “http://goo.gl/KrwrBa” -O PiAUISuite.tar.gz
  • tar -xvzf PiAUISuite.tar.gz
  • cd PiAUISuite/Install/
  • sudo ./InstallAUISuite.sh
Please not that the wget command in the first line uses two dashes (- -) before “no-check”. During the installation, several questions shall pop up. You need to read these carefully and press y/n accordingly. I would recommend you to press y for all of them.Some of the questions include: Do you want to set a keyword? (Keyword is a voice command like a name, the system gets activated only when first use this command), Do you want to set filler flag to zero? (Press y, else you will always hear “Filler Fill” before every speech response from the pi) , Do you want to install youtube-dl? (A terminal service for playing youtube videos), etc. Options for changing the listening duration and system response is also presented during the installation. Read carefully each of these questions and respond accordingly.
Best Voice Recognition Software for Raspberry Pi DIY Hacking
Questions you might see while installing the voice control software for raspberry pi

Step 3:Using the voice control software and setting up your own commands

You can verify the voice to text conversion by running “./speech-recog.sh” in the directory: /home/pi/PiAUISuite/VoiceCommand. The software is activated to run continuously when you execute the command “sudo voicecommand -c” in the terminal. By default, the keyword used to activate it is “Pi” , only when you say this when its listening can you execute the other commands.Check the video below to get a feel of the software.
I would recommend changing the keyword from “Pi” to something else, as the system usually interpreted it for me as “Hi”.You can change the keyword and other voice commands and actions by opening the commands configuration file. This can be done by entering the command “voicecommand -e“.Inside this, you can see various options for setting the keyword, the speech response ,etc. Please remove the “#” before the lines in the file while changing them.
Best Voice Recognition Software for Raspberry Pi DIY Hacking
Voice commands configuration file
Here, each command is linked to a particular action. Eg: “Youtube==youtube-search …” , here when you say for example “Youtube android” , it runs the command “youtube-search android” in the bash. The “…” stands for anything you say after the command “Youtube”. In case of the voice command definition : “play  $1 season $2 episode $3 =playvideo -s $2 -e $3 $1” , here when you say for example “play Big bang Theory season 1 episode 4”, it executes the command “playvideo -s 1 -e 4 Big Bang Theory“, i.e., it plays the 4th episode of the 1st season of Big Bang Theory.
So, if you want to add a new voice command to this, for example: a voice command “Check internet” that uses “ping” to check your internet connection. Then in the configuration file, enter a line like this “Check internet==ping google.com”. It executes “ping google.com” when you say “Check internet”.
Best Voice Recognition Software for Raspberry Pi DIY Hacking
The voice control software in action
Use this system for home automation, robotics and other cool stuff. This software is quite accurate and swift for your applications.Now, the video of the voice control software in action :

IOT BASED RASPBERRY PI HOME AUTOMATION USING IBM BLUE MIX

  1 9


We all have at some point of life desired to control everything at the click of a button. May it be turning off unnecessary lights when you are not at home to detecting intruders when you are not around. This tutorial will guide you to build a simple raspberry pi home automation system that will allow you to control appliances in your home from anywhere in the world. And it will also allow you to view data from the PIR motion sensor via the internet to detect intruders. This project will be using platforms like the Raspberry Pi, IBM’s IoTF (Internet of Things Foundation) and Bluemix packages. And can be used as a perfect project to get into the world of Internet of Things. So lets get started!
What are the stuff required to do this project?
Hardware:
  1. Raspberry Pi 2 / B+.
  2. USB wifi dongle.
  3. USB keyboard and mouse.
  4. HDMI monitor and cable.
  5. Micro USB power adapter (smartphone charger).
  6. PIR motion sensor.
  7. Male-female and male-male jumpers.
  8. Breadboard.
  9. BC547 transistor.
  10. 5V SPDT relay and 1n4001 diode.
  11. LED and 220Ohm resistor.
Software:
Raspbian OS
How does it work?
If you are a beginner to Raspberry Pi, you can always use our free eBook to learn how to setup the pi and Raspbian OS. The Raspberry Pi home automation system uses client and server side python scripts. These can communicate with each other through IBM’s IoTF platform. This whole Internet of Things project can be divided into two parts:
1. Sending commands to the Raspberry Pi
The server side script running on our laptop or on a web server takes input commands from the user and correspondingly sends it to the client (Raspberry Pi). Here, we will be using commands to turn a light ON/OFF. When we pass the command to turn ON a light through the server side script, the information is relayed to the Raspberry Pi and it’s GPIO pin turns ON a relay. The system also sends status updates to the server on whether the light is ON/OFF.Raspberry Pi home automation using IBM Bluemix IoT2. Receiving data from the Raspberry Pi
In case of sending data from the PIR motion sensor connected to the Raspberry Pi, we run a script which reads the sensor through a GPIO pin and broadcasts the data through the IoTF platform. This can then be viewed through the IoTF console or through a custom web application designed using the platform.Raspberry Pi home automation using IBM Bluemix IoT
A few quick reads that will help you before you get started:
  1. The concepts of using IBM IoTF https://docs.internetofthings.ibmcloud.com/reference/concepts.html
  2. Creating applications using bluemix: documentation.
  3. Interfacing Raspberry Pi with an accelerometer sensor: IBM blog.

Step 1: Testing IBM IoTF using a simulator

First you need to sign up for a one month free trial account from IBM:https://quickstart.internetofthings.ibmcloud.com/#/. You can do that by going here. Next you need to log into: IBMIoTF page with the credentials you just created. And then you need to click on “Quickstart” from the above menu. Next, click on: “Find out more” from the “Don’t have a device?” section:
Internet of Things Raspberry Pi IBM Bluemix IoTF
Then from the new window that pops up, follow the instructions to setup the simulator or just click this link: “http://quickstart.internetofthings.ibmcloud.com/iotsensor“.
This simulator acts like the data coming from your Raspberry Pi or any other connected device, it simulates data like: temperature, humidity, etc. The simulator open up in a new tab and looks like a smartphone application:
Raspberry Pi home automation using IBM Bluemix IoT
Next, copy the MAC address from the top right corner of the simulator. Here, in this example it is: DD:2D:36:E1:C0:17. Now, paste this MAC address on the IoTF quickstart page: https://quickstart.internetofthings.ibmcloud.com/#/ or just click on the MAC address itself. You can see the data coming from the simulator in this new tab in the form of a graph. Now go back to the simulator and click on the UP/DOWN arrows on it to increase/decrease the value of temperature. And you will get to see that the graph on the quickstart page updates accordingly, and at the bottom of the page you will see the current value of temperature you have set.
Internet of Things Raspberry Pi IBM Bluemix IoTF
Step 2: Adding the Raspberry Pi to IBM IoTF
The next step is to add our Raspberry Pi device to IBM IoTF platform, so that it can recognise it. In order to do this, you need to create a device ID for the pi. To do that, check the instructions on this page under the heading: “Connect (Quickstart)“: https://developer.ibm.com/iotfoundation/recipes/raspberry-pi/. After installing the packages using the commands on the instructions page, find the device ID of your pi using this command in the terminal:
“service iot getdeviceid”. Note down the device ID.
Next log into the Bluemix console: https://console.ng.bluemix.net/ and then click on “Add Service” or “Use Service”.Internet of Things Raspberry Pi IBM Bluemix IoTF
After that scroll down to find and select the “Internet of Things” boilerplate or icon.
Internet of Things Raspberry Pi IBM Bluemix IoTF
Next, assign a name for this project and click “Create”.
Internet of Things Raspberry Pi IBM Bluemix IoTF
Now from the new page, click on “Launch Dashboard”. And follow the steps below.
Internet of Things Raspberry Pi IBM Bluemix IoTF
FYI – From next time onwards, you can just log into the IoTF page and click on the top right account section. A dropdown will come up, from there you will see “My organizations”. Click on the that,which will take you to a new page.
Internet of Things Raspberry Pi IBM Bluemix IoTF
Now, after launching the dashboard, select “Devices” from the above tabs. Then click on “+Add Device” from the page. Fill in the name of your device (anything that you want to name it) and then enter the device ID you got from the earlier steps. After doing this, you will get a Token id, please note it down or take a screenshot of the window. You will be using this Token id to create a configuration file.
Raspberry Pi home automation using IBM Bluemix IoT
Now, you can view the data coming from your pi (CPU temperature, etc) when you enter the device ID of your pi on the quickstart page. And you can also see it from the “Devices” section on your account page. Just click on the “+” symbol in the “Last Event” column to view the incoming data. Click on each of them, to see the data in detail:
Raspberry Pi home automation using IBM Bluemix IoT

Next you have to follow the steps listed under the heading: “Connect (Registered)” on this page: https://developer.ibm.com/iotfoundation/recipes/raspberry-pi/. This will initialise your Raspberry Pi with details like Organization id, Device id, Token, etc so that we can communicate with it through other applications.

Step 3: Get the API key

Now you need to create an API key for the Raspberry Pi, so that we can read data from it through other external applications. Click on the “API Keys” tab on your organisation page and click on “New API Key”. Note down the key and authentication token that is generated, this will be shown only one time, so note it down or take a picture.

Step 4: Assembling the components together for the Raspberry Pi home automation system

Raspberry Pi home automation using IBM Bluemix IoT
Based on the above connection diagram, connect the components for the Raspberry Pi home automation system. You can learn more about connecting relays here, if you are a beginner. And you can find the pin out for the BC547 transistor here. Also, check out the pin out for the Raspberry Pi here. You can connect the appliance you wish to control to the relay as shown above. One line of the light/bulb should be connected directly to power and the other line through the relay. You can use the relay guide link given above as a guide. We are using mainly three GPIO pins, which are used as follows:
  1. GPIO pin 3: To provide the control signal to BC547 which in turn activates the relay.
  2. GPIO pin 7: To monitor the status (ON/OFF) of the appliance connected to the relay.
  3. GPIO pin 11: To provide the status for intruder detection via the PIR motion sensor (0/1).

Step 5: Setting up the client and server side python scripts for the Raspberry Pi home automation system

You can clone or download the python scripts for this project from here: https://github.com/DIYhacking/IoT.git. But, please note that you have to edit both these scripts with your organisation/device details. Next, log into your Raspberry Pi and open the terminal and follow these steps:
cd /home/pi
git clone https://github.com/DIYhacking/IoT.git
Raspberry Pi home automation using IBM Bluemix IoT
client1.py
The git clone will copy the folder “IoT” from github to the pi. Next, you need to go inside that folder and edit the python script called: “client1.py”. You can use the nano editor within the terminal to add the details about your organization, deviceType, etc. So do the following commands:
cd /home/pi/IoT
nano client1.py
Go to the lines in the editor which asks for organization id, device type, etc and fill in the details. You can view these details by using this command in a new terminal window:
service iot getdeviceid
After updating your client1.py python script with all the information,
Raspberry Pi home automation using IBM Bluemix IoT
server1.py
next we need to do the same for the server1.py script. So open your laptop and clone the code files (git clonehttps://github.com/DIYhacking/IoT.git or just download it from the link) and open the editor for server1.py and add all the details about the organization, etc just like earlier for the pi. But, here there is an additional information that needs to be filled in. You also have to fill in the details of the API key (authkey and authtoken). You can get this information from Step3.
After performing the above steps, next we need to install the python IoTF packages for running the server1.py script on the laptop/webserver. To install that, perform this command:
pip install ibmiotf
You also need to check if your system has “pip” installed, if it isn’t you need to install it based on your OS.
For linux–> sudo apt-get install python-pip
For mac–> sudo easy_install pip
For windows–> Check this tutorial.

Step 6: Running and executing the Raspberry Pi home automation system

Finally, we can execute the system for running our raspberry pi home automation project. Follow the instructions for executing and viewing the output here:
First we need to stop the default IoT service running on the pi, use this command to do that:
sudo service iot stopNext, run the script on the pi using:
sudo python client1.pyAnd then from the laptop, run the server side script:
sudo python server1.py
We will be able to do two things with this system:
  1. See whether there are any intruders using the PIR motion sensor and check whether a light is ON/OFF from a internet connected device.
  2. Control an appliance/light using a remote device connected to the internet.
1. Checking the PIR motion sensor data and light status sent from the Raspberry Pi
Here we are following the same steps we used in Step 2. To do this, log into your IBM IoTF account using the same link we used earlier: https://internetofthings.ibmcloud.com/. Next, click on your account section on the top right corner and click on your organization (check out the pictures in Step2). Then, click on the “Devices” tab and next on the “+” symbol in the “Last Event” column. You will see the data being updated and on click each of those data rows, you can see the data in detail, showing the Light and Intruder status (0/1) from the Raspberry Pi home automation system:
Raspberry Pi home automation using IBM Bluemix IoT
2. Controlling an appliance by turning it ON/OFF using the server side script
Now execute your server side python script on your laptop. You can use the command:
sudo python server1.pyThis script will then ask for commands, like so:
Raspberry Pi home automation using IBM Bluemix IoT
You can use two commands to control a lamp:
To turn it ON: lighton
To turn it OFF: lightoff
Type in “lighton” and hit enter, you will see that in a few seconds the relay and LED connected to the Raspberry Pi home automation system gets activated. Whatever appliance you had connected to the relay will be turned ON. And on the terminal of your laptop you will see the data generated from the Raspberry Pi like in the picture above.
Next, enter the command “lightoff” to disable the relay and LED and correspondingly your appliance turns OFF.
Potentially, you can create a webpage and a HTML button and run this script when the button is clicked to control appliances through online webpages. Check out python and HTML integration to do that. And you will be able to control appliances in your home from any part of the world.So thats it guys, I hope you guys come up with really cool project ideas to make use of this powerful platform from IBM. And you can post your suggestions and queries in the comments section below :) Now check out a video showing the demo of the raspberry pi home automation system: