Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on email

Signal: ESP32 Send message and Image

This tutorial shows how to send text messages (notification) or Images to your Signal app using ESP32. Now your ESP32 projects will be able to send any alerts on the Signal app. ESP32 will be programmed using Arduino IDE.

Project Summary

This tutorial will cover how to use Signal bot API to send notifications and images from ESP32 to your signal account. At the end of this tutorial, we will use two buttons connected to ESP32.

The first button will send a message showing the total Button press count to your signal app. Another button press will send an image to your Signal app.

project overview for ESP32 with two buttons showing sending image and message to signal app

Here is the project breakdown:

It’s a simple project using API for interacting with the Signal app. You can use it in your IoT or any Home automation project based on ESP.

Watch the Video Tutorial

Introduction to Signal app

The Signal is a cross-platform centralized encrypted messaging service. It uses the internet to send a message such as an image, voice, video, etc. It is similar to a different messaging app like WhatsApp, but it focuses more on user privacy to enhance the overall user experience. Signal software allows us to use a bot to interact with them.

A bot is third-party software that runs on the signal app. You can interact with the bot, and the bot will interact with the signal app using a different bot API; it will act as a middle person. We can control our bot by sensing HTTPS requests to the bot API.

ESP32 will monitor the button press, and based on that, it will interact with the bot API, and it will send a message or an image to your Signal account.

Setting up a Signal bot

The first step will be to download the Signal app from google play or the app store. Skip if you have are already using a signal app.

Signal app installing from google play store

The bot that we will use in this project is known as Callmebot. Steps to add bot to your Signal app are as followed-

  1. Add this exact phone number +34 603 21 25 97 into your Phone Contacts. (you can name it as you like). Therefore we have saved this number as “Signal Bot.”
    Creating Contact number in Signal app for communicating signal bot
  2. From the Signal app, you have to send this exact message “I allow callmebot to send me messages” to the same bot number you saved in step 1.
    Allowing Signal bot to message and requesting API key for communication with signal app
  3. The bot will immediately reply with your API key. Copy that API key. We will use that key in our ESP32 code. 
    Signal bot replied with new API key on request.

After these three simple steps completion out Signal Bot is ready to interact with our ESP32, it’s that simple. 

Preparing Arduino IDE

To program ESP32 using Arduino IDE, we have to install the ESP32 board to Arduino IDE first. Follow our guide on.

Installing ESP32 in Arduino IDE

If you are not familiar with Arduino IDE then check our guide on-

❑ Getting Familiar With Arduino IDE

We will require an EasyButton.h library from evert-arias for the final example. This library takes care of button debouncing. For installing the library, follow these steps.

  1. Click here to download the latest release of EasyButton.h.
  2. Go inside Sketch > Include Library > Add .Zip Library.
  3. Browse the downloaded zip file from step 1.

For more details, you can check out EasyButton.h library Github Repository.

Parts Required

For this project, you will require the following parts.

  • ESP32 board or ESP8266

Additional requirement for a final example

  • Breadboard
  • 2x button
  • jumper or hookup wires.

Understanding Signal message sending API

Below is the API format to send a text message to the Signal app. Therefore we can use the HTTPS post method to send a text message to the Signal app using ESP32.

https://api.callmebot.com/signal/send.php?phone=[phone_number]&apikey=[apiKey ]&text=[message]

[phone_number]: Your Phone number, including the country code. Ex. +91 756 712 123

[apiKey ]:  Your API key that you received in Setting up a Signal bot step 3.

[message]: Text message you want to send ( all space ‘ ‘ need to be converter to ‘+’)

Example:

https://api.callmebot.com/signal/send.php?phone=+91756712123&apikey=598890&text=Hello+from+ESP32
Calling the above URL in any browser search bar, you will get “Hello from ESP32” as a message in the Signal app if your phone number and API key are correct.

Sending Message to Signal App with ESP32

The following code will send your message once on startup to the Signal bot using its API. Therefore you will receive one message to your Signal app when ESP32 powers ON or ESP32 reset.

ESP32 sending Hello message to Signal using Signal Bot and API

