4. SMS Application - KieranThompsonCE/Smart-Pill-Organizer GitHub Wiki

One feature of the Smart Pill Organizer is that it is able to notify the user through SMS when they should take their pill. Here is a step-by-step guide of the design process and understanding the code written.

Setting up the ESP8266

The SMS is sent using the ESP8266 development board. This board is able to connect to the internet and use IOT applications. In order to use the board you will need to download the ESP8266 board libraries. Below are two resources that can help with the process. One is for downloading the board libraries to the Arduino IDE and the other is the GitHub link to the board libraries.

ESP8266 Instructions: https://www.instructables.com/Setting-Up-the-Arduino-IDE-to-Program-ESP8266

ESP8266 Board Library: https://github.com/esp8266/Arduino

Creating a Twilio Account

For sending an SMS, the ESP8266 uses Twilio, an online API that allows you to send messages to a registered number. You will need to set up a trial account and copy the required info shown below along with the actual phone number you are using into the Arduino program.

image

For getting your SHA1 fingerprint the Twilio website provides information for securing this info along with code for their setup using the esp8266 with Twilio. I have listed the Twilio base website and the Twilio ESP8266 instructions below. [https://www.twilio.com/en-us](Twilio Website) [https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-esp8266-cpp](Using Twilio With the ESP8266)

Software Explanation

The ESP8266 will first print out any available wifi networks through the serial monitor for debugging reasons and to make sure that it can see the available wifi network you are trying to connect to. It connects to the wifi network based on the wifi information stored at the top of the program.

image

If this information is correct it will print out in the serial monitor that if found the connection and then wait for a signal received through digital pin 14 or D5 on the ESP8266 in which when it receives a high signal it will call the sendSMS function sending it a specific message.

image

The sendSMS function will then use the provided information about the twilio account to create an HTTP post request to send to the API which uses the base64 library to encode the account ID and authentication token. It will print out the request in the serial monitor along with what was returned from the request. This HTTP post request after being sent will have the API send the custom message to the listed phone number.

image

If you are having any errors using this code I would recheck your SMS client information to make sure it is all correct. Especially "auth_token" and "fp[]" as the authentication token and SHA1 Fingerprint can change after a certain amount of time.