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.
The library has recently undergone a complete rewrite and improvement, so we will cover how to install and utilize the updated version.
Yowsup is a Python library that enables logging into and using the WhatsApp service. It provides all the functionalities of an official WhatsApp client, allowing you to build a fully-customized WhatsApp application. We will explore how to install Yowsup and leverage its capabilities to create a custom WhatsApp client with full access to the service’s features.
You need:
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
Update firmware
sudo rpi-update
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
cd yowsup
and install the library with the command
sudo python setup.py install
Step 2: Registration
After installing the library, the next step is to register the device for WhatsApp usage. Yowsup includes a cross-platform command line interface called yowsup-cli that streamlines the registration process. It offers registration options and provides some demonstrations, such as a command line WhatsApp client. Through yowsup-cli, we can easily register our devices to use WhatsApp programmatically via the library.
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
Warning
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
cd /home/pi/yowsup
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.
Source: WhatsApp on Raspberry Pi