Intro: Connect Raspberry Pi to Asksensors Using Node.js
This tutorial is useful for anyone looking to connect a Raspberry Pi to AskSensors IoT platform using Node.js .
If you don’t currently own a Raspberry Pi, I will recommend you to get a Raspberry Pi 3, because it's fast and you will not need to buy a separate USB Wi-Fi adapter. In addition, we will need to install node.js on the Raspberry Pi and many Node.js script sources require a Raspberry Pi based on the ARMv7+ architecture such as the Pi 3 or Pi 2 and will not work with the Raspberry Pi 1 Model B/B+ or the Raspberry Pi Zero.
But don't worry, it's pretty straight forward, just follow the steps!
Note: You may need to do a first test of node.js with AskSensors from your computer (Windows/Linux/MacOs), my previous instructable demonstrates a step by step guide for automated data Sending to AskSensors using node.js.
Step 1: Materials You Need
- Raspberry Pi 3 Model B+ or Model B (your can also use a Raspberry Pi 2 Model B)
- USB micro cable to power up your Pi.
- MicroSD card, I recommend a class 10 card that is 16 GB or higher.
- MicroSD to SD memory card adapter, you will need to use the SD card reader on your laptop/desktop to write to the microSD card.
Step 2: Set Up Your Raspberry Pi
Running a basic setup of Raspbian on Raspberry Pi become easy and clearly explained in this Getting Started Guide. Here are the main steps:
- Download NOOBS,
- Extract it on your SD
- Plug it in and turn on the Raspberry Pi.
- When prompted, choose to install Raspbian and let it run.
That's it, Now we have an amazing Raspberry Pi system that can be used for a variety of tasks!
Step 3: Install Node Js
Here we go in the node.js installation, Installing an ARM-version of Node become very easy!
- Make sure you are connected to internet
- Open the terminal on the Raspberry Pi. Type these commands:
sudo dpkg -i node_latest_armhf.deb
Basically. It shouldn't take too long to download and install.
You have also the option to specify the link address of the version you need:
Go to node.js download page and copy the link address of the version of ARM that you need. For example:
Step 4: Test Your Node
To make sure that node.js runs correctly, Type the commands below. It should return the current version of node and npm installed.
Make sure it doesn't give any error. If everything is ok, we can move to the next step!
Step 5: Sign Up for Asksensors
Signing up for AskSensors account is easy and free, create a new account on https://asksensors.com.
Create a new Sensor with at least one module, Save it, and show the module 1 graph.
A unique Api Key In will be provided, we will use it in the next step.
Step 6: Run the Node.js Script
The node.js demo we are suggesting sends a dummy data to AskSensors over HTTPS GET Requests, every 20 seconds (20 seconds was set as an example, you can set different time interval).
You will need to set your Api Key In in order to send data to the sensor module you have created as shown in the previous step (The image above shows my Api Key In in the Sensor information Tab).
Now your are ready to run the final script :
That's it! Enjoy seeing your dummy data plotted in the AskSensor module graph!
Step 7: Done!
Thank you for reading. feel free to comment!
We are going to publish many useful instructables in the future, follow us!
Hope to see you then :)