Pulses per minute

677 views
Skip to first unread message

Dan Hoover

unread,
Feb 11, 2017, 11:33:51 PM2/11/17
to Node-RED
This is my second NOOB question. I'm humming right along getting things working the way I'd like, but I have another simple question.  

I have a flow sensor that puts out pulses in the form of 1s and 0s.  Ideally I'd like to count the number of pulses in a minute and then do something with that information.  How do I get that ppm number?  The sensor is definitely inputting. I just don't know what to do with that input.

Mark Setrem

unread,
Feb 12, 2017, 1:21:12 AM2/12/17
to Node-RED

Dan Hoover

unread,
Feb 12, 2017, 2:16:08 AM2/12/17
to Node-RED
I had not, but that thing is super helpful. I've searched pulse, timer, increment, counter, and got nothing, but that one seems to work.  

The only thing I can't figure out is how to pass that info into an http request.  I know if I want to pass the whole payload I can do something like


But that information is coming in as 
frequency:msg.payload:number

How do I parse that in there?

Cor Bosman

unread,
Feb 12, 2017, 7:53:52 AM2/12/17
to Node-RED
You can just say:  msg.payload.number


Nick O'Leary

unread,
Feb 12, 2017, 8:01:49 AM2/12/17
to Node-RED

Cor,

You are assuming that when Dan says 'frequency:msg.payload:number' he means his payload has a property called number. Or does it mean payload is of type number? His previous example was just that. This is why I've asked Dan to clarify where he got that text from as it isn't clear what it means.

Nick


On Sun, 12 Feb 2017, 12:53 Cor Bosman, <cor.b...@gmail.com> wrote:
You can just say:  msg.payload.number


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/30086a61-7b27-4e13-b4cc-db520e4a4d6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Hoover

unread,
Feb 12, 2017, 9:27:02 AM2/12/17
to Node-RED
This is one of those cases where I don't know exactly what I don't know.  I see the number in the debug. In the attached screenshot, it's the 11.8.  I need that to go into the url of my http request after the pause on the screen. When I was doing temperature I was just able to pass {{{payload}}} in there, but because my flow meter is spitting out pulses of 1s and 0s, I need a way to represent that over time, hence the frequency .

Screenshot attached.
pi_screenshot.png

Dan Hoover

unread,
Feb 12, 2017, 9:28:32 AM2/12/17
to Node-RED
Also, I get that the pi/15 is the gpio pin 15 of the pi... I just need the gist of how to address that stuff. I'm a php guy jumping in with both feet on this.


Colin Law

unread,
Feb 12, 2017, 9:34:47 AM2/12/17
to node...@googlegroups.com
The screenshot is showing that the payload from the frequency node
contains the number 15 so your html should work ok. What is the
problem with the way you have done it?

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/e4e2a859-6c17-4ad3-a0be-29830b954ecc%40googlegroups.com.

Colin Law

unread,
Feb 12, 2017, 9:36:01 AM2/12/17
to node...@googlegroups.com
I don't understand what question you are trying to ask here

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/72a51e6b-ea9c-4ed8-b066-9ff5c2c145c0%40googlegroups.com.

Dan Hoover

unread,
Feb 12, 2017, 9:41:42 AM2/12/17
to Node-RED
I need to get the 11.8 from that frequency:msg.payload:number passed into my url like
or something like that. I just don't get how to address those numbers in other places. 

Julian Knight

unread,
Feb 12, 2017, 9:46:13 AM2/12/17
to Node-RED
The "pi/15" is the msg.topic and the msg.payload is currently zero.

If you change the debug output to output the whole message, it will probably be clearer.

But the frequency node gives you the frequency of incoming messages so it will be wrong as I think you only want to count when the payload is 1 am I right? If so, you need to put a switch node in front of it and only allow through a message when the msg.payload = 1.

Julian Knight

unread,
Feb 12, 2017, 9:52:17 AM2/12/17
to Node-RED
To get your web request, you need to wire in an http request node after the frequency node.

Import this as an example for the settings:

