-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttps_get.js
More file actions
35 lines (31 loc) · 1.16 KB
/
https_get.js
File metadata and controls
35 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Connect Raspberry Pi to AskSensors
* Description: This code sends dummy data to askSensors IoT platform over HTTPS GET Request.
* Author: https://asksensors.com, 2018
* github: https://github.com/asksensors
* Instructables: https://www.instructables.com/id/Connect-Raspberry-Pi-to-Asksensors-IoT-Platform-Us/
*/
// includes
var https = require('https');
const request = require('request');
// TODO: Raspberry Pi user Configuration
var ApiKeyIn = '...................'; // TODO: fill your sensor Api Key In given by https://asksensors.com
var writeInterval = 25000; // TODO: adjust timerInterval (in ms)
// API host name
var host = 'https://api.asksensors.com';
// Function declaration: send data
function send_data(){
var url = host + '/write/';
url+= ApiKeyIn;
url+= '?module1='
url+= 100*Math.random(); // random data in module 1
url+= '&module2='
url+= 100*Math.random(); // random data in module 2
console.log('Data sent to:' + url);
request(url, { json: true }, (err, res, body) => {
if (err) { return console.log(err); }
});
}
send_data();// send first data
// Send data every timerInterval
setInterval(send_data, writeInterval); // setInterval