Skip to content

Commit fbe2078

Browse files
authored
Return all feed data (#743)
1 parent a57bf53 commit fbe2078

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

io/emoncms/88-emoncms.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383

8484
<script type="text/x-red" data-help-name="emoncms in">
8585
<p>Fetches data from emoncms.</p>
86-
<p>The <code>msg.payload</code> contains last emoncms feed value
86+
<p>The <code>msg.topic</code> contains the name of the Feed</p>
87+
<p>The <code>msg.payload</code> contains last emoncms feed value</p>
88+
<p>The <code>msg.feed_data</code> contains all the feed data</p>
8789
</script>
8890

8991
<script type="text/javascript">

io/emoncms/88-emoncms.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ module.exports = function(RED) {
160160
if (this.baseurl.substring(0,5) === "https") { http = require("https"); }
161161
else { http = require("http"); }
162162
this.on("input", function(msg) {
163-
this.url = this.baseurl + '/feed/value.json';
163+
this.url = this.baseurl + '/feed/aget.json';
164164
this.url += '&apikey='+this.apikey;
165165
var feedid = this.feedid || msg.feedid;
166166
if (feedid !== "") {
@@ -169,14 +169,17 @@ module.exports = function(RED) {
169169
http.get(this.url, function(res) {
170170
msg.rc = res.statusCode;
171171
msg.payload = "";
172+
msg.feed_data = "";
172173
res.setEncoding('utf8');
173174
res.on('data', function(chunk) {
174-
msg.payload += chunk;
175+
msg.feed_data += chunk;
175176
});
176177
res.on('end', function() {
177178
if (msg.rc === 200) {
178179
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;
180183
}
181184
catch(err) {
182185
// Failed to parse, pass it on

0 commit comments

Comments
 (0)