banner



How To Send Data To Mongodb

mongolab-motion-layout

Arduino is an open-source electronics platform that tin acknowledge and interact with its environment through a variety of sensor types.  Information technology'due south great for hardware prototyping and one-off projects.

I just got an Arduino Board from our friends at SendGrid, who likewise gave me a little tutorial in the art of Arduino hacking. Inspired past the tutorial and armed with this new  board, I bought a passive infared (PIR) motion sensor from my local Radio Shack. Now I was ready to play; in item, I wanted to exist able to collect that continuous stream of hardware sensor data into a MongoDB database for logging, tendency analysis, system event correlation, etc.

To this terminate, I created the demo project "mongodb-motility", which I've fabricated public on Github. In the "mongodb-motion" Github repo, you will find an Arudino project that writes motility sensor data to a cloud MongoDB database at MongoLab and sends alerts via email based on certain criteria. I built this demo using Node.js and the MongoLab Remainder API.

Below, I'll go through exactly what hardware y'all need to make your own "mongodb-motion" projection a success, and how the code really works.

What Yous Need

The hardware used in this demo includes: an Arduino UNO R3 and a Parallax PIR motion sensor.

How the Code Works

You can use a variety of motion sensors with the Arduino. In this particular experiment, I used a PIR motion sensor. The PIR motion sensor behaves like a switch, with 'downwards' events emitted on motion detection and 'up' events a few seconds later on motion ceases to be detected.

On the receiving side, I used JohnnyFive, an appropriately named Node.js package that accepts sensor events and sends messages to the Arduino board.

With the ii ends prepare, I'll move on to the project'due south configuration file. In this demo, I've included a configuration file, config-sample.js, where credentials for the MongoLab REST API and for the electronic mail SMTP server tin can be added. In my case, I used the SendGrid SMTP service.

The configuration file also has two callbacks that determine when an email is emitted, ane for each type of event - "observe" and "ceased". I've used this characteristic to automatically send an e-mail alarm if an result timestamp is between seven:00pm and viii:00am, ostensibly when my office should be motionless... I'k out at that place watching you, office!

Once you lot've customized this config-sample.js file, exist sure to rename it to config.js in order for it to be usable.

If you inspect the project code, you lot'll notice that the MongoLab Rest API is called in the logMsg() office, using an https.request.

Edifice this little demo has given me some new ideas for hardware hacking the deject. I promise you lot give information technology a try besides.

Thanks to the Arduino, Node.js and Javascript communities, and special thanks to Rick Waldon for Johnny V, SendGrid for the UNO board, and a big shout out to @swiftalphaone for the Waza tutorial.

I'1000 MongoLab'south VP of Sales and Marketing. And I'k here to serve our customers' needs for MongoDB hosting in the deject.

About benwen

I'm MongoLab's VP of Sales and Marketing. And I'thou here to serve our customers' needs for MongoDB hosting in the deject.

How To Send Data To Mongodb,

Source: https://blog.mlab.com/2013/03/sensor-data-arduino-mongodb/

Posted by: jimenezenwhat.blogspot.com

0 Response to "How To Send Data To Mongodb"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel