Introduction: WhatsApp Message From Phidgets SBC

Picture of WhatsApp Message From Phidgets SBC

In the last tutorial, we used the Phidgets SBC for a small alarm system, which detects the presence of a person and sent us an e-mail.
In this tutorial the SBC will send us a message on WhatsApp instead of an e-mail.

We need:
1073_0 - PhidgetSBC3

1111_0 - Motion Sensor

A valid number to register WhatsApp

Yowsup library

Step 1: Yowsup

Picture of Yowsup

Yowsup is a python library that allows you to do all the previous in
your own app. Yowsup 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 solid example of Yowsup's usage is Wazapp. Wazapp is full featured Whatsapp client that is being used by hundreds of thousands of people around the world. Yowsup is born out of the Wazapp project. Before becoming a separate project, it was only the engine powering Wazapp. Now that it matured enough, it was separated into a separate project, allowing anyone to build their own Whatsapp client on top of it. Having such a popular client as Wazapp, built on Yowsup, helped bring the project into a much advanced, stable and mature level, and ensures its continuous development and maintaince.

Yowsup also comes with a cross platform command-line frontend called yowsup-cli. yowsup-cli allows you to jump into connecting and using Whatsapp service directly from command line.

Yowsup require python-dateutil, then the first thing to do is

apt-get update  
apt-get upgrade  
apt-get install python-dateutil

Then install git-core we need to download the library Yowsup

apt-get install git-core

Download the library with the command

git clone git://github.com/tgalal/yowsup.git

navigate to the folder

cd /yowsup/src

and edit the file config.example

nano config.example

You should see something like this

######## Yowsup Configuration file #####################
  # Lines are commented using # and ;
  # Your configuration should contain info about your login credentials to Whatsapp. This typically consist of 3 fields:\n
  # cc:           Your country code. See <a rel="nofollow"> http://www.ipipi.com/help/telephone-country-codes...</a>>
  #               If not set, it will be autodetected from phonenumber
  # phone:        Your full phone number including country code, without '+' or '00'
  # id:           This field is used in registration calls (-r|-R|-e), and for login if you are trying to use an existing account that is setup
  #               on a physical device. Whatsapp has recently deprecated using IMEI/MAC to generate the account's password in updated versions
  #               of their clients. Use --v1 switch to try it anyway. Typically this field should contain the phone's IMEI if your account is setup on
  #               a Nokia or an Android device, or the phone's WLAN's MAC Address for iOS devices. If you are not trying to use existing credentials
  #               or want to register, you can leave this field blank or set it to some random text.
  # password:     Password to use for login. You obtain this password when you register using Yowsup.
  ###################################################### 
   
  ## Actual config starts below ## 
   
  cc=39 #if not specified it will be autodetected
  phone=39xxxxxxxxx
  id=xxxxxxxxxxxxxxx
  password=xxxxxxxxxxxxxxxxxxxx=

Edit file with your data

cc: is your country code

phone: is your phone number, preceded by the country code

id: IMEI or MAC Address of a phone, or a random text

password: You obtain this password when you register using Yowsup

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.

Ok, after setting up our file we ask for the code number with the command

python yowsup-cli -c config.example --requestcode sms

If all goes well you should receive on your phone a sms message with a code like xxx-xxx

Then send a message to request registration with this command, (replace xxx-xxx with code you received)

python yowsup-cli -c config.example --register xxx-xxx

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

Enter the password you received in the file config.example, then test the application with this command (replace xxxx with your number recipient)

python yowsup-cli -c config.example -w -s 39xxxxxxxxx "Message sent from Phidgets SBC, read complete tutorial www.emmeshop.eu/blog" 

If everything is ok the recipient will receive the message

Step 2: Alarm System With Phidgets

Picture of Alarm System With Phidgets

Edit the code of the tutorial Alarm System with Phidgets

Create a new file

nano /usr/userapps/Alarm/sendWhatsapp.sh

with this content

#!/bin/sh
  cd /yowsup/src
  python yowsup-cli -c config.example -w -s 39xxxxxxxxx "Message sent from Phidgets SBC, read complete tutorial www.emmeshop.eu/blog"

replace xxxxxxx with recipient's number

Then modify sendEmail function in sbc-email.c

int sendEmail()
  {
      time(&now);
      dif = difftime(now, lastTimeEmail);
      if (dif >= tmrEmail)
      {
          //system("./sendMail.sh");
          system("./sendWhatsapp.sh");
          time(&lastTimeEmail);
      }
      else
      {
      }
      
      return 0;
  }

Compile and restart the project.

Now when the sensor detects the presence of a person will send us a message on WhatsApp.

This is a simple example, in the next tutorials we will deepen the use of Phidgets SBC to make it even more interactive.

Follow us on social to stay informed.
www.emmeshop.eu

Comments

grompot (author)2015-03-04

looks intresting. Will it be possable to send whatsapp text to the PhidgetSBC.

emmeshop (author)grompot2015-03-06

Try this

http://www.emmeshop.eu/blog/?q=node/34

seamster (author)2014-11-03

Great project. Thanks for sharing this!