Following changes are required to use this code with your Signal app-

  1. Add your Wi-Fi credentials to the ssid and password variable.
  2. Add your API key to you to apiKey variable. (Same API key that you received by bot)
  3. Add your registered Signal app mobile number with country code to the phone_number variable.
 
/*
  Date: 07-05-21
  Code written by: Dharmik
  ESP32 sending a message to Signal messenger
  Find more on www.TechTOnions.com
*/

#include <WiFi.h>         //Including wifi.h library it will take care of all wifi related task
#include <HTTPClient.h>   //Including HTTPClient.h library to use all api

const char* ssid = "Replace me with your SSID";             //Add your WiFi ssid
const char* password =  "Replace me with your PASSWORD";    //Add your WiFi password

String apiKey = "222222";              //Add your Token number that bot has sent you on signal messenger
String phone_number = "+917561123123"; //Add your signal app registered phone number (same number that bot send you in url)

String url;                            //url String will be used to store the final generated URL

void setup() 
{
  Serial.begin(115200);

  WiFi.begin(ssid, password);              // Try to connect with the given SSID and PSS
  Serial.println("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {  // Wait until WiFi is connected
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Connected to the WiFi network"); // Print wifi connect message

  // use message_to_signal function to send your own message
  message_to_signal("Hello from TechTOnions.");  // you send your own message just change "hello from TechTOnions" to your message.
}

void loop()
{
  //loop will do nothing for this example
}

void  message_to_signal(String message)       // user define function to send meassage to Signal app
{
  //adding all number, your api key, your message into one complete url
  url = "https://api.callmebot.com/signal/send.php?phone=" + phone_number + "&apikey=" + apiKey + "&text=" + urlencode(message);

  postData(); // calling postData to run the above-generated url once so that you will receive a message.
}

void postData()     //userDefine function used to call api(POST data)
{
  int httpCode;     // variable used to get the responce http code after calling api
  HTTPClient http;  // Declare object of class HTTPClient
  http.begin(url);  // begin the HTTPClient object with generated url
  httpCode = http.POST(url); // Finaly Post the URL with this function and it will store the http code
  if (httpCode == 200)      // Check if the responce http code is 200
  {
    Serial.println("Sent ok."); // print message sent ok message
  }
  else                      // if response HTTP code is not 200 it means there is some error.
  {
    Serial.println("Error."); // print error message.
  }
  http.end();          // After calling API end the HTTP client object.
}

String urlencode(String str)  // Function used for encoding the url
{
    String encodedString="";
    char c;
    char code0;
    char code1;
    char code2;
    for (int i =0; i < str.length(); i++){
      c=str.charAt(i);
      if (c == ' '){
        encodedString+= '+';
      } else if (isalnum(c)){
        encodedString+=c;
      } else{
        code1=(c & 0xf)+'0';
        if ((c & 0xf) >9){
            code1=(c & 0xf) - 10 + 'A';
        }
        c=(c>>4)&0xf;
        code0=c+'0';
        if (c > 9){
            code0=c - 10 + 'A';
        }
        code2='\0';
        encodedString+='%';
        encodedString+=code0;
        encodedString+=code1;
        //encodedString+=code2;
      }
      yield();
    }
    return encodedString;
}

You will see this message in your Signal app “Hello from TechTOnions.” once uploading is completed and ESP32 gets a proper Internet connection. Additionally, you will see sent ok message printed on the serial monitor.

ESP32 have successfully send message to Signal app therefore printing sent ok in serial monitor.

How code works

The first step will be to include a required library for the example.

  • WiFi.h library will take care of all wifi-related tasks like connecting to your Wi-Fi.
  • HTTPClient.h library used to post the API with HTTP requests.
    
#include <WiFi.h>         //Including wifi.h library it will take care of all wifi related task
#include <HTTPClient.h>   //Including HTTPClient.h library to use all api

Network Credentials

Insert your Wi-Fi network credentials. So that ESP32 can connect to your Wi-Fi network for Internet connection.

    
const char* ssid = "Replace me with your SSID";             //Add your WiFi ssid
const char* password =  "Replace me with your PASSWORD";    //Add your WiFi password

Signal Bot Credentials

Insert the API key that you received in Setting up a Signal bot step 3. Additionally, add your Phone number with the country code that your signal app is registered.

    
String apiKey = "222222";              //Add your Token number that bot has sent you on signal messenger
String phone_number = "+917561123123"; //Add your signal app registered phone number (same number that bot send you in URL)

setup()

First, we will initialize the serial communication so we can see data in the Serial monitor.

    
Serial.begin(115200);

Init the Wi-Fi

Initialize the Wi-Fi So that it can connect to your Wi-Fi network.

Note: If your Wi-Fi credentials are wrong, then ESP will be stuck in the infinite while loop.

    
WiFi.begin(ssid, password);              // Try to connect with the given SSID and PSS
  Serial.println("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {  // Wait until WiFi is connected
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Connected to the WiFi network"); // Print wifi connect message

Finally, we will send a message to the Signal app by calling our user-defined function named message_to_signal. You can change the message that you want to send.

It will send “hello from TechTOnions.” if you do not modify the existing message.

message_to_signal (String message)

message_to_signal is our user-defined function that will send messages to Signal App.

Inside this function, it will generate the final url String used for HTTP GET request. The final url will consist of an API url with your phone number, API key, and your message in encoded form.

To encode the message, we will pass the message to the urlencode function.

We are finally calling the postData function to send the message.

    
void  message_to_signal(String message)       // user define function to send meassage to Signal app
{
  //adding all number, your api key, your message into one complete url
  url = "https://api.callmebot.com/signal/send.php?phone=" + phone_number + "&apikey=" + apiKey + "&text=" + urlencode(message);

  postData(); // calling postData to run the above-generated url once so that you will receive a message.
}

postData()

postData is another user-defined function used to send the URL using the HTTP GET method.

Initialize the new http object with HTTPClient. And begin the new http object with the final url build.

    
  HTTPClient http;  // Declare object of class HTTPClient
  http.begin(url);  // begin the HTTPClient object with generated url

Post the url by calling this POST function and save the HTTP response code in the httpCode variable.

    
httpCode = http.POST(url); // Finaly Post the URL with this function and it will store the http code

Now we will check the httpCode that we received, and if it is 200, POST was successful. Therefore printing “Sent ok.” in Serial monitor. If not 200, then printing “Error.” as POST is not successful.

Finally, we will end the http object by calling the end function.

    
  if (httpCode == 200)      // Check if the responce http code is 200
  {
    Serial.println("Sent ok."); // print message sent ok message
  }
  else                      // if response HTTP code is not 200 it means there is some error.
  {
    Serial.println("Error."); // print error message.
  }
  http.end();          // After calling API end the HTTP client object.

urlencode(String str)

This function is used to encode the standard URL because it is necessary to encode sending messages or URL when using HTTP GET request.

    
  String urlencode(String str)  // Function used for encoding the url
{
    String encodedString="";
    char c;
    char code0;
    char code1;
    char code2;
    for (int i =0; i < str.length(); i++){
      c=str.charAt(i);
      if (c == ' '){
        encodedString+= '+';
      } else if (isalnum(c)){
        encodedString+=c;
      } else{
        code1=(c & 0xf)+'0';
        if ((c & 0xf) >9){
            code1=(c & 0xf) - 10 + 'A';
        }
        c=(c>>4)&0xf;
        code0=c+'0';
        if (c > 9){
            code0=c - 10 + 'A';
        }
        code2='\0';
        encodedString+='%';
        encodedString+=code0;
        encodedString+=code1;
        //encodedString+=code2;
      }
      yield();
    }
    return encodedString;
}

For example,

If you want to send “Hello World“, it should be encoded as “Hello+World“.

And if you want to send the URL “https://www.techtonions.com/“, then the encoded URL will be like “https%3A%2F%2Fwww.techtonions.com%2F“.

loop()

For this example, the loop() function will be empty. You can add your code in the loop function. You can also send multiple messages by calling the message_to_signal again inside the loop.

Note:- Calling the message_to_signal function inside the loop without delay can crash the bot, so have some delay if you do so.

Understanding Signal Image sending API

Image sending API is similar to message sending API. Hence you can send any Image to the Signal app by HTTP get method by ESP32.

https://api.callmebot.com/signal/send.php?phone=[phone_number]&apikey=[apiKey ]&image=[image_url]

[phone_number]: Your Phone number, including the country code. Ex. +91 756 712 123

[apiKey ]:  Your API key that you received in Setting up a Signal bot step 3.

[image_url]: put any image encoded URL you like here (Only works for .jpg .gif .png)

Sending Image to Signal App with ESP32

In this example, we will send the Image to the Signal app from ESP32. For this example, we are sending the TechTOnions logo. Therefore you will receive our logo to your Signal app when ESP32 powers ON or ESP32 reset.

Sending image to Signal App using signal bot or API with ESP32

Following changes are required to use this code with your Signal app-

  1. Add your Wi-Fi credentials to the ssid and password variable.
  2. Add your API key to you to apiKey variable. (Same API key that you received by bot)
  3. Add your registered Signal app mobile number with country code to the phone_number variable.
 
/*
  Date: 07-05-21
  Code written by: Dharmik
  ESP32 sending image to Signal messenger
  Find more on www.TechTOnions.com
*/

#include <WiFi.h>        //Including wifi.h library it will take care of all wifi related task
#include <HTTPClient.h>  //Including HTTPClient.h library to use all api

const char* ssid =      "Replace me with your SSID";        //Add your WiFi ssid
const char* password =  "Replace me with your PASSWORD";    //Add your WiFi password

String apiKey = "222222";              //Add your Token number that bot has sent you on signal messenger
String phone_number = "+917561123123"; //Add your signal app registered phone number with country code (the same number that bot send you in url)  
String url;                            //url String will be used to store the final generated URL


void setup() {

  Serial.begin(115200);
  WiFi.begin(ssid, password);             // Try to connect with the given SSID and PSS
  Serial.println("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) { // Wait until WiFi is connected
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Connected to the WiFi network");  // Print wifi connect message

  //image_to_signal function will send your image to Signal app
  //Just you have to add your image url
  //it only works for .jpg .gif .png    // not working with .webp image format 
  image_to_signal("https://www.techtonions.com/wp-content/uploads/2021/05/New-Profile-picture-logo-big-250x250-1.jpg");
}

void loop()
{
  //loop will do nothing for this example
}


void image_to_signal(String img_url)  //user define function to send image to Signal App
{
  //adding all number, your api key, your image url into one complete url
  url = "https://api.callmebot.com/signal/send.php?phone="+ phone_number + "&apikey=" + apiKey + "&image=" + urlencode(img_url);
  postData(); // caling postData to run the above generated url once so that you will receive image.
}


void postData()     //userDefine function used to call api(POST data)
{
  int httpCode;     // variable used to get the responce http code after calling api
  HTTPClient http;  // Declare object of class HTTPClient
  http.begin(url);  // begin the HTTPClient object with generated url
  httpCode = http.POST(url); // Finaly Post the URL with this function and it will store the http code
  if (httpCode == 200)      // Check if the responce http code is 200
  {
    Serial.println("Sent ok."); // print message sent ok message
  }
  else                      // if response HTTP code is not 200 it means there is some error.
  {
    Serial.println("Error."); // print error message.
  }
  http.end();         // After calling API end the HTTP client object.
}

String urlencode(String str)  // Function used for encoding the url
{
    String encodedString="";
    char c;
    char code0;
    char code1;
    char code2;
    for (int i =0; i < str.length(); i++){
      c=str.charAt(i);
      if (c == ' '){
        encodedString+= '+';
      } else if (isalnum(c)){
        encodedString+=c;
      } else{
        code1=(c & 0xf)+'0';
        if ((c & 0xf) >9){
            code1=(c & 0xf) - 10 + 'A';
        }
        c=(c>>4)&0xf;
        code0=c+'0';
        if (c > 9){
            code0=c - 10 + 'A';
        }
        code2='\0';
        encodedString+='%';
        encodedString+=code0;
        encodedString+=code1;
        //encodedString+=code2;
      }
      yield();
    }
    return encodedString;
}

How code works

The code is all similar to the message sending code. We will require the same library for this code also.
You’ll need to add your Wi-Fi credentials, API key, and Phone number as described in the message send method.

    
#include <WiFi.h>        //Including wifi.h library it will take care of all wifi related task
#include <HTTPClient.h>  //Including HTTPClient.h library to use all api

const char* ssid =      "Replace me with your SSID";        //Add your WiFi ssid
const char* password =  "Replace me with your PASSWORD";    //Add your WiFi password

String apiKey = "222222";              //Add your Token number that bot has sent you on signal messenger
String phone_number = "+917561123123"; //Add your signal app registered phone number with country code (the same number that bot send you in url)  

setup()

Inside setup function serial begin and Wi-Fi init logic will be same, but we will not use the message_to_signal function; instead, we will use another user-defined function for the Image sending name as image_to_signal.

You need to send an image URL with this function, and it will send your Image to the Signal app.

    
  //image_to_signal function will send your image to Signal app
  //Just you have to add your image url
  //it only works for .jpg .gif .png    // not working with .webp image format 
  image_to_signal("https://www.techtonions.com/wp-content/uploads/2021/05/New-Profile-picture-logo-big-250x250-1.jpg");

image_to_signal(String img_url)

image_to_signal is our user-defined function that will send any image to Signal App whenever called.

Inside this function, it will encode the image URL by using the urlencode function used in the previous example. After that, we will generate the final URL, which will contain your phone number, API key, and encoded image URL.

Finally, calling the postData function to send the message.

    
void image_to_signal(String img_url)  //user define function to send image to Signal App
{
  //adding all number, your api key, your image url into one complete url
  url = "https://api.callmebot.com/signal/send.php?phone="+ phone_number + "&apikey=" + apiKey + "&image=" + urlencode(img_url);
  postData(); // caling postData to run the above generated url once so that you will receive image.
}

For this example, the loop() function will be empty. You can add your code in the loop function. You can also send multiple images by calling the image_to_signal again inside the loop.

Note:- Calling the image_to_signal function inside the loop without delay can crash the bot, so have some delay if you do so.

Signal message and Image on a button press

For this project, we will use two buttons connected with ESP32 GPIOs. We will use the above-mentioned message and Image sending functions in this example with a button interface.
We will send a message with the total number of button count when button1 is pressed. And we will send our TO logo as an image when button2 is pressed.

ESP32 breadboard circuit with two input buttons


This example demonstrates how you can integrate the user-defined functions into your IoT projects.

Circuit Diagram

Here is the simple schematic used for this project. It has two buttons tied to an ESP32 GPIOs. Button1 with GPIO23 and Button2 with GPIO22. We will use internal pullups for both switches.

ESP32 circuit diagram with two push button

ESP32 to Signal message and Image on a button press – Sketch

The following code will communicate to the Signal bot hence sending messages and images with buttons. If you understand this concept of using this function, you can easily integrate this code with your ESP32 IoT or Home automation projects i.e.
You can use a Door sensor switch with a Reed switch instead of buttons to get notified whenever a door is open/closed. Or maybe Pir sensor motion detection-based alerts.

Sending Button count and image messages to signal app with signal bot or API with ESP32

Following changes are required to use this sketch with your Signal app-

  1. Add your Wi-Fi credentials to the ssid and password variable.
  2. Add your API key to you to apiKey variable. (Same API key that you received by bot)
  3. Add your registered Signal app mobile number with country code to the phone_number variable.
  4. If you use different Button pins, then change btn1 and btn2 accordingly.
 
/*
  Date: 07-05-21
  Code written by: Dharmik
  ESP32 sending a message & image to Signal messenger on button press.
  Find more on www.TechTOnions.com
*/

#include <WiFi.h>         //Including wifi.h library it will take care of all wifi related task
#include <HTTPClient.h>   //Including HTTPClient.h library to use all api 
#include <EasyButton.h>   //Including EasyButton.h library for handling debouncing on button input
#define btn1 23           //define button 1 pin
#define btn2 22           //define button 2 pin
int button_count;          //it will store total number of button press count

const char* ssid = "Replace me with your SSID";            //Add your WiFi ssid
const char* password = "Replace me with your PASSWORD";    //Add your WiFi password

String apiKey = "222222";              //Add your Token number that bot has sent you on signal messenger
String phone_number = "+917561123123"; //Add your signal app registered phone number (same number that bot send you in url)

String url;                            //url String will be used to store the final generated URL


EasyButton button1(btn1);  // Button1 object for btn1
EasyButton button2(btn2);  // Button2 object for btn2

String send_message;

void setup() {

  button1.begin();  // Initialize the button1
  button2.begin();  // Initialize the button2

  // Add the callback function to be called when the button1 is pressed.
  button1.onPressed(onButton1Pressed);
  // Add the callback function to be called when the button2 is pressed.
  button2.onPressed(onButton2Pressed);

  Serial.begin(115200);

  WiFi.begin(ssid, password);              // Try to connect with the given SSID and PSS
  Serial.println("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {  // Wait until WiFi is connected
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Connected to the WiFi network"); // Print wifi connect message

}

void loop()
{
  // Continuously read the status of the buttons
  button1.read();
  button2.read();
}

// Callback function to be called when button1 is pressed
void onButton1Pressed()
{
  button_count++;
  send_message = "Button count = " + String(button_count);
  Serial.println("button1 pressed sending");
  Serial.println(send_message);
  message_to_signal(send_message); // Send send_message to Signal app
}

// Callback function to be called when button2 is pressed
void onButton2Pressed()
{
  Serial.println("Button2 pressed send image");
  image_to_signal("https://www.techtonions.com/wp-content/uploads/2021/05/New-Profile-picture-logo-big-250x250-1.jpg");
}

void image_to_signal(String img_url)  //user define function to send image to Signal App
{
  //adding all number, your api key, your image url into one complete url
  url = "https://api.callmebot.com/signal/send.php?phone="+ phone_number + "&apikey=" + apiKey + "&image=" + urlencode(img_url);
  postData(); // caling postData to run the above generated url once so that you will receive image.
}

void  message_to_signal(String message)       // user define function to send meassage to Signal app
{
  //adding all number, your api key, your message into one complete url
  url = "https://api.callmebot.com/signal/send.php?phone=" + phone_number + "&apikey=" + apiKey + "&text=" + urlencode(message);

  postData(); // calling postData to run the above-generated url once so that you will receive a message.
}

void postData()     //userDefine function used to call api(POST data)
{
  int httpCode;     // variable used to get the responce http code after calling api
  HTTPClient http;  // Declare object of class HTTPClient
  http.begin(url);  // begin the HTTPClient object with generated url
  httpCode = http.POST(url); // Finaly Post the URL with this function and it will store the http code
  if (httpCode == 200)      // Check if the responce http code is 200
  {
    Serial.println("Sent ok."); // print message sent ok message
  }
  else                      // if response HTTP code is not 200 it means there is some error.
  {
    Serial.println("Error."); // print error message.
  }
  http.end();         // After calling API end the HTTP client object.
}

String urlencode(String str)  // Function used for encoding the url
{
    String encodedString="";
    char c;
    char code0;
    char code1;
    char code2;
    for (int i =0; i < str.length(); i++){
      c=str.charAt(i);
      if (c == ' '){
        encodedString+= '+';
      } else if (isalnum(c)){
        encodedString+=c;
      } else{
        code1=(c & 0xf)+'0';
        if ((c & 0xf) >9){
            code1=(c & 0xf) - 10 + 'A';
        }
        c=(c>>4)&0xf;
        code0=c+'0';
        if (c > 9){
            code0=c - 10 + 'A';
        }
        code2='\0';
        encodedString+='%';
        encodedString+=code0;
        encodedString+=code1;
        //encodedString+=code2;
      }
      yield();
    }
    return encodedString;
}

How Code Works

We will Install all necessary libraries for the code required. Now we will also use EasyButton.h library for easy debouncing of button used.

    
#include <WiFi.h>         //Including wifi.h library it will take care of all wifi related task
#include <HTTPClient.h>   //Including HTTPClient.h library to use all api 
#include <EasyButton.h>   //Including EasyButton.h library for handling debouncing on button input

We are defining button pins as btn1 and btn2. Additionally, we need the button_count variable to store total button counts.

    
#define btn1 23           //define button 1 pin
#define btn2 22           //define button 2 pin
int button_count;          //it will store total number of button press count

Now we require Wi-Fi credentials, your Signal API key, and phone number.

    
const char* ssid = "Replace me with your SSID";            //Add your WiFi ssid
const char* password = "Replace me with your PASSWORD";    //Add your WiFi password

String apiKey = "222222";              //Add your Token number that bot has sent you on signal messenger
String phone_number = "+917561123123"; //Add your signal app registered phone number (same number that bot send you in url)

We will generate button1 and button2 as a new object for EasyButton.

    
EasyButton button1(btn1);  // Button1 object for btn1
EasyButton button2(btn2);  // Button2 object for btn2

setup()

Inside Setup function now we will begin our two-button object. By default, the library will set it as Input with internal pullups.

    
  button1.begin();  // Initialize the button1
  button2.begin();  // Initialize the button2

Assigning callback function onButton1Pressed to button1 and onButton2Pressed to button2. It means that now whenever EasyButton detects one button press event, it will trigger this callback function.

    
  // Add the callback function to be called when the button1 is pressed.
  button1.onPressed(onButton1Pressed);
  // Add the callback function to be called when the button2 is pressed.
  button2.onPressed(onButton2Pressed);

Now initialize the serial communication with a baud rate of 115200, so we can see data in the Serial monitor.

    
  Serial.begin(115200);

Init the Wi-Fi

Initialize the Wi-Fi So that it can connect to your Wi-Fi network.

    
  WiFi.begin(ssid, password);              // Try to connect with the given SSID and PSS
  Serial.println("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {  // Wait until WiFi is connected
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Connected to the WiFi network"); // Print wifi connect message

Note:- If your Wi-Fi credentials are wrong, then ESP will be stuck in the infinite while loop.

loop()

Inside the loop, we have to call the read() function of the EasyButton library. It will continuously monitor both buttons. And on a button press, it will trigger the callback function we defined in the setup function.

    
  // Continuously read the status of the buttons
  button1.read();
  button2.read();

onButton1Pressed()

Inside this callback function, we will increment the button_count variable, and we will send a button count message to the Signal app using the message_to_signal function that we explored before.

    
void onButton1Pressed()
{
  button_count++;
  send_message = "Button count = " + String(button_count);
  Serial.println("button1 pressed sending");
  Serial.println(send_message);
  message_to_signal(send_message); // Send send_message to Signal app
}

onButton2Pressed()

Inside this callback function, we will send an image to the Signal app using the image_to_signal function that we explore before.

    
void onButton2Pressed()
{
  Serial.println("Button2 pressed send image");
  image_to_signal("https://www.techtonions.com/wp-content/uploads/2021/05/New-Profile-picture-logo-big-250x250-1.jpg");
}

All remaining function we used for this example has discussed before.

Conclusion

The tutorial shows how easily you can use any third-party API with an ESP32 for interacting with the Signal app. Explore more and write in the comment section about your Signal IOT project using this method.

More projects that you may like reading.

❑ Get alerts on WhatsApp with ESP32 when a door opens.

Consider subscribing to our weekly newsletters for weekly updates on new IoT projects based on ESP32.

Subscribe to our weekly newsletter

Subscribe
Notify of
guest
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Robert Grover
Robert Grover
Guest
May 13, 2021 7:20 pm

Another awesome tutorial – very clearly written and an interesting application. Thanks for writing this!

Akingbade Tunde
Akingbade Tunde
Guest
June 29, 2021 7:14 pm

In fact, this tutorial is very helpful.
Thank you.
God Bless

Tirth Bhavani
Tirth Bhavani
Admin
Reply to  Akingbade Tunde
July 3, 2021 11:26 am

Thank you akingbade.

posts info

Subscribe to our weekly newsletter

STAY IN TOUCH WITH US

Subscribe to our weekly newsletter