How Can We Help?

Print

How can I send Signal or Whatsapp messages from our HMI with CallMeBot?

 

CallMeBot Free API can send notifications and images to the Signal or WhatsApp messaging application.

Super easy to implement using a simple API call from an HMI script

 

Ethernet HMI configuration

You need an Internet acces for your HMI. It means that your HMI must have:

  • its IP address
  • an IP address for the gateway which must have an internet access
  • an IP for the DNS

If you cannot enter an IP for DNS in the HMI, you must replace the domain name with its IP address in the script.

  • InitEthernet("signal.callmebot.com", 80);
    • become InitEthernet("13.38.186.117", 80);
  • "Host: signal.callmebot.com\r\n"
    • become (for Signal) "Host:13.38.186.117\r\n"

See HMI Ethernet IP address and Modbus-TCP

Get API key from CallMeBot for Signal messenger

You need to get a personal APIkey before using the API. So only you can send messages to yourself.

Just follow these 3 simple steps:

  • On your phone, add the phone number +34 644 52 74 88 to your address book (Let’s name it “CallMeBot”)
  • Always on your phone, using the Signal app, send this message “I allow callmebot to send me messages” to the newly created contact.
  • The bot will answer you with your personal APIKey.

Here is the message you should receive:

👍 New APIkey created for CallMeBot Signal API!
The APIKey created for you is: 123456
Congratulations! You can now send Signal messages from any devices,app,service!
Use this URL to send a message:
https://signal.callmebot.com/signal/send.php?phone=+33123456789&apikey=123456&text=This+is+a+test
Note: Replace This+is+a+test parameter with the message that you want to send.

You can now start sending messages to yourself through Signal Messaging App.

If your phone number is not visible to the robot (due to your privacy settings), the robot will take your UUID (Unique User ID) as the phone number.
For example: 25a7d32b-0c51-44d8-b11b-c5bc73294abc
You can still use the API with the UUID instead of the phone number.

You can find more details on the website: https://www.callmebot.com/blog/free-api-signal-send-messages/
For WhatsApp, the procedure is similar: https://www.callmebot.com/blog/free-api-whatsapp-messages/

 

The HMI script used for Signal

In the HMI-Tool Script Editor

  1. Add a new Script
  2. Copy the Script below.
    < ! > This script will work only if you replace the phone number (or UUID) and API key with your own
  3. Compil.

#include "MacroInit.h"
#include // For sleep()
void Macro_main(IN *p)
{
MarcoInit
LocalWord[1] = 0;
int writeEthernet(char *cBuffer, int iSize);
char phone[] = "25a7d32b-0c51-44d8-b11b-c5bc73294abc"; // Your UUID or Phone number like +33123456789
char apikey[] = "123456"; // Your APIKey like 123456
char text[] = "Sent+from+HMI"; // Your message
char request[512]; // Increase if the message is much longer
LocalWord[0] = InitEthernet("signal.callmebot.com", 80);
sleep(1); // Wait InitEthernet
snprintf(request, sizeof(request),
"GET /signal/send.php?phone=%s&text=%s&apikey=%s HTTP/1.1\r\n"
"Host: signal.callmebot.com\r\n"
"Connection: close\r\n\r\n",
phone, text, apikey
);
LocalWord[1] = writeEthernet(request, strlen(request)); // Send the HTTP request
LocalBit[10] = 0;
LocalWord[0] = 0;
}

Execute the script with a button on the HMI

  • Trigger the script on LB10 Bit, OFF->ON
  • Setup a Bit Button to set LB10 to 1 (Script will reset it after)

 

Add LW0 and WL1 to see InitEthernet and writeEthernet status

  • Setup a Display Numercial to see LW0 = InitEthernet
  • Setup a Display Numercial to see LW1 = writeEthernet

Using the HMI script for WhatsAp

The script is identical, just take care about the GET instruction for the URL and the APIKey

For Signal

The URL is:

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

The GET instruction is:

"GET /signal/send.php?phone=%s&text=%s&apikey=%s HTTP/1.1\r\n"
"Host: signal.callmebot.com\r\n"
"Connection: close\r\n\r\n",
phone,text,apikey
);

For WhatsApp

The URL is:

  • https://api.callmebot.com/whatsapp.php?phone=[phone_number]&text=[message]&apikey=[your_apikey]

The GET instruction is:

"GET /whatsapp.php?phone=%s&text=%s&apikey=%s HTTP/1.1\r\n"
"Host: api.callmebot.com\r\n"
"Connection: close\r\n\r\n",
phone,text,apikey
);

 

Remember

You must have an Internet access from the HMI with DNS (or replace domaine names by its IP in the script).

 

How to adapt your code for a generic REST API

Our code sends a GET request to CallMeBot’s REST API over HTTP to send a message via Signal.

Key elements in this code:

  • InitEthernet() — opens TCP client connection
  • writeEthernet() — sends data
  • Possibly readEthernet() too (for reading responses)

This is a REST GET request, just without JSON

The server returns a simple HTTP response (But we don’t currently read or display it)

Adapted version (Generic REST GET):

#include "MacroInit.h"
#include // For sleep()
void Macro_main(IN *p)
{
MacroInit;
// Reset status words
LocalWord[0] = 0;
LocalWord[1] = 0;
LocalBit[10] = 0;
// --- Define REST endpoint ---
char host[] = "myserver.local"; // or IP address like "192.168.0.10"
int port = 80; // 443 if HTTPS (not supported by plain TCP)
char path[] = "/api/device/status"; // REST API endpoint
// --- HTTP Request buffer ---
char request[512];
// 1. Initialize Ethernet connection
LocalWord[0] = InitEthernet(host, port);
sleep(1); // wait for connection setup
// 2. Build HTTP GET request
snprintf(request, sizeof(request),
"GET %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Accept: application/json\r\n"
"Connection: close\r\n\r\n",
path, host
);
// 3. Send the HTTP request
LocalWord[1] = writeEthernet(request, strlen(request));
// Optionally: You could call readEthernet() here to capture the response
// char response[512];
// int len = readEthernet(response, sizeof(response));
// response[len] = '\0';
// printf("Response: %s\n", response);
// 4. Reset status flags
LocalBit[10] = 0;
LocalWord[0] = 0;
}

Part    Explanation

  • char host[] : The server domain or IP address
  • char path[] : The REST resource path
  • InitEthernet() : Opens TCP socket connection
  • writeEthernet() : Sends HTTP request
  • sleep(1) : Small delay for connection to be ready
  • readEthernet() : Can be added if you need to handle the JSON reply

 

Example for a REST API with parameters

If your REST API expects query parameters (like /api/data?value=123), simply change:

char path[] = "/api/data?value=123";

To add POST requests (sending JSON)

You can also easily extend your macro to do a POST:

snprintf(request, sizeof(request),
"POST /api/device/update HTTP/1.1\r\n"
"Host: %s\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n"
"Connection: close\r\n\r\n"
"%s",
host, strlen(json_body), json_body
);