Intro: WhatsApp on Raspberry Pi
In this tutorial we will see how to use WhatsApp with Raspberry Pi.
We will use the Yowsup library we had already used in these tutorials: WhatsApp message from Phidgets SBC , Phidgets WhatsApp - ask the status of your sensors.
These days the library has been completely rewritten and improved, so we will see how to install it and use it.
Yowsup is a python library that allows you to login and use the WhatsApp service and provides you with all capabilities of an official WhatsApp client, allowing you to create a full-fledged custom WhatsApp client.
a Raspberry Pi B or B+, with the latest version of Raspbian, or our MIcroSD Card 8GB Class 10 Raspbian preinstalled.
Step 1: Installation
Update the packages with
sudo apt-get update
sudo apt-get upgrade
Prepare the system with the necessary components to Yowsup
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
Download the library with the command
git clone git://github.com/tgalal/yowsup.git
navigate to the folder
and install the library with the command
sudo python setup.py install
Step 2: Registration
After installing the library we have to register the device to use WhatsApp. Yowsup comes with a cross platform command-line frontend called yowsup-cli. It provides you with the options of registration, and provides a few demos such as a command line client.
WhatsApp registration involves 2 steps. First you need to request a registration code. And then you resume the registration with code you got.
Request a code with command
python yowsup-cli registration --requestcode sms --phone 39xxxxxxxxxx --cc 39 --mcc 222 --mnc 10
Replace with your data ,
cc is your country code in this example 39 is for Italy,
mcc is Mobile Country Code check your here
mnc is Mobile Network Code check your here
You should receive on your phone a sms message with a code like xxx-xxx
Send a message to request registration with this command, (replace xxx-xxx with code you received)
python yowsup-cli registration --register xxx-xxx --phone 39xxxxxxxxxx --cc 39
If all goes well, we should get a message like this
status: ok kind: free pw: xxxxxxxxxxxxxxxxxx= price: € 0,89 price_expiration: 1416553637 currency: EUR cost: 0.89 expiration: 1445241022 login: 39xxxxxxxxxxx type: existing
WhatsApp requires the registration of a number, and with that number you can use WhatsApp on only one device at a time, so it is preferable to use a new number.
WhatsApp can be used on one device at a time and if you will make many attempts to register the number, it could be banned. We recommend you using Telegram, see our tutorial
Step 3: Utilization
Create a file to save your credentials
sudo nano /home/pi/yowsup/config
with this content
## Actual config starts below ## cc=39 #if not specified it will be autodetected phone=39xxxxxxxxxx password=xxxxxxxxxxxxxxx=
Ok, we're ready for the test, Yowsup has a demo application in /home/pi/yowsup/yowsup/demos
Navigate to yowsup folder
Start yowsup-cli demos with the command
yowsup-cli demos --yowsup --config config
You can see Yowsup prompt
If type "/help" you can see all available commands
First use the '/L' command for login; to send a message type
/message send 39xxxxxxxxxx "This is a message sent from Raspberry Pi"
replace xxx with the recipient number
If you respond with a message it will be displayed on Raspberry.
The possibilities of use are endless, for example you could use
WhatsApp to send messages in the home automation system seen in the tutorial Home Automation Raspberry and Phidgets part 2 or Home Automation Raspberry and Phidgets part 3
Follow us on social to stay informed.