Node.js client for the Demo Steinkjer API.
See https://api.demosteinkjer.no/ for documentation. The API requires a key and a secret to be used.
var api = require'demosteinkjer-api''key' 'secret';
To get time series data for a given meter, a download url must first be obtained.
Although you receive a link, it will not be immediately available to use. This can be solved in multiple ways. If one tries to send a GET request to a resource that is not yet available. A response code of 202 will be returned. Thus you can keep on sending requests until it becomes available (check for status code) or you can download the url ahead of time to be somewhat certain it will be available when you need it.
var intervalId = setIntervalapireadDownloadURLdownloadURLif err return;console.logreadings;clearIntervalintervalId;;1000;
To get the latest reading for a meter, a url must not be obtained first:
Some of the meters have minute precision. Their IDs are available in the object
It is wise to cache results from the API, both meter readings and download urls. Redis is a wise choice for such a task. One way to do it is to create a key hash made of the meter id and the options for that reading
return sliceapplyargumentsreducereturn h + JSONstringifye;'';var key hashmeterID options
and store it in redis
var client = require'redis'createClient;clientsetkey data
key is a hash made using any method you'd prefer and
data is the data for that request.