Monday, November 24, 2014

Whatsapp on your Raspberry Pi: Yowsup

Did you think Whastapp is only for your smartphone? Wrong! You can use it also on your RPi and it works quite well!

Yowsup is a python library developed for accessing Whatsapp without the original app (and on a machine that is not a smartphone, just like a RPi).

Unfortunately you still need a smartphone and a sim card for configuring Yowsup, but after the first steps you can leave it alone.

The first thing to do is an update of the RPi. It's always a good practice to make an update before installing a new software so you can be sure to have the most recent libraries.

It could also be a good idea to upgrade RPi firmware, but it's not really needed for installing Yowsup, so i will skip it this time.

To make an update type as usual:

sudo apt-get update && sudo apt-get upgrade

Eventually answer Yes to continue and wait for the tasks to complete.

Now you have to install some dependencies used by Yowsup installation:

sudo apt-get install python-dev libncurses5-dev

Now you can download Yowsup from the git repository:

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

and wait for completion. If there are no issues, you can find a subfolder named yowsup.

Just after downloading the package you need to execute the setup. This way all the needed dependencies will be downloaded automatically:

cd yowsup
sudo python setup.py install

The setup will take a while, so be prepared to wait several minutes.

Before using Yowsup you need to create the configuration file using a text editor. Note that You can put the configuration file wherever you wish. Just remember that you will have to specify the path when using Yowsup.

In case you are just upgrading from old version to the new Yowsup 2, you can skip this steps and reuse the old configuration file.

nano config

Of course you can also use another name for the file.

Into this file you have to type four rows:

cc=00
phone=00tttttttttt
id=0000000000
password=

Let's see what they are for and what you need to change to match your sim card:

In the first line you have to specify the country code of the phone number without the +. For example if you have a number from Italy you have to type:

cc=39

if your number is from France just type:

cc=33

and so on. Next you specify the phone number with the country code, but without the +. Again as an example, a number from Italy will be something like:

phone=391111111111

One thing you really have to consider: the number cannot be used for Whatsapp on another device (smartphone or whatever) as Whatsapp can have just one account for every telephone number.

The next two rows can be ignored for a while.

Now it's time to create the account and to do this you need a phone that can receive sms. You could do this also with a voice call if there are problems with the sms.

Type (from the yowsup/src folder):

python yowsup-cli -c config -r sms

If your configuration file is placed into another folder or has a different name, just put the right path after the -c parameter. This has to be done every time you invoke yowsup-cli.

With this command you are requesting the pass code from Whatsapp to enable the account. After a while you should receive the sms with the code.
To register type:

python yowsup-cli -c config --register 123-456

where 123-456 is the received code. If everything went right, Yowsup should display a text like the following:

status: ok
kind: free
pw: jg7w4fewhb7TFGErcm2sQCfSLgXM=
price: 0,89
price_expiration: 1362803446
currency: EUR
cost: 0.89
expiration: 1391344106
login: 391111111111
type: new

Copy the text after pw: up to the = from that reply. This is the password that we need to put in the configuration file.

Edit the file and in the last line put the password. Now the configuration should look like this:

cc=00
phone=00tttttttttt
id=0000000000
password=jg7w4fewhb7TFGErcm2sQCfSLgXM=

Yowsup is now ready to send and receive Whatsapp messages. Using yowsup-cli you can test some demo functions. For example let's send a message:

python yowsup-cli demos -c config -s 392222222222 "Message"

where 392222222222 is the destination number and "Message" is the text you wish to send.

Another demo function waits for a message and reply with the same message to the sender:

python yowsup-cli demos -c config -e

For all the options you can refer to Yowsup website.

From time to time Whatsapp will update communication protocols, so remember to check from the git repository if there are update files. In that case just download them and replace the old ones.

