Introduction: Loactor With Whether Live Report Using Chat Bot
Through WhatsApp, get variables (location, altitude, pressure... ) from NodeMCU as requested or send commands to NodeMCU via Twilio's API.
for a few weeks, I have been working with Twilio’s API, especially for WhatsApp messaging, and even created a project sending the variables coming from NodeMCU to my phone.But, my former project was merely sending data packets to my phone as WhatsApp messages periodically. And, I was determined to take my nascent idea and improve it by using WhatsApp response messages and a MySQL database and thus created this project. In that way, NodeMCU transfers variables to the phone as WhatsApp messages when the user requested them or gets commands from the user through WhatsApp. To manage that, I created a web application in PHP, which detects whether a WhatsApp message was sent or not and response the message depending on the keyword in the body. The application, named WhatsApp Two-Way Connection Hub, saves all variables transferred from NodeMCU and commands received from WhatsApp to a dedicated MySQL database and therefore communicates the user and NodeMCU instantly when something requested. I shared the source code of the application below if you want to use the localhost or your server instead of TheAmplituhedron to create a connection hub, but first, you have to download Twilio Helper Library in your directory.In this project, I wanted to make a remote mapping and weather forecast bot sending temperature, pressure, altitude, latitude, and longitude when requested as WhatsApp response messages and control the base by giving commands through WhatsApp. To gather data, I decided to use a BMP180 Pressure and Temperature Sensor, and a GY-NEO6MV2 GPS Module and to make the base remote and controllable, I used an L298N Motor Driver and two Wheel and DC Motor Kit along with a ball caster.
Also, you can view the location generated by the GPS module on Google Maps through WhatsApp.
- Hardware components
- NodeMCU ESP8266 Breakout Board×1
- NodeMCU LoLin ESP8266 Base Shield×1
- GY-NEO6MV2 GPS Module×1
- SparkFun BMP180 Pressure Sensor×1
- L298N Motor Driver×1
- Wheel and DC Motor Kit×2
- Ball Caster×1Battery Holder, AA x 8×1
- SparkFun Solder-able Breadboard - Mini×1
- Male/Female Jumper Wires×1 Male/Male Jumper Wires
Software apps and online services
- Arduino IDE
- Twilio API for WhatsApp
Step 1: Twilio for WhatsApp
To send WhatsApp messages through Twilio's API, the only thing you need to do is to sign up for a 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. Important: To be able to response WhatsApp messages coming from your verified phone, you must change the default endpoint URL of your Twilio application in the Sandbox with your connection hub path.
Step 2: How to Create a Connection Hub to Manage Data Transferring
I programmed a web application, named WhatsApp Two-Way Connection Hub, which allows you to response WhatsApp messages coming from a verified phone number by a Twilio application in order to get variables from NodeMCU, or any other device that can make an HTTP Request, as WhatsApp messages and send commands to the device.
This application saves the data coming from the device temporarily into a dedicated MySQL server hence no need to call the current variables from the device every time the data requested by the user. To register variables from the device properly, you must send the variables through an HTTP Request to your unique connection hub path. Important: To be able to use the application, you must change the default endpoint URL of your Twilio application in the Sandbox with your connection hub path generated with your hedron by TheAmplituhedron API.
When you enter a specific keyword, which you can see below for each data on your dedicated database, on WhatsApp, this application will response that message by sending the requested variable associated with the keyword to your phone or transferring commands to the device.
Data holders in the database: Data_1, Data_2, Data_3, Data_4, Data_5, Data_6, Command
- Temperature -> Get Data_1
- Pressure -> Get Data_2
- Altitude -> Get Data_3
- Date -> Get Data_4
- Time -> Get Data_5
- Latitude and Longitude -> Get Data_6
- Map Location -> Get Google Maps link using GPS information
- Go Straight -> Send itself as a command to the device
- Go Back -> Send itself as a command to the device
- Go Right -> Send itself as a command to the device
- Go Left -> Send itself as a command to the device
- Halt -> Send itself as a command to the device
- Programmed by
- How r u?
- Further information
- ContactSpidey -> Test media transferring
- Batman -> Test media transferring
- Help -> Print all keywords
Reminder: WhatsApp Two-Way Connection Hub is open-source. If you do not want to use TheAmplituhedron instead of localhost or your server in your projects, you can download the source code below and thus specialize the keywords by creating your connection hub application on your server.
Step 3: Features
- Collect date, time, latitude, and longitude information generated by a GY-NEO6MV2 GPS Module.
- Get temperature, pressure, and altitude from a BMP180 Pressure Sensor.
- Make an HTTP Get Request to transfer variables to the database and receive the command from the database as a response.
- Depending on the command, control an L298N Motor Driver.
- Monitor all processes on the serial monitor.
- Elicit response messages to display variables saved to the database as requested through WhatsApp or give commands to the device by sending the command on WhatsApp.
Step 4: Code and Circuit
Participated in the
Arduino Contest 2020