[
   
{
       
"id": "a63281b1.c7abd",
       
"type": "http request",
       
"z": "462586cc.55d938",
       
"name": "",
       
"method": "GET",
       
"ret": "txt",
       
"url": "http://mydomain.com/mypage.php?freq={{{payload}}} ",
       
"tls": "",
       
"x": 532.5,
       
"y": 4536,
       
"wires": [
           
[]
       
]
   
}
]

Dan Hoover

unread,
Feb 12, 2017, 10:08:00 AM2/12/17
to Node-RED
I wish it worked that way, but it doesn't.  Here's my dilemma...

The frequency instructions clearly state that it can't be wired "inline".  

But I can't have that information flow straight into my http request or I'll DOS my server.

So I don't know how to get the information from the top branch into that bottom branch's http request. 

I'm sure it's something so simple, and that's what's driving me crazy.
pi_screenshot.png

Colin Law

unread,
Feb 12, 2017, 10:28:41 AM2/12/17
to node...@googlegroups.com
I was slightly confused by that too, but I believe it means that you
should not wire anything into the left side of the frequency node, not
that you cannot connect to anything on the right hand side. You have
connected to a debug node after all, and as far as the frequency node
is concerned it does not care what it is wired to. Try Julian's
suggestion.

Colin

On 12 February 2017 at 15:08, Dan Hoover <mud...@gmail.com> wrote:
> https://groups.google.com/d/msgid/node-red/52e98348-5338-4473-87b1-b72a05b7da56%40googlegroups.com.

Julian Knight

unread,
Feb 12, 2017, 10:31:33 AM2/12/17
to Node-RED
Agreed. It clearly outputs the frequency as a number and that is what you want.

One other improvement though. As you say, you don't want to spam your own server so put a limiter before the http request so it only triggers once a minute no matter how many inputs per second it gets.

Dan Hoover

unread,
Feb 12, 2017, 10:39:02 AM2/12/17
to Node-RED
I think I have it figured out.  By changing how often the frequency calculator sends out a msg I was able to control how often that http request fires. 

I still don't really have an understanding of how to address one particular part of a message payload if there is more than one piece of information in that payload.  

Dan Hoover

unread,
Feb 12, 2017, 10:41:11 AM2/12/17
to Node-RED
Yep. You're exactly right. I was able to get it to sample once a minute and only output that sample every 15 minutes which is enough information for my needs. THANK YOU so much.  I'm new to this, but this is going to be extremely helpful for me.  

Someone needs to make a 20 hour Udemy or Lynda class on this.  

Dave C-J

unread,
Feb 12, 2017, 10:51:15 AM2/12/17
to node...@googlegroups.com
maybe some introductory information on javascript objects would be useful... http://www.w3schools.com/js/js_objects.asp

Dave C-J

unread,
Feb 12, 2017, 11:02:50 AM2/12/17
to node...@googlegroups.com
And maybe a look at this may help get you going - http://noderedguide.com/

Dan Hoover

unread,
Feb 12, 2017, 11:59:43 AM2/12/17
to Node-RED
Thanks for the info. That's the kind of stuff I'm looking for.

Julian Knight

unread,
Feb 12, 2017, 12:09:27 PM2/12/17
to Node-RED
How about the 5 second version?

the msg variable that is passed between nodes is a JavaScript object that typically looks something like:

{ topic: "pi/15", payload: 0, _msgid: "47ffbfe2.6569c" }

the msgid is put there by Node-RED itself.

If you put a msg like that into a function node, you can get the elements of it (the attributes) by:

var myPayload = msg.payload;
var myTopic = msg.topic;

If the payload is actually more complex, as some are, perhaps something like:

{ topic: "pi/15", payload: { temperature: -10, humidity: 100, sensorName: "Outside" }, _msgid: "47ffbfe2.6569c" }

Then you can access the sensor data with code like:

var temperature = msg.payload.temperature;

and so on.

There is lots more but that's basically it. As I said previously, changing the debug node to output the full msg may give you a better understanding of the actual structure.

Dan Hoover

