Neurio flow to gather Energy Data

222 views
Skip to first unread message

Blue Collar Ingenuity

unread,
Nov 17, 2015, 6:49:04 PM11/17/15
to Node-RED

I have the following flow working; 















It produces the following info; 

{ "timestamp": "2015-11-17T23:37:13.701Z", "channelMeasurements": [ { "id": 1, "powerW": 2613.433, "reactivePowerVAR": 973.784, "voltage": 121.116 }, { "id": 2, "powerW": 483.512, "reactivePowerVAR": -119.128, "voltage": 122.362 }, { "id": 3, "powerW": -0.118, "reactivePowerVAR": -0.118, "voltage": 0.203 }, { "id": 4, "powerW": 0.148, "reactivePowerVAR": -0.118, "voltage": 121.117 } ], "sensorReadings": [ { "channel": 1, "powerKW": 2.613, "energyImportedkWH": 4592.409, "energyExportedkWH": 0, "reactivePowerkVAR": 0.974, "voltageV": 121.116 }, { "channel": 2, "powerKW": 0.484, "energyImportedkWH": 2970.707, "energyExportedkWH": 0, "reactivePowerkVAR": -0.119, "voltageV": 122.362 }, { "channel": 3, "powerKW": 3.097, "energyImportedkWH": 7560.407, "energyExportedkWH": 0, "reactivePowerkVAR": 0.855, "voltageV": 121.739 }, { "channel": 4, "powerKW": 0 ....

How do I pull the individual pieces (powerW as an example) and send it emoncms. 

I have also tried the following flow 


It Works except for the Total power because it tries to pull data from the second table and I don't know how to reference it.
This works for CT  tr:nth-child(3) > td:nth-child(2) but tr:nth-child(11) > td:nth-child(2) doesnt work for power
Hope this isn't to confusing :) Jeff  











 

  

Mark Setrem

unread,
Nov 18, 2015, 4:30:32 AM11/18/15
to Node-RED
So if understand your post, you want us to help you grab the TotalPower from a data feed.  

But you aren't going to show us any of your workings ( i.e. what you are currently doing in the function nodes) .

Forget about the table (in which the headings are confusingly different from the data you posted)
My guess is that you need to read up on javascript objects and arrays and how to reference them.  There are lots of guides on the web that help to explain this.

Then simplify what you are trying to do.  
I assume that TotalPower is an addition of several values?  You can quickly configure the debug node to display something other then msg.payload.  So it is easy to use it to walk through msg.payload focussing in on the piece of the data you want.
So for example start by displaying  msg.payload.sensorReadings when you can display that and get the expected result then add to it to target a bit of the array.

When you can display each of the data items you want it should be easy to recreate that in a function node where you can sum them etc prior to exporting them to emoncms.




Blue Collar Ingenuity

unread,
Nov 18, 2015, 1:06:36 PM11/18/15
to Node-RED
Thanks Mark, 
                      Sorry for the scattered post with no code. I do know better. I will focus on the first method and post my functions nodes when I get stuck.
Jeff  





Blue Collar Ingenuity

unread,
Nov 18, 2015, 7:18:36 PM11/18/15
to Node-RED
OK, I followed your instructions. Here is the flow and code 














Function 
var parsed = msg.payload;
var msg = {
payload : {
timestamp : new Date(),
channelMeasurements : [],
sensorReadings : [],
summary : {
channelMeasurementsTotal : 0,
energyImportedkWHTotal : 0,
energyExportedkWH : 0,
powerKWTotal : 0
}
}
};
msg.payload.channelMeasurements.push(loadChannel(parsed, 5));
msg.payload.channelMeasurements.push(loadChannel(parsed, 9));
msg.payload.channelMeasurements.push(loadChannel(parsed, 13));
msg.payload.channelMeasurements.push(loadChannel(parsed, 17));

msg.payload.sensorReadings.push(loadSensorReading(parsed, 28));
msg.payload.sensorReadings.push(loadSensorReading(parsed, 34));
msg.payload.sensorReadings.push(loadSensorReading(parsed, 40));
msg.payload.sensorReadings.push(loadSensorReading(parsed, 46));
msg.payload.sensorReadings.push(loadSensorReading(parsed, 52));
msg.payload.sensorReadings.push(loadSensorReading(parsed, 58));
 
for(var c in msg.payload.channelMeasurements) {
var i = msg.payload.channelMeasurements[c];
msg.payload.summary.channelMeasurementsTotal += i.powerW;
}


for(var c in msg.payload.sensorReadings) {
var i = msg.payload.sensorReadings[c];
msg.payload.summary.energyImportedkWHTotal += i.energyImportedkWH;
msg.payload.summary.energyExportedkWH += i.energyExportedkWH;
msg.payload.summary.powerKWTotal += i.powerKW;
}

context.global.neurio = msg.payload;


return msg;


function loadSensorReading(parsed, start) {
return {
channel : new Number(parsed[start]),
powerKW : new Number(parsed[start+1]),
energyImportedkWH : new Number(parsed[start+2]),
energyExportedkWH : new Number(parsed[start+3]),
reactivePowerkVAR : new Number(parsed[start+4]),
voltageV : new Number(parsed[start+5]),
};
}

function loadChannel(parsed, start) {
return {
id : new Number(parsed[start]),
powerW : new Number(parsed[start+1]),
reactivePowerVAR : new Number(parsed[start+2]),
voltage : new Number(parsed[start+3]),
};
}

_________________________________________________________

When I insert msg.payload.summary.powerKWTota into debug node I get the correct response. Now how do I get the those individual pieces to the Emoncms node? Do I write another function or is there an easier way to split all the data up? 

Thanks 
 

Mark Setrem

unread,
Nov 19, 2015, 6:23:02 AM11/19/15
to Node-RED

I notice in your screen shot the emoncms node you are using has a pinkish background.  But when I look at 
The latest node has a blue background.  

1) are you sure you are on the latest version of node-red?  and the latest version of the emoncms node?

The http://flows.nodered.org/node/node-red-node-emoncms page includes the information you would normally see if you click on a node after you've dragged it onto the workspace and look at the info tab on the right hand side.

This shows the format you need to use: "

The msg.payload can contain either a comma separated list of name value pairs, e.g.

    name:value,...

"

So in a new function you can now create the data you want e.g


msg.payload = "TotalPowerKW:"+msg.payload.summary.powerKWTota;

return msg;


and pass that on to the emoncms node.




Blue Collar Ingenuity

unread,
Nov 26, 2015, 8:52:30 PM11/26/15
to Node-RED
Thanks AGAIN Mark! 
I have the data stripped out now with your example and the New emoncms node installed. It appears to be working but Emoncms is not seeing my feed. I'm not sure what I should put in the "NODE" field. I believe my string is OK and I setup the key correctly from my emoncms. 

Mark Setrem

unread,
Nov 27, 2015, 3:27:21 AM11/27/15
to Node-RED

It might sound daft but when you say emoncms is not seeing your data where are you looking?

The "input API help" link from the input scene in Emoncms should explain what to put in the node field.

I'd probably ignore your data for the time being and try to send a test value to rule out any issues.  

There's also a very active emoncms support forum on http://openenergymonitor.org/emon/

Blue Collar Ingenuity

unread,
Nov 28, 2015, 9:10:39 PM11/28/15
to Node-RED
Still stuck and can't get the Emoncms node working 



So for Base URL I put "http://emoncms.org" and my api key....I can not get this to work , I get ERROR Node not deployed

it seems simple but I can't get it :( 

Jeff 

Mark Setrem

unread,
Nov 29, 2015, 6:38:14 AM11/29/15
to Node-RED

OK, so lets check your API key has the right permissions.

If you go back to the "input API help" on emoncms.org you will see example of the URL to post data to emoncms.org

Create a url with your apikey e.g.


post that into the address bar of your browser.  What do you see?  Do you then see the data in emoncms?


Blue Collar Ingenuity

unread,
Nov 29, 2015, 1:05:22 PM11/29/15
to node...@googlegroups.com
Ok, 
      Another and last fresh install. I installed the .img (Jessie with NR)  from the raspberry Pi website. Your test produced an ok and sent the data to emoncms. Downloaded the Emoncms node and configured as per my post. All good now....Emoncms is seeing my feed. 

Jeff 

--
http://nodered.org
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/k-9z5bzzjJA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Blue Collar Ingenuity

unread,
Dec 10, 2015, 9:04:18 PM12/10/15
to Node-RED
Update: I currently have a flow working from my Neurio to emoncms that takes data from (local)192.168.1.127/both_tables.html and parse it to a json string. The issue I'm having is that my local devices freezes randomly and won't allow access to this page. I contacted Neurio and they leaked me an update that the new firmware supports a json object. So now my goal is to breakdown the object and get the info to emoncms. This is a big learning step for me.  (Just signed up for a javascript course at the age of 46 :)) 

My flow 

[{"id":"6dc4aa9b.923b54","type":"inject","z":"ff2aad21.00d55","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":155,"y":523,"wires":[["d1ba3c5c.2e45c"]]},{"id":"d1ba3c5c.2e45c","type":"http request","z":"ff2aad21.00d55","name":"","method":"GET","ret":"obj","url":"http://192.168.1.127/readings_json.json","x":332,"y":522,"wires":[["942888b2.6bd778"]]},{"id":"3718c505.c8e73a","type":"debug","z":"ff2aad21.00d55","name":"","active":true,"console":"false","complete":"payload","x":681,"y":525,"wires":[]},{"id":"942888b2.6bd778","type":"json","z":"ff2aad21.00d55","name":"","x":496,"y":523,"wires":[["3718c505.c8e73a"]]}]

Produces (Debug) 
10/12/2015, 20:50:583718c505.c8e73amsg.payload : string [921]{"Timestamp":"2015-12-11T01:51:01Z","Channel_Readings":[{"Type":"PHASE_A_CONSUMPTION","Channel":1,"eImp_kWh":5282.851,"eExp_kWh":0,"rPwr_kVAR":0.837,"Vol_V":120.311},{"Type":"PHASE_B_CONSUMPTION","Channel":2,"eImp_kWh":3486.211,"eExp_kWh":0,"rPwr_kVAR":-0.117,"Vol_V":121.462},{"Type":"CONSUMPTION","Channel":3,"eImp_kWh":8766.354,"eExp_kWh":0,"rPwr_kVAR":0.72,"Vol_V":120.887},{"Type":"SUBMETER","Label":"","Channel":4,"eImp_kWh":0.018,"eExp_kWh":0,"rPwr_kVAR":0,"Vol_V":0},{"Type":"SUBMETER","Label":"","Channel":5,"eImp_kWh":0.018,"eExp_kWh":0,"rPwr_kVAR":0,"Vol_V":0},{"Type":"SUBMETER","Label":"","Channel":6,"eImp_kWh":0,"eExp_kWh":0,"rPwr_kVAR":0,"Vol_V":0}],"CT_Measurements":[{"CT":1,"Pwr_W":2748.404,"rPwr_VAR":836.826,"Vol_V":120.311},{"CT":2,"Pwr_W":772.355,"rPwr_VAR":-116.589,"Vol_V":121.462},{"CT":3,"Pwr_W":-0.118,"rPwr_VAR":-0.177,"Vol_V":0.203},{"CT":4,"Pwr_W":0.148,"rPwr_VAR":-0.118,"Vol_V":120.313}]}
Using this example (Emoncms) 

The msg.payload can contain either a comma separated list of name value pairs, e.g.

    name:value,...

"


It would be great to send all the data string at once. I'm assuming I have to break the long objects into two short objects name:value,....

That is were my skills fall short....just a bit of kick hopefully I can figure it all out. My first contribution to the NR IOT world :) . 


