Skip to content

Commit 2960ade

Browse files
author
ssadams11
authored
Merge pull request #11 from osos/publicdata
added get public data - node
2 parents 7a375d7 + a0e8c22 commit 2960ade

File tree

3 files changed

+127
-5
lines changed

3 files changed

+127
-5
lines changed

netatmoNodes.html

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,74 @@
258258

259259
<!-- ************************************************************* -->
260260

261+
<script type="text/javascript">
262+
console.log("registering netatmo get public data");
263+
RED.nodes.registerType('get public data',{
264+
category: 'Netatmo',
265+
color: '#669966',
266+
defaults: {
267+
name: {value:""},
268+
lat_ne: {value: '15'},
269+
lon_ne: {value: '20'},
270+
lat_sw: {value: '-15'},
271+
lon_sw: {value: '-20'},
272+
required_data: {value:'rain,humidity'},
273+
filter: {value:"false"},
274+
creds: {value:"",type:"configNode"}
275+
},
276+
inputs:1,
277+
outputs:1,
278+
icon: "feed.png",
279+
label: function() {
280+
return "get public data";
281+
}
282+
});
283+
</script>
284+
285+
<script type="text/x-red" data-template-name="get public data">
286+
<div class="form-row">
287+
<label for="node-input-client_id"><i class="icon-tag"></i> Creds</label>
288+
<input type="text" id="node-input-creds" placeholder="Add netatmo creds">
289+
</div>
290+
<div class="form-row">
291+
<label for="node-input-lat_ne"><i class="icon-tag"></i> Latitude noth-east corner</label>
292+
<input type="text" id="node-input-lat_ne" value="15">
293+
</div>
294+
<div class="form-row">
295+
<label for="node-input-lon_ne"><i class="icon-tag"></i> Longitude noth-east corner</label>
296+
<input type="text" id="node-input-lon_ne" value="20">
297+
</div>
298+
<div class="form-row">
299+
<label for="node-input-lat_sw"><i class="icon-tag"></i> Latitude south-west corner</label>
300+
<input type="text" id="node-input-lat_sw" value="-15">
301+
</div>
302+
<div class="form-row">
303+
<label for="node-input-lon_sw"><i class="icon-tag"></i> Longitude south-west corner</label>
304+
<input type="text" id="node-input-lon_sw" value="-20">
305+
</div>
306+
<div class="form-row">
307+
<label for="node-input-required_data" title="any mix of Temperature,CO2,Rain,Humidity,Pressure,Noise"><i class="icon-tag"></i> Required data</label>
308+
<input type="text" id="node-input-required_data" value="rain,humidity">
309+
</div>
310+
<div class="form-row">
311+
<label for="node-input-filter"><i class="icon-tag"></i> Filter</label>
312+
<input type="text" id="node-input-filter" value="false">
313+
</div>
314+
<div class="form-row">
315+
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
316+
<input type="text" id="node-input-name" placeholder="Name">
317+
</div>
318+
</script>
319+
320+
<script type="text/x-red" data-help-name="get public data">
321+
<p>This node returns public data from netatmo with this username and credentials.</p>
322+
<p>Outputs an object called <b>msg</b> containing <b>msg.topic</b> and
323+
<b>msg.payload</b>. msg.payload is JSON.</p>
324+
<p>See <a href="https://dev.netatmo.com/resources/technical/reference/weatherapi/getpublicdata" target=_blank>https://dev.netatmo.com/resources/technical/reference/weatherapi/getpublicdata</a> for details on format</p>
325+
</script>
326+
327+
<!-- ************************************************************* -->
328+
261329
<script type="text/javascript">
262330
console.log("registering netatmo config node");
263331
RED.nodes.registerType('configNode',{
@@ -297,3 +365,4 @@
297365
<label for="node-input-device_id"><i class="icon-tag"></i> Device ID</label>
298366
<input type="text" id="node-config-input-device_id" placeholder="70:ee:.....">
299367
</div>
368+
</script>

netatmoNodes.js

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ module.exports = function(RED) {
168168
type: this.types
169169
};
170170
if ((this.beginDate !== '')&&(this.beginDate !== null)){
171-
options.date_begin = JSON.parse(this.beginDate)
171+
options.date_begin = JSON.parse(this.beginDate);
172172
}
173173
if ((this.endDate !== '')&&(this.endDate !== null)){
174-
options.date_end = (this.endDate === 'last' ? 'last' : JSON.parse(this.endDate))
174+
options.date_end = (this.endDate === 'last' ? 'last' : JSON.parse(this.endDate));
175175
}
176176
if ((this.limit !== '')&&(this.limit !== null)){
177-
options.limit = JSON.parse(this.limit)
177+
options.limit = JSON.parse(this.limit);
178178
}
179179

180180
api.getMeasure(options,function(err, measure) {
@@ -219,6 +219,59 @@ module.exports = function(RED) {
219219
}
220220
RED.nodes.registerType("get stations data",NetatmoGetStationsData);
221221
/***************************************************************/
222+
function NetatmoGetPublicData(config) {
223+
RED.nodes.createNode(this,config);
224+
this.creds = RED.nodes.getNode(config.creds);
225+
var node = this;
226+
this.on('input', function(msg) {
227+
config.lat_ne = config.lat_ne || '15';
228+
config.lon_ne = config.lon_ne || '20';
229+
config.lat_sw = config.lat_sw || '-15';
230+
config.lon_sw = config.lon_sw || '-20';
231+
config.required_data = config.required_data || 'rain,humidity';
232+
config.filter = config.filter || false;
233+
this.lat_ne = mustache.render(config.lat_ne, msg);
234+
this.lon_ne = mustache.render(config.lon_ne, msg);
235+
this.lat_sw = mustache.render(config.lat_sw, msg);
236+
this.lon_sw = mustache.render(config.lon_sw, msg);
237+
this.required_data = mustache.render(config.required_data, msg);
238+
this.filter = mustache.render(config.filter, msg);
239+
var netatmo = require('netatmo');
240+
241+
var auth = {
242+
"client_id": this.creds.client_id,
243+
"client_secret": this.creds.client_secret,
244+
"username": this.creds.username,
245+
"password": this.creds.password
246+
};
247+
var api = new netatmo(auth);
248+
249+
api.on("error", function(error) {
250+
node.error(error);
251+
});
252+
253+
api.on("warning", function(error) {
254+
node.warn(error);
255+
});
256+
257+
var options = {
258+
lat_ne: config.lat_ne,
259+
lon_ne: config.lon_ne,
260+
lat_sw: config.lat_sw,
261+
lon_sw: config.lon_sw,
262+
required_data: config.required_data,
263+
filter: config.filter,
264+
};
265+
266+
api.getPublicData(options,function(err, data) {
267+
msg.payload = data;
268+
node.send(msg);
269+
});
270+
});
271+
272+
}
273+
RED.nodes.registerType("get public data",NetatmoGetPublicData);
274+
/***************************************************************/
222275
function NetatmoConfigNode(n) {
223276
RED.nodes.createNode(this,n);
224277
this.client_id = n.client_id;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "git+https://github.com/ssadams11/node-red-contrib-netatmo.git"
1111
},
1212
"dependencies": {
13-
"netatmo": "2.0.0",
13+
"netatmo": "2.2.0",
1414
"mustache": "2.2.1"
1515
},
1616
"version": "0.1.5",
@@ -37,4 +37,4 @@
3737
"email": "[email protected]"
3838
}
3939
]
40-
}
40+
}

0 commit comments

Comments
 (0)