Imagine how convenient it would be to have a device that sends in your location to your family/loved ones on the fly. The instances where such a device comes handy is vast. The project simply sends in your location as an SMS to the number you have inputted.
- Bolt IoT module
- TTP223 touch sensor
- Connecting wires
- Breadboard(to hold the sensor in place)
- VS Code(IDE): https://code.visualstudio.com/download
- Node JS(Back-end runtime environment): https://nodejs.org/en/download/
- Bolt API: https://docs.boltiot.com/docs/api-request-syntax
- Twilio(SMS service): https://www.twilio.com/login
- Bootstrap(CSS framework): https://getbootstrap.com/docs/5.0/getting-started/introduction/
- Connect the VCC hole of the sensor to the 5V pin of the Bolt IoT module.
- Connect the I/O hole of the sensor to digital pin 1 of the module.
- Finally, Connect the GND hole to the GND pin of the module and Voila! The hardware part of the project is ready.
STEP 1: To install Node JS and VS code on your Windows system, you can follow this video: Node js setup
STEP 2: If you have not worked with Node JS or Express before, I would suggest going through this tutorial to help you set your project up:
Additionally, you may look for other sources of information to deepen your understanding on them.
STEP 3: Here is a list of npm packages you should download in the project directory through your terminal with the command:
npm install "package-name"
(no double quotes)
- express https://www.npmjs.com/package/express
- body-parser https://www.npmjs.com/package/body-parser
- dotenv https://www.npmjs.com/package/dotenv
- axios https://www.npmjs.com/package/axios
- ejs https://www.npmjs.com/package/ejs
- twilio https://www.twilio.com/docs/sms/quickstart/node
- node-cron https://www.npmjs.com/package/node-cron
STEP 4: Create two new directories(views and public) in the main project directory. The views folder contains all the files with .ejs extension and the public folder consists of the static files.(NOTE: do not change the names of these directories)
- The views folder contains index.ejs and home.ejs
- The public folder contains styles.css
In the directory tree above,
- Tracker2 is the name of the project directory
- index.js is the main JavaScript file that houses the back-end code
- .env is used to store environment variables
- package.json file, package-lock.json file and node_modules directory are automatically created when you initialize the project and install the npm packages
STEP 5: In the .env file, replace the placeholders with your data. To get your Bolt Device ID and API key, have a look at the images below:
To get the SID and AUTH token from Twilio, login to your Twilio account and follow the image below:
Now, replace the values obtained above to these placeholders in the .env file. Code:
//.env file
TWILIO_ACCOUNT_SID=Your Twilio SID
TWILIO_AUTH_TOKEN=Your Twilio auth token
DEVICE_ID=Your Bolt Device's ID
DEVICE_API=Your Bolt API key
//Make sure you don't have spaces in between and no quotes
STEP 6: The index.js file(entry point of the node JS application) has the following code:
Similarly, the code for index.ejs, home.ejs and styles.css is given below:
- index.ejs https://gist.github.com/rishabhAjay/9e4ac42bb28f4026567aaacfefba735f
- home.ejs https://gist.github.com/rishabhAjay/86da505545b9c01891daf5ee919cbada
//styles.css
.mainBody {
display: flex;
flex-direction: column;
align-items: center;
}
To start your server locally, use node index.js
in your terminal and head over to http://localhost:3000 on a web browser(preferably Chrome)
- When you go to the http://localhost:3000, you get the page to check whether your device is online or not.
- If your Bolt device is offline, a message pops up.
- If it is online, you are redirected to a new page which asks you for the Twilio phone number and your number. You will be required to fill in all the details and check the radio button. The phone numbers should start with +17 and +91 respectively.
- After you are done entering the details, you will be redirected to a new page which MUST BE KEPT ACTIVE until you want the instance to end by clicking the "off" button. You must not QUIT, GO BACK or RELOAD the page. Since a cron job is running for the particular instance, it must be terminated by clicking the "off" button. You should keep the browser idle on this page until you want to switch the tracker off.
- If in case you forgot to terminate the cron job or have multiple cron jobs running, you have to quit your local server(CTRL + C) and start over.
- You will be redirected to the first page after clicking the "off" button
- Make sure you don't click the BACK, QUIT or RELOAD buttons on your browser after starting the instance. You may end up creating multiple such instances which will cause a mess.
- Always SWITCH the tracker OFF and then quit the browser so that no instance is left hanging.
- If you wish to keep sending your location via the SMS and keep the sensor active, keep the browser IDLE after you initiate the instance(i.e. on the page that lets you switch OFF the tracker).
- The project utilizes JavaScript's built-in geolocation services so this project does not require a GPS module.
To deploy your web application, you can use heroku or any other deploying service. You can follow this documentation to deploy your website on heroku: https://devcenter.heroku.com/articles/getting-started-with-nodejs
In this project, we integrated a node.js web application with Bolt API(source: https://forum.boltiot.com/t/support-for-node-js/17092/2?u=rishabhajay24) and built a prototype which sends your location to your friends/family with just a touch via a web application interface.
Any suggestions or improvements to the web application are welcome.