File tree 2 files changed +9
-4
lines changed
2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change 83
83
84
84
< script type ="text/x-red " data-help-name ="emoncms in ">
85
85
< p > Fetches data from emoncms.</ p >
86
- < p > The < code > msg . payload < / c o d e > c o n t a i n s l a s t e m o n c m s f e e d v a l u e
86
+ < p > The < code > msg . topic < / c o d e > c o n t a i n s t h e n a m e o f t h e F e e d < / p>
87
+ < p > The < code > msg.payload</ code > contains last emoncms feed value</ p >
88
+ < p > The < code > msg . feed_data < / c o d e > c o n t a i n s a l l t h e f e e d d a t a < / p>
87
89
</ script >
88
90
89
91
< script type ="text/javascript ">
Original file line number Diff line number Diff line change @@ -160,7 +160,7 @@ module.exports = function(RED) {
160
160
if ( this . baseurl . substring ( 0 , 5 ) === "https" ) { http = require ( "https" ) ; }
161
161
else { http = require ( "http" ) ; }
162
162
this . on ( "input" , function ( msg ) {
163
- this . url = this . baseurl + '/feed/value .json' ;
163
+ this . url = this . baseurl + '/feed/aget .json' ;
164
164
this . url += '&apikey=' + this . apikey ;
165
165
var feedid = this . feedid || msg . feedid ;
166
166
if ( feedid !== "" ) {
@@ -169,14 +169,17 @@ module.exports = function(RED) {
169
169
http . get ( this . url , function ( res ) {
170
170
msg . rc = res . statusCode ;
171
171
msg . payload = "" ;
172
+ msg . feed_data = "" ;
172
173
res . setEncoding ( 'utf8' ) ;
173
174
res . on ( 'data' , function ( chunk ) {
174
- msg . payload += chunk ;
175
+ msg . feed_data += chunk ;
175
176
} ) ;
176
177
res . on ( 'end' , function ( ) {
177
178
if ( msg . rc === 200 ) {
178
179
try {
179
- msg . payload = JSON . parse ( msg . payload ) ;
180
+ msg . feed_data = JSON . parse ( msg . feed_data ) ;
181
+ msg . topic = msg . feed_data . name ;
182
+ msg . payload = msg . feed_data . value ;
180
183
}
181
184
catch ( err ) {
182
185
// Failed to parse, pass it on
You can’t perform that action at this time.
0 commit comments