Skip to content

Instantly share code, notes, and snippets.

@xopr
Created August 16, 2016 07:24
Show Gist options
  • Save xopr/b23f19e8812f1ff70dd13bf765fd91b6 to your computer and use it in GitHub Desktop.
Save xopr/b23f19e8812f1ff70dd13bf765fd91b6 to your computer and use it in GitHub Desktop.
"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