I was working with WhatsApp Business API, provided by my Twilio account and number, to create a self-replying order bot. After achieving my ostensible goal, I contemplated using Twilio WhatsApp Helper Library to send information(data packets) from a NodeMCU to my phone as WhatsApp messages by transferring information through a webhook initially. In this way, I was able to create template messages with the data coming from NodeMCU through an HTTP Get Request to send them as WhatsApp messages via Twilio API. For subscribers of my website, I implemented a new web application named WhatsApp WebHook on Dashboard, which generates a unique webhook path using your hedron, explained below. I shared the source code of this application below if you want to use the localhost or any other link provider to create a webhook, but first, you have to download Twilio Helper Library in your directory.
I wanted to obtain three variables as WhatsApp messages in every half minute – temperature, humidity, and movement. In other words, WhatsApp Notification Station sends these three variables to the webhook to be combined as a template WhatsApp message every half minute. I used a DHT11 Temperature and Humidity Sensor to elicit temperature and humidity at the same time, and an HC-SR04 Ultrasonic Sensor to detect any movement(trespassing).
First of all, download the required libraries for Arduino IDE below to continue the following steps.
Required Libraries:
For NodeMCU boards, click here.
For DHT11 Temperature and Humidity Sensor, click here.
To send WhatsApp messages through Twilio API, the only thing you need to do is to sign up for Twilio Trial Account.
After signing up, with your SID and Auth Token, you can use Twilio API for WhatsApp without a charge. As explained on Twilio, you need to join a shared phone number with your phone in order to initiate the API and WhatsApp template messages.
For more information and learn how to activate your account, click the link below.
You can sign up to Twilio with my referral code here.
In this project, the webhook gets information from NodeMCU through an HTTP Get Request to send it to your phone via Twilio WhatsApp API.
For subscribers of my website, I created a web application, named WhatsApp WebHook, which generates a unique webhook for each account by using their hedron provided by TheAmplituhedron(my website).
By using this web application, you can connect directly to your Twilio account to send WhatsApp messages via ESP8266, Raspberry Pi, or any other device that is compatible with the operating system.
It is just a simple webhook requiring five parameters defined below.
1) Twilio Account SID
2) Twilio Account AUTH TOKEN
3) Message Body
4) From: Dedicated Business Phone Number(Shared)
5) To: Your Verified Phone Number
Note: Normally, you would have to enter the plus sign(+) and the country code, followed by the full phone number, like this +14081234567.
But, while sending information from your device to your phone through this web application(WhatsApp WebHook), enter the number like this 14081234567 without the plus sign(+).
For more information about this application and getting a auto-generated webhook, click the link below.
If you want to create a webhook for this project at localhost or any other server than TheAmplituhedron, you can copy the source code of the webhook generated by TheAmplituhedron(shared at Code down below) and alter the webhook path in the code uploaded to NodeMCU.
But, to manage that, you have to download Twilio PHP Helper Library at your directory from here.
After creating a webhook and joining a shared number, when the webhook is triggered, you can transmit data packets as WhatsApp messages from NodeMCU to your verified phone.
Even though there is no restriction for the duration, I choose to send information every half-minute.
NodeMCU sends three variables – Temperature, Humidity, and Movement – to the webhook to be combined as a WhatsApp template message. And, the webhook transmits that message to your verified phone as a WhatsApp message.
1) Monitor variables and whether the message is sent through the webhook successfully or not on the serial monitor.
2) Display temperature and humidity measured by DHT11 Temperature and Humidity Sensor on WhatsApp.
"Temperature: Value" and "Humidity: Value"
3) Get notified if any movement detected by HC-SR04 Ultrasonic Sensor on WhatsApp. In other words, if someone is trespassing.
"Movement: No movement detected!" or "Someone is trespassing!"
NodeMCU GPIO pin connections are well-explained at the code down below. Make connections as depicted on figures below.
I just fastened all components to an old plastic box by using a hot glue gun and connect them to NodeMCU(ESP-12E).
Note: If your HC-SR04 module generates 0 as distance, feed it with an external 5V power supply.
WhatsApp Notification Station | Demonstration
WhatsApp Notification Station | Incoming WhatsApp Messages
Comments