WhatsApp is one of the most popular and widely used messaging app but its only available for Smartphones and don’t work on computers. But there is a way to install it on palm sized computer Raspberry Pi and it works quite well using command line interface.
There is a Python library to access all capabilities of an official WhatsApp on Raspberry pi - Yowsup. It enables you to use your WhatsApp account to exchange messages without the original app with your contacts. This library allows the user to create a full-fledged custom WhatsApp client on Raspberry Pi.
Previously, it was easy to install WhatsApp on Raspberry using this library but from last few months this library is completely rewritten and many modifications have been done in the library, so installing process has become more tedious than before. Here we will explain the complete process of installing and configuring WhatsApp on Raspberry Pi.
For activating the WhatsApp on pi, you will need a new Phone no. as it won’t work with currently running WhatsApp no. So unfortunately for configuring Yowsup we still need a phone and a SIM card, but after the first step you can leave it alone.
So, let’s get started.
- Raspberry Pi 2 or newer (with Raspbian Jessie or newer installed in it).
- Working Internet Connection
Here, we will use SSH to access Raspberry Pi on the laptop. You can use VNC or Remote Desktop connection on the laptop, or can connect your Raspberry pi with a monitor. Learn more about setting up Raspberry Pi headlessly here without a monitor.
Installing Yowsup (WhatsApp) Library in Raspberry Pi
1. First thing that we have to do is update and upgrade our Pi. It is good practice to update the Pi before installing any new library or package so that you can be sure to have most recent library. Run the below command to perform the update.
sudo apt-get update && sudo apt-get upgrade
Hit ‘y’ wherever ask for yes/no and wait for completion.
2. Install following dependencies as required by Yowsup library.
sudo apt-get install python-dev libncurses5-dev sudo apt-get install build-essential libssl-dev libffi-dev python-dev
Now, install cryptography packages (required for encrypting the data used in WhatsApp) which is already installed in our Raspberry Pi but the version is not compatible as required by Yowsup library.
So, install required version using below command
pip install cryptography
3. Download the Yowsup library from GitHub using below command
git clone git://github.com/tgalal/yowsup.git
4. Go to yowsup directory using cd yowsup and install the downloaded library using following command
sudo python setup.py install
5. Now, we are ready to setup the WhatsApp account. First check whether the library is installed correctly or not. For this, run the given command
If you are getting the below output then library is installed correctly.
Setup WhatsApp Account on Raspberry Pi
After installing WhatsApp on Raspberry Pi, its time to activate and configure the WhatsApp on pi.
1. Save the country code “cc” and phone number in a file so that Yowsup client can fetch this information for authorization. Open nano editor using sudo nano config and save the info using ctrl+x as shown below.
sudo nano config cc=91 phone=91xxxxxxxxxx
91 is the cc for India if you are outside of India use your cc and replace phone with your phone number. Make sure the phone number entered is not used by another WhatsApp account and the SIM card should be in phone because you will receive registration code in next step.
2. Now, register your WhatsApp account using below command.
yowsup-cli registration --config config --requestcode sms
After running the above command you will receive the six digit code through an SMS.
3. Use that code to register the phone number using the command
yowsup-cli registration --config config --register xxx-xxx
Replace xxx-xxx with the code you received on your phone.
After a second or two, you'll receive a response from WhatsApp on the Pi terminal as shown below
The response contains the password for your WhatsApp. The ID, shown by the arrow in above image, is your password without double quotes. Save this password in the same config file.
So, open the config file using nano editor and paste the id as
Now, config file will look like this. Save this file.
Running the WhatsApp on Raspberry Pi
yowsup-cli demos --yowsup --config config
You will see following response from WhatsApp. We have to login now. Enter “/L” and hit enter. For exploring more commands you can type /help.
If you are failed to login, restart your Raspberry Pi.
2. After login you are all set to send and receive messages.
For sending message to other WhatsApp number type the following command.
/message send 91********** "Your message"
Replace ********** with the receiver WhatsApp number. Sent and received messages will be shown on the same terminal as shown below.
So this is how the Raspberry Pi can be converted into a WhatsApp client to send and receive messages from another WhatsApp number. We can also implement the Home Automation using WhatsApp messages but the Yowsup library is not working properly for that purpose and the improvement is going on to use this functionality .