Return all feed data (#743)

This commit is contained in:
Brian Orpin 2021-02-07 22:32:58 +00:00 committed by GitHub
parent a57bf5383f
commit fbe2078324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -83,7 +83,9 @@
<script type="text/x-red" data-help-name="emoncms in">
<p>Fetches data from emoncms.</p>
<p>The <code>msg.payload</code> contains last emoncms feed value
<p>The <code>msg.topic</code> contains the name of the Feed</p>
<p>The <code>msg.payload</code> contains last emoncms feed value</p>
<p>The <code>msg.feed_data</code> contains all the feed data</p>
</script>
<script type="text/javascript">

View File

@ -160,7 +160,7 @@ module.exports = function(RED) {
if (this.baseurl.substring(0,5) === "https") { http = require("https"); }
else { http = require("http"); }
this.on("input", function(msg) {
this.url = this.baseurl + '/feed/value.json';
this.url = this.baseurl + '/feed/aget.json';
this.url += '&apikey='+this.apikey;
var feedid = this.feedid || msg.feedid;
if (feedid !== "") {
@ -169,14 +169,17 @@ module.exports = function(RED) {
http.get(this.url, function(res) {
msg.rc = res.statusCode;
msg.payload = "";
msg.feed_data = "";
res.setEncoding('utf8');
res.on('data', function(chunk) {
msg.payload += chunk;
msg.feed_data += chunk;
});
res.on('end', function() {
if (msg.rc === 200) {
try {
msg.payload = JSON.parse(msg.payload);
msg.feed_data = JSON.parse(msg.feed_data);
msg.topic = msg.feed_data.name;
msg.payload = msg.feed_data.value;
}
catch(err) {
// Failed to parse, pass it on