When I try to break down the string the function node doesn't like me using numbers (Type":"PHASE_A_CONSUMPTION","Channel":1,"eImp_kWh":value) Channel:1  

Here's hoping this makes sense :) 

Jeff 








On Thursday, November 19, 2015 at 6:23:02 AM UTC-5, Mark Setrem wrote:

Mark Setrem

unread,
Dec 11, 2015, 3:39:51 AM12/11/15
to Node-RED
Try googling "JavaScript arrays and objects"
Which should give you the kick you need.

The other tip i would have is to forget about emoncms at the moment.

Link the input node up to a debug node and change the debug node config from displaying msg.payload to displaying the path of a specific piece of data. When you can navigate around your data you can then write a full function node to do the format conversion.

Dave C-J

unread,
Dec 11, 2015, 5:51:22 AM12/11/15
to node...@googlegroups.com
Hi, I updated the emoncms node a few days ago so that it should now accept a complete object. However what you have there is a string representation of an object - the clue being the top of the debug - msg.payload : string [921].
So you need to transform that into an object - simplest way is to pass it through the JSON node which does just that. (and vice versa if so required).

Then we can see the object contains some header data plus two arrays - one of the Readings and one of CT_Measurements.... which should now be gettable as msg.payload.Channel_Readings[0]  (for the first one) and  ...[1] ..[2]  etc and msg.payload.CT_Measurements[0]   ...[1]   etc

We can then see there are 6 channel radings and 4 ct_measurements... so I don't know how they relate to each other or how you would want to handle each of those into emoncms... so As Mark implies you'll have to iterate over the arrays yourself to pull out the bits you want.

PS - cut and paste that string into jsonlint.com to see it formatted more nicely.
Reply all
Reply to author
Forward
0 new messages