Sending messages through Signal or Whatsapp

Earlier I described how to send messages from your ESP8266 (or ESP32 for that matter) via the Telegram message app.
Signal is a slightly less known app that is getting more and more popular and it is also possible to send messages from your microcontroller through that app. It is even simpler (in my humble opinion than via Telegram).
Here is what to do:
install the messenger app on your phone and register.
Add the number “+34 603 21 25 97” to your contact list and give it a name (let’s say ‘Signal Bot’)

Yes, the SignaBot has Whatsapp too


Send the following message to that contact:
“I allow callmebot to send me messages”

You should get a reply “New user registered”, followed by an API key

It is now possible to send messages to your phone with https:/api.callmebot.com/signal/send.php?phone=<yourphonenumber>&apikey=xxxxxx&text=This+is+a+test

So suppose your international phonenumber =+31612345678 and your Api=123456, and your message is “Hello World”, then the call will become:

https:/api.callmebot.com/signal/send.php?phone=+31612345678&apikey=123456&text=Hello+World

Sending pictures is possible like this

https://api.callmebot.com/signal/send.php?phone=+31612345678&apikey=123456&image=https://arduinodiy.files.wordpress.com/2021/07/signal.jpg

Currently it is not possible yet to send messages to Signal, but that supposedly is in the making.

Program
A https connection is necessary, which the ESP8266/ ESP32 can do. Unles you plan to send highly classified material, it is easiest to do away with certificates or fingerprint and use ‘client.setInsecure();’
You can download the program here.

Just a few remarks: My first version of the program worked immediately. However, it did send one message, and somehow it would never send another message. Tried several solutions, but none brought it back to life. Then I picked a basic example of Ivan Gorotkov that I adapted to use with setInsecure() rather than with fingerprint.
As Ivan’s core code was virtually akin to my first program, albeit with some checks on the http request….it did not work. Curious about what the request reply was (hoping to find an indication of the problem), I started fiddling a bit with the cut-off character. Normally this was a “\n”, but that is not very helpful if the first character is in fact a return. To my surprise, using another character, suddenly brought the program back to life and it has been working reliable since (albeit that one time a message took a bit long to arrive). Now it should not really matter in what way i read the reply string in order for the program to function properly, but it does, so I suspect there is a bit of a timing issue before the connection is closed. If anybody can give some insight in this i would be glad to hear it.

Whatsapp

The same approach works for Whatsapp as well:

Note that the https request string is slightly different from the one used in Signal. (It is also possible to send messages from your ESP8266 through WhatApp via Twilio and Webhooks)

Telegram & messenger
The ‘callmebot’ supposedly works with telegram and facebook messenger as well.
As far as telegram goes, the approach there is a bit different.
Make sure you have a usename set in Telegram (in ‘settings’. I found this is easiest through a browser)
Authorize callmebot through this link. Or, you can start the bot sending /start to @CallMeBot_txtbot.
The https request to send is:
https://api.callmebot.com/text.php?user=@yourusername&text=This+is+a+test+from+CallMeBot

Then send messages with this call

https://api.callmebot.com/text.php?user=@yourusername&text=This+is+a+test+from+CallMeBot

mind you though that telegram als has its own bot service I refer to that one at the beginning of this article.
As i do not use facebook, I cannot really try that out, but the procedure is described here.

10 thoughts on “Sending messages through Signal or Whatsapp”

    1. Not yet possible but as far as i am informed that will be added in near future such that e.g. you can switch a lamp through signal. Kinda akin to whaf the telegrambot can do

      1. I read that the same bot can be used with whatsapp in the same manner, still one way communication.
        This mean that the bot is mantained by another company where the Telegram bot is mantained by Telegram. Anyway it is very simple, much much simpler than the Telegram bot.

      2. Yes ‘callmebot’ maintains it. I added the procedure for Whatsapp as well
        Ofcourse the TelegramBot has more possibilities and it has a library to do all the hard work

  1. Hello,
    thank you for the instruction. Would like apply this sample but I cannot import:
    #include

    Error message I get is the following:

    …./src/SignalBot.ino:11:10: fatal error: credentials.h: No such file or directory

    *********************************************************************
    * Looking for credentials.h dependency? Check our library registry!
    *
    * CLI > platformio lib search “header:credentials.h”
    * Web > https://platformio.org/lib/search?query=header:credentials.h
    *
    *********************************************************************

    How can I fix this and import the credentials library?

    Regards,
    Daniel.

  2. Regarding my latest post..
    I have created a new header file in same project folder with credentials.h
    Means including credentials.h works now, but now I get this:

    …/src/SignalBot.ino:54:14: error: ‘class BearSSL::WiFiClientSecure’ has no member named ‘verify’
    54 | if (client.verify(fingerprint, host)) {
    | ^~~~~~
    Compiling .pio\build\d1-mini\libf26\ESP8266WiFi\WiFiServerSecureBearSSL.cpp.o
    Compiling .pio\build\d1-mini\libf26\ESP8266WiFi\WiFiUdp.cpp.o
    *** [.pio\build\d1-mini\src\SignalBot.ino.cpp.o] Error 1

  3. Could make it applicable.

    If someone using platformio you can use the latest version of espressif8266 with specifying in platformion.ini
    platform = espressif8266@3

    Then you have to remove the client.verify() fingerprint check in your .ino code:

    if (client.verify(fingerprint, host)) {
    Serial.println(“certificate matches”);
    } else {
    Serial.println(“certificate doesn’t match”);
    }

    Otherwise, if you like to have the client.verify() in your code, you need to specify the older espressif version in platformio.ini:
    platform = espressif8266@2.6.3

    Regards,
    Daniel.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.