unread,
Feb 12, 2017, 3:13:08 PM2/12/17
to Node-RED
That is perfect! Thank you! I've been able to use this to access my data and already do some cool things with it. Thanks so much for taking the time to explain that.

Julian Knight

unread,
Feb 12, 2017, 6:49:35 PM2/12/17
to Node-RED
Pleasure. Enjoy!

Connor Clarry

unread,
Apr 25, 2017, 5:36:34 PM4/25/17
to Node-RED
I have a similar question using the frequency node discussed in this thread. I am trying to use 5 different flow sensors and convert their output to frequency. I can get one line of nodes to work, but when I use multiple frequency node, they all display the flow for one. For instance, if their is flow through sensor one, the frequency node for sensor one will display, but it will display for all the frequency nodes even though there is no flow through the other.

Any ideas why this might be?
There are no topic options within the frequency node so I don't know how to separate or distinguish the nodes from each other.

Here is my code, any help is appreciated

[{"id":"fc970bd2.e54088","type":"arduino in","z":"9454f48c.72abc8","name":"Sensor1","pin":"2","state":"INPUT","arduino":"eca26002.443b5","x":140,"y":120,"wires":[["879b206e.f9542","8a87da02.720f88"]]},{"id":"8c571203.b2e1e","type":"function","z":"9454f48c.72abc8","name":"K Factor","func":"msg.payload = (msg.payload/5.6);\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":120,"wires":[[]]},{"id":"641257ce.e3ff58","type":"smooth","z":"9454f48c.72abc8","name":"","action":"mean","count":"5","round":"1","x":400,"y":120,"wires":[["8c571203.b2e1e"]]},{"id":"cec6f3f6.297e6","type":"ui_text","z":"9454f48c.72abc8","group":"bb286d45.56e59","order":1,"width":0,"height":0,"name":"","label":"Flow Rate 1","format":"{{msg.payload}}","layout":"row-spread","x":690,"y":120,"wires":[]},{"id":"7d255f08.e26a9","type":"arduino in","z":"9454f48c.72abc8","name":"Sensor5","pin":"6","state":"INPUT","arduino":"eca26002.443b5","x":140,"y":360,"wires":[["577073f3.a70bfc"]]},{"id":"b2eb5b39.6528b8","type":"function","z":"9454f48c.72abc8","name":"K Factor","func":"msg.payload = (msg.payload/5.6);\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":360,"wires":[["d778329e.63ba3"]]},{"id":"c191caf7.ed3008","type":"smooth","z":"9454f48c.72abc8","name":"","action":"mean","count":"5","round":"1","x":400,"y":360,"wires":[["b2eb5b39.6528b8"]]},{"id":"d778329e.63ba3","type":"ui_text","z":"9454f48c.72abc8","group":"bb286d45.56e59","order":5,"width":0,"height":0,"name":"","label":"Flow Rate 5","format":"{{msg.payload}}","layout":"row-spread","x":690,"y":360,"wires":[]},{"id":"879b206e.f9542","type":"frequency","z":"9454f48c.72abc8","name":"freq1","interval":"1000","ntfyinterval":"250","x":273.33338165283203,"y":122.22221183776855,"wires":[["641257ce.e3ff58"]]},{"id":"577073f3.a70bfc","type":"frequency","z":"9454f48c.72abc8","name":"freq5","interval":"1000","ntfyinterval":"250","x":270,"y":360,"wires":[["c191caf7.ed3008"]]},{"id":"8a87da02.720f88","type":"debug","z":"9454f48c.72abc8","name":"","active":true,"console":"false","complete":"false","x":290,"y":220,"wires":[]},{"id":"eca26002.443b5","type":"arduino-board","z":"","device":"/dev/cu.usbmodemFA131"},{"id":"bb286d45.56e59","type":"ui_group","z":"","name":"Flow 1","tab":"692b4a84.386ef4","disp":true,"width":"6"},{"id":"692b4a84.386ef4","type":"ui_tab","z":"","name":"Flow Rates","icon":"dashboard"}]
Reply all
Reply to author
Forward
0 new messages