25 comments:

  1. Nice and clear toturial! Is it also possible to send picture of IP cam to mobile phone? If yes, how?

    ReplyDelete
  2. Thanks!

    Yes, it's possible, but you have to change yowsup-cli script to be able to send pictures. Sooner or later i will post an article about this, but if you need it now you can take a look here: http://sirpoot.blogspot.com/2014/08/using-yowsup-to-send-pictures-to-group.html

    In this blog i found the modified scripts to send pictures using yowsup-cli, so you just need to save a picture from the camera and the use yowsup-cli to send it.

    If you are skilled with python you can also take and send the picture using just a single script.

    If you need some help using the modified yowsup-cli, just contact me!

    ReplyDelete
    Replies
    1. Great! I will check the link and look forward to seeing your script.

      Regards,

      Joey

      Delete
    2. how to send mms prloaded images

      Delete
  3. How to send picture,above mentioned is not work for me

    ReplyDelete
  4. With instructions in this post you can only send or receive text. To send pictures you should take a look at the post http://rpihome.blogspot.it/2015/02/sending-pictures-with-yowsup.html where you can also download the python class for media files...

    ReplyDelete
  5. No handlers could be found for logger "ypwsup.stscks.yowstack"
    Authentication Error: not-authorized

    pls replay
    thanks

    ReplyDelete
  6. Hi, many thanks for this nice Tutorial. Because of low knowledge of Python-programming: could you give me a code-snippet how to react on a certain received message. RPi received message with content "2+2" and then send back "Result is 4" e.g.. again, many thanks in advance, Dirk !

    ReplyDelete
    Replies
    1. Thanks!
      Just take a look at the post http://rpihome.blogspot.com/2015/01/using-whatsapp-for-home-automation.html where you can find some info on how to make a (simple) process to the incoming message and reply with the requested answer.
      If you need to make a more complex analysis you surely can find several websites about that topic that can help you much more than I could...

      Delete
  7. Hi Carlo, many thanks for yor very fast response! Seems to be a webpage which I unfortunately couldn't find up to date....
    Again, many thanks!
    Dirk

    ReplyDelete
    Replies
    1. It's the link for the next post of this blog.

      Delete
  8. I'm a bit of a noob with linux, so I'm having trouble with sending the message. Everything up until this has worked perfectly, but as soon as I go to send a message, I get something like this:

    [connected]:Sent: XXXXXXXXX
    [connected]:
    IQ:
    ID: 2
    Type: result
    from: XXXXXXXXXX@s.whatsapp.net

    then a couple minutes later, I'll get the same thing, except the ID is a 3. Like this:
    IQ:
    ID: 3
    Type: result
    from: XXXXXXXXXX@s.whatsapp.net

    I have allowed it to go until 130, and the message still isn't received. Does anyone know what's going on?

    -LTC

    ReplyDelete
    Replies
    1. Unfortunately I never saw something like that... Maybe it's a version issue. I see that there have been several update to Yowsup (one just today), so just try to reinstall it (you can keep the configuration file as the password should not be changed).

      Delete
  9. Downloaded yowsup lib and register to whatsapp successfully, but not able to send message.

    python yowsup-cli registration --register 590-977 --phone 91XXXXXXXXX --cc 91

    INFO:yowsup.common.http.warequest:{"status":"ok","login":"917676733041","pw":"SdodVaGlhihaKod3CFqGImfEapo=","type":"existing","expiration":1463491432,"kind":"free","price":"\u20b9 55","cost":"55.00","currency":"INR","price_expiration":1447154413}

    status: ok
    kind: free
    pw: XXXXXXXXXXXXXXXXXXXXXX=
    price: ₹ 55
    price_expiration: 1447154413
    currency: INR
    cost: 55.00
    expiration: 1463491432
    login: 91XXXXXXXXX
    type: existing

    Up to here its fine. But now on sending messages I am getting following error messages.

    pi@raspberrypi ~/yowsup $ python yowsup-cli demos -c config -s 917676733041 "Message"
    Traceback (most recent call last):
    File "yowsup-cli", line 323, in
    if not parser.process():
    File "yowsup-cli", line 231, in process
    self.startSendClient()
    File "yowsup-cli", line 279, in startSendClient
    not self.args["unmoxie"])
    File "/home/pi/yowsup/yowsup/demos/sendclient/stack.py", line 24, in __init__
    from yowsup.layers.axolotl import YowAxolotlLayer
    File "/home/pi/yowsup/yowsup/layers/axolotl/__init__.py", line 1, in
    from .layer import YowAxolotlLayer
    File "/home/pi/yowsup/yowsup/layers/axolotl/layer.py", line 2, in
    from .protocolentities import SetKeysIqProtocolEntity
    File "/home/pi/yowsup/yowsup/layers/axolotl/protocolentities/__init__.py", line 3, in
    from .iq_keys_get_result import ResultGetKeysIqProtocolEntity
    File "/home/pi/yowsup/yowsup/layers/axolotl/protocolentities/iq_keys_get_result.py", line 3, in
    from axolotl.state.prekeybundle import PreKeyBundle
    ImportError: No module named axolotl.state.prekeybundle


    pi@raspberrypi ~/yowsup $ yowsup-cli demos --help
    Traceback (most recent call last):
    File "/usr/local/bin/yowsup-cli", line 4, in
    import pkg_resources
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2707, in
    working_set.require(__requires__)
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 686, in require
    needed = self.resolve(parse_requirements(requirements))
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 584, in resolve
    raise DistributionNotFound(req)
    pkg_resources.DistributionNotFound: pillow

    Can you please tell me what I am doing wrong?

    ReplyDelete
  10. Downloaded yowsup lib and register to whatsapp successfully, but not able to send message.

    python yowsup-cli registration --register 590-977 --phone 91XXXXXXXXX --cc 91

    INFO:yowsup.common.http.warequest:{"status":"ok","login":"917676733041","pw":"SdodVaGlhihaKod3CFqGImfEapo=","type":"existing","expiration":1463491432,"kind":"free","price":"\u20b9 55","cost":"55.00","currency":"INR","price_expiration":1447154413}

    status: ok
    kind: free
    pw: XXXXXXXXXXXXXXXXXXXXXX=
    price: ₹ 55
    price_expiration: 1447154413
    currency: INR
    cost: 55.00
    expiration: 1463491432
    login: 91XXXXXXXXX
    type: existing

    Up to here its fine. But now on sending messages I am getting following error messages.

    pi@raspberrypi ~/yowsup $ python yowsup-cli demos -c config -s 917676733041 "Message"
    Traceback (most recent call last):
    File "yowsup-cli", line 323, in
    if not parser.process():
    File "yowsup-cli", line 231, in process
    self.startSendClient()
    File "yowsup-cli", line 279, in startSendClient
    not self.args["unmoxie"])
    File "/home/pi/yowsup/yowsup/demos/sendclient/stack.py", line 24, in __init__
    from yowsup.layers.axolotl import YowAxolotlLayer
    File "/home/pi/yowsup/yowsup/layers/axolotl/__init__.py", line 1, in
    from .layer import YowAxolotlLayer
    File "/home/pi/yowsup/yowsup/layers/axolotl/layer.py", line 2, in
    from .protocolentities import SetKeysIqProtocolEntity
    File "/home/pi/yowsup/yowsup/layers/axolotl/protocolentities/__init__.py", line 3, in
    from .iq_keys_get_result import ResultGetKeysIqProtocolEntity
    File "/home/pi/yowsup/yowsup/layers/axolotl/protocolentities/iq_keys_get_result.py", line 3, in
    from axolotl.state.prekeybundle import PreKeyBundle
    ImportError: No module named axolotl.state.prekeybundle


    pi@raspberrypi ~/yowsup $ yowsup-cli demos --help
    Traceback (most recent call last):
    File "/usr/local/bin/yowsup-cli", line 4, in
    import pkg_resources
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2707, in
    working_set.require(__requires__)
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 686, in require
    needed = self.resolve(parse_requirements(requirements))
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 584, in resolve
    raise DistributionNotFound(req)
    pkg_resources.DistributionNotFound: pillow

    Can you please tell me what I am doing wrong?

    ReplyDelete
  11. i am not able to send mms, how to send mms manually mean with out cam any loaded image or copied image in PI

    ReplyDelete
    Replies
    1. Yowsup (whatsapp) cannot send mms. But if you mean sending an image with whatsapp, you can take a look at some post after this one...

      Delete
  12. /usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning: /home/dileep/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
    warnings.warn(msg, UserWarning)
    Traceback (most recent call last):
    File "yowsup-cli", line 323, in
    if not parser.process():
    File "yowsup-cli", line 229, in process
    self.startEcho()
    File "yowsup-cli", line 264, in startEcho
    stack = echoclient.YowsupEchoStack(credentials, not self.args["unmoxie"])
    File "/home/dileep/yowsup/yowsup/demos/echoclient/stack.py", line 20, in __init__
    from yowsup.layers.axolotl import YowAxolotlLayer
    File "/home/dileep/yowsup/yowsup/layers/axolotl/__init__.py", line 1, in
    from .layer import YowAxolotlLayer
    File "/home/dileep/yowsup/yowsup/layers/axolotl/layer.py", line 3, in
    from axolotl.util.keyhelper import KeyHelper
    File "/usr/local/lib/python2.7/dist-packages/python_axolotl-0.1.7-py2.7.egg/axolotl/util/keyhelper.py", line 3, in
    File "/usr/local/lib/python2.7/dist-packages/python_axolotl-0.1.7-py2.7.egg/axolotl/identitykeypair.py", line 1, in
    File "/usr/local/lib/python2.7/dist-packages/python_axolotl-0.1.7-py2.7.egg/axolotl/state/storageprotos.py", line 9, in
    ImportError: cannot import name symbol_database

    ReplyDelete
    Replies
    1. yowsup-cli is not made by me, but by the creator of yowsup, so maybe you should ask him.
      Anyway I can think about few things:
      - be sure to have the latest yowsup installed (you need to check for updates regularly and reinstall yowsup every time)
      - you installed ywosup on debian jessie. I found several issues with many softwares using that distro and that's why I'm still using wheezy...
      - you can try launching yowsup-cli using sudo, I do not really think that this could solve the problem, but you can try.

      Delete
  13. I'm trying to get my Whatsapp going but when I get to the command to request a code it returns an error of "fail:old_version". Any suggestions for what to do?

    ReplyDelete
    Replies
    1. It seems that you are using an old yowsup version, or maybe something changed in the whatsapp servers and yowsup has not been updated yet...
      Try to wait a comple of days and reinstall yowsup. You can also try to check in the yowsup site for news about updates...

      Delete
    2. Thank you!

      Delete
  14. hola buenas noches he enviado varios mensajes pero ahora me salio error de autenticacion
    exactamente dice Authentication Error: not-authorized como puedo corregir esto que debo hacer muchas gracias de ante mano

    ReplyDelete
    Replies
    1. If I have undesrtood well your question (I do not speak spanish), you may try to register again the telephone number you use for the RPi.
      If this do not work, maybe Whatsapp team blocked that number. Remember that actually you should use whatsapp only with their app on a smartphone (or now also by web interface). Every other use is not allowed, but if you do not send too many messages they should not be aware of that. In case of a too high traffic for normal human interaction they may note it and disable the number...

      Delete
  15. hola buen dia
    yo tenia el mismo problema y este consistia en que el numero de telefono lo tenia mal escrito, cuando te registra el numero te lo devuelve con 5214441 agrega un 1, solo se puse como me lo mostro y se soluciono

    ReplyDelete

Note: Only a member of this blog may post a comment.