Introduction: Automated Data Sending to AskSensors Using Node.js
In a previous tutorial, I showed how to send data to AskSensors IoT platform using the web browser. It was helpful especially for beginners and people don't have material in hand or don't work with electronics!
This made me thinking more about providing you different ways to communicate with AskSensors without using electronics. This instructable explains step-by-step how to conduct automated data sending to AskSensors using Node.js over HTTPS GET Requests.
Note for guys not familiar with Node.js:
- We will type command-line instructions, so you need to be comfortable with or at least know how to start a command-line tool like the Windows Command Prompt, or the Git shell.
So let's do it!
Step 1: Install Node.js and NPM
- First thing’s first: You need to download Node.js. It’s free and available for Windows, MacOs and Linux (in my case I'm using Windows).
Run the installer, follow the prompts in the installer. Accept the license agreement, click the NEXT button a bunch of times and accept the default installation settings.
NPM is distributed with Node.js, which means that when you download Node.js, you automatically get npm installed on your computer.
- Restart your computer. You will not be able to run Node.js until you restart your computer!
Step 2: Test the Node.js
To Make sure you have Node.js and NPM installed, we will run simple commands to see what version of each is installed and to run a simple test program:
- Test Node.js: To confirm that you have Node.js installed, type this command in your terminal:
This should print a version number.
- Test NPM: To check if you have NPM installed, you can run this command in your terminal:
- Run the code: open your command line program, navigate to the folder where you save the file and type:
You should see " Hello AskSensors!", means all fine!
Now, you have the Node.js and NPM ready. By next we will create an AskSensors account..
Step 3: Create a Free AskSensors Account
Step 4: Create a Sensor for Node.js Data
This video shows how to create a new sensor, add module, and get the sensor informations (Api Key In, ..).
Once you have your sensor and module set, copy down your Api Key In, we will need it for the next step.
Step 5: The Code
- Download this example code from the AskSensors github page. It provides you a simple and already tested code to start with.
- You need to install the https NPM package.
- Put your Api Key In generated for your sensor.
- This code will be sending data every 20 seconds, You can modify this by setting the timerInterval value.
var ApiKeyIn = '................'; // Api Key In var timerInterval = 20000; // timer interval
Step 6: Result
- Sign in to Asksensors, open your Sensor and show your module graph.
- You should see your graph plotting all the data sent from your Node.js.
Step 7: Well Done!
Thank you for reading.
I hope this helps!
Your feedback is important for us, please leave a comment!