Created
August 16, 2016 07:24
-
-
Save xopr/b23f19e8812f1ff70dd13bf765fd91b6 to your computer and use it in GitHub Desktop.
nodejs script that connects https://github.com/ACKspace/IoTaps with https://github.com/ACKspace/spaceAPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict" | |
var request = require( "request" ); | |
var sensorIds = [ | |
"TAP_TEMP", | |
"PARTY_TENT_TEMP", | |
"ARMY_TENT_TEMP", | |
"TAP_OPEN", | |
"FISSA_ENABLED", | |
]; | |
function fetchData( _url ) | |
{ | |
request( _url, function( _error, _response, _body ) | |
{ | |
if ( _error || _response.statusCode !== 200 ) | |
return; | |
var data = _body.split("\r\n"); | |
data.pop(); | |
var url = "https://ack.space/spaceAPI/?update=sensors&key=<API_KEY>"; | |
data.forEach( function( _val, _idx ) | |
{ | |
url += "&address[]=" + sensorIds[ _idx ] + "&value[]=" + _val + "&type[]=celcius"; | |
} ); | |
request( url, function( _error, _response, _body ) | |
{ | |
if ( _error || _response.statusCode !== 200 ) | |
return; | |
} ); | |
} ); | |
} | |
var timer = setInterval( fetchData.bind( this, "http://<IP_ADDRESS>:8182/raw.txt" ), 3000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment