WhatsApp is an instant messaging application originally developed for iPhones. It quickly emerged as a cross-platform messenger application and is now the most popular instant messaging application. Due to projects like Android for x86 and other raspberry-pi projects, a number of users were using WhatsApp from their PCs which ensured them high speed connectivity. Thus WhatsApp is no longer limited to smartphones but can be used from a number of devices. This trend has even led WhatsApp to come up with WhatsApp for web. Raspberry Pi is certainly one of such devices.
You can say Raspberry Pi is a very small computer. It belongs to the family of single board computers(SBC). Some of the other popular SBC devices are Arduino, Beaglebone and UDOO. As the name suggests SBCs are computers that are built on a single circuit board. Every fundamental part of a computer – processor, memory and I/O units are embedded within that circuit board which nowadays is usually of the size of a credit card.
Why WhatsApp on Raspberry Pi?
Raspberry Pi is not just a small computer. It has the capability to connect with the outside world. Using Raspberry Pi one can make use of sensors, cameras and many other I/O devices to design applications that interact with the outside environment. Since WhatsApp is the most popular media for communication among smartphone users, using WhatsApp on Raspberry Pi will be very advantageous to those who come up with such applications.
Requirements for using WhatsApp on Raspberry Pi
In this tutorial we assume you have Raspberry Pi B or B+ that runs Raspbian on it. If you do not know how to install Raspbian you can refer to some of our articles on Raspberry Pi like the one accessible from the link below.
Steps for using WhatsApp on Raspberry Pi
Step 1:- Installation of necessary packages
To use WhatsApp on Raspberry Pi we will need Yowsup which is a Python library that lets you access all the functionalities of WhatsApp on Raspberry Pi just as you would from the official client app on your smartphone. It is recommended that you update all the packages before you install new packages. It has been mentioned in the above article that you can do so with the help of apt – package manager used in Debian and Debian-based operating systems.
Once you are done updating the packages you may update the firmware.
Command :- sudo rpi-update
Note :- Those who are not familiar with Gnu\Linux may wonder what this sudo is? It gives a user elevated privileges much like the administrative privileges in Windows. The article will have many commands beginning with sudo. You may not start every such command with sudo. Instead you can be the super user called root by typing su and then entering the root password. Then, you can ignore sudo and just type in the rest of the commands.
To install Yowsup you need to install certain packages. As apt is the package manager in Raspbian you can use the apt-get install tool to install packages.
sudo apt-get install python-dateutil sudo apt-get install python-setuptools sudo apt-get install python-dev sudo apt-get install libevent-dev sudo apt-get install ncurses-dev
The Yowsup library can then be downloaded.
Command :- git clone git://github.com/tgalal/yowsup.git
Use cd command to get into the Yowsup folder and install the library.
cd yowsup sudo python setup.py install
Step 2 :- WhatsApp registration
To register with WhatsApp you do not have a GUI but you can make use of a command line utility provided by Yowsup – yowsup-cli. To use it you need to know your country code(cc), mobile country code(mcc) and mobile network code(mnc). You may be familiar with the country code which you see in the beginning of phone numbers. To find mcc and mnc visit the link below.
Command :- python yowsup-cli registration --requestcode sms --phone 91xxxxxxxxxx --cc 91 --mcc 405 --mnc 035
While entering phone number keep in mind that you can use WhatsApp for one number on one device only. Do not use a number that you use for you daily WhatsApp messaging.
You will receive a code like your normal WhatsApp registration process. Send back this code using the following command. The code is to be entered by replacing the ‘x’s after register.
Command :- python yowsup-cli registration --register xxx-xxx --phone 91xxxxxxxxxx --cc 91
If your registration is successful you will get a confirmation message.
Step 3:- Using WhatsApp
To use WhatsApp you will need to enter your phone number and password. You can save them on a config file inside the Yowsup folder. Use nano, a command line text editor for the same.
Command :- sudo nano /home/pi/yowsup/config
Add the following lines into the config file.
## Actual config starts below ## cc=39 #if not specified it will be autodetected phone=39xxxxxxxxxx password=xxxxxxxxxxxxxxx
To begin using WhatsApp use the yowsup-cli demo.
Command :- yowsup-cli demos --yowsup --config config
You will be greeted with the Yowsup prompt. To login you may enter ‘/L’ and enter your login credentials you saved in the config file. You can see a list of commands by typing ‘/help’. Use the /message command to send a message to your desired number.
Command :- /message send 91xxxxxxxxxx "Your message"
The replies will be displayed on your Raspberry Pi.
You can use WhatsApp on Raspberry Pi as an efficient but cheap communication media for sending alerts or activation messages in your raspberry-pi projects related to automation, monitoring or surveillance. Thus the applications for WhatsApp on Raspberry Pi are endless.