I'm a beginner to Node Red and wondered how variables are implemented. Great guide and extremely useful 👍
@the_tux2 жыл бұрын
Great explenation. Simple, to the point and no yakety-yaking along. Somewhere YT still seems to have good content...
@d_sellers13 жыл бұрын
Very well made video. I found your webpage first and read over it. This video did an excellent job of demonstrating everything you mentioned in the text. With the information you gave, I should be able to improve my automations.
@TheHellis4 жыл бұрын
This makes it so much easier to set all variables that is used in one flow. You just set everything in a function node and with an inject. Then just trigger a read to keep everything in memory. Wow.. This really made my flows much easier to maintain.
@tarunarya17803 жыл бұрын
Thanks. I was going to use files to store data from another of your videos till I saw this. As a newbie I had to figure out how to get the debug to show the msg.payload.
@inbarajananbu86495 жыл бұрын
Well explained.. First time am seeing someone explaining about the scope in detail.. Very useful 👍
@agsonethetube3 жыл бұрын
Your videos are a great help
@stsmith19754 жыл бұрын
Excellent videos Steve. Many thanks
@jibinjosemathewjibinjosema76175 жыл бұрын
I am extremely thankful to you Sir, you explained everything very well and in detail...
@alainjacob9254 жыл бұрын
Hi Steve, many thanks for your explanation.
@doubando3 жыл бұрын
Thank you sir, very informative and exactly what Ive been looking for
@johnwilson39183 жыл бұрын
Thank you. Is there any 'init' process (perhaps by way of using an 'init-flow' javascript node) which is automatically executed/triggered, allowing me to initialise flow variables? I wanted to set up a clean way of initialising flow constants (like HTTP URLs).
@johnwilson39183 жыл бұрын
Ah! This is embarrassing. I've just watched your initialising node-red video. I can see you can use an auto 'inject' node to set flow variables.
@leonsteiner84122 жыл бұрын
ne explained , better than my teacher
@uweri_38516 жыл бұрын
very well explained. Hope we get much more videos from you.
@erikjorpes13256 жыл бұрын
Useful. Thanks for your guides related Node Red, Mosquitto and others.
@succubiuseisspin37073 жыл бұрын
Hi! Thanks a lot for the video! I am trying to store an array of objects in a global variable with „var myarray=global.get('myarray') || [];“ and then push objects into it „myarray.push({name:msg.deviceName,status:msg.payload});“ Afterwarts write the array back with „global.set('myarray',myarray);“ But as soon as the first object gets into the array the push() methods seems to stop working. No new elements are added. Any idea by chance ? :-)
@arifkarisman10165 жыл бұрын
Thank you mr.. soory mr.. how but method reset user object , with flow and global reset ???..
@humbertolagomarsino81075 жыл бұрын
Hi, i need your help PLEASE. i want to define a flow node to add some html code inside it and then use in a template node. I have this but isnt working --o-- flow.set("flowVariable","text"); var obtainData= flow.get("flowVariable"); msg.payload = obtainData; return msg; {{{flow.flowVariable}}} (this work but only with a tiny html code, i want to add a large html code, like and so on)
@lfmtube4 жыл бұрын
Thank you very much. Great video and very instructive!
@douglas4915 жыл бұрын
Amazing explanation. Thank you.
@guicmbh5 жыл бұрын
Thanks Steve, i don't understand this line of code: context.set('count',count); Why do you have to type Count twice? What is the difference between one and the other? When doing context.get you only did count one in between ' ', which in my understanding means a counter is natively available in the context object. Then you created a variable count, and that's what you also declared in the context.set, but why? Thanks
@stevecope5 жыл бұрын
with the get we used var count=context.get('count') the count in quotes is the count stored in the context object. When we store it back ''count' is the value in the context object and count is the variable we are using in the function node. Perhaps if I had used var c=context.get('count') context.set('count',c) it would make more sense Is that OK?
@guicmbh5 жыл бұрын
@@stevecope Thanks Steve, i understand one is the variable and the 'count' in quotes is the actual counter natively part of the context object. But why did you have to include the variable in the context.set in line 4 is my doubt. Line 1 - you create a variable from getting the counter of the context object Line 2 - you increment that variable with 1 unit Line 3 - you modify the msg.payload Line 4 - You store the counter back to the 'count' of the context object, but why also need to add the variable? I have tested without the variable and it does not work, but i don't understand this. Is it because you are setting the 'count' to have the same value as the variable? Is it mandatory to indicate where the value to be set in 'count' should be coming from? And that is how you did it? Could you also simply put a literal for testing purpose?
@stevecope5 жыл бұрын
@@guicmbh Because teh variable had or could have changed. You could also do context.set('count',1) to store 1 in the context variable count. think of it as the same as var count=1 Does that make sense?
@enricorighetto33025 жыл бұрын
Grazie molto chiaro, very well explained.
@TheJrahhal5 жыл бұрын
I was wondering if you show how the reset function works?
@stevecope5 жыл бұрын
Hi The reset functions are there to reset the flow and global counters to 0 or in the case of objects to {}.They aren't reset on a redeploy
@TheJrahhal5 жыл бұрын
@@stevecope awesome, thank you!
@timfries3985 жыл бұрын
very well done, thanks!
@michaelmcnaughton15356 жыл бұрын
Is there a method of programmaticaly changing the target file name of a file node. I would like to use a flag in my incoming data stream to trigger the name change. When the flag indicates, I would like the flow to produce a new target file name and supply it to the File node for future data streaming.
@stevecope6 жыл бұрын
I haven't found it. It is on my list to try and modify the node so that you can do that as I've a need for that as well. Rgds Steve
@stevecope6 жыл бұрын
Correction I just found an answer on aGoogle group. Leave the filename in the file node empty The in the function feeding the file node use msg.filename=""your filename"; I tried it and it works
@michaelmcnaughton15356 жыл бұрын
Steve Cope Thanks for the excellent advice. I put in a simple user function node to build the file name and put it into a flow context. Elementary from there.
@rjh88884 жыл бұрын
Thank you.
@stevmoon6 жыл бұрын
I'm having trouble. I'm not sure if its sytax or what but I can't seem to get it to work. I have a function to grab a numeric from the dashboard: var timer = msg.topic *1000; global.set('ontime', timer); return msg; An another to add the it to the msg object msg.delay: msg.delay = global.get('ontime'); //msg.delay = global.get('ontime') || 0; return msg; As is I get undefined in my msg.delay debug and if I use the commented version I get "0". It seem straight forward, but wont work for me... I even try the old method with no luck.
@stevecope6 жыл бұрын
Hi Use the ask-steve page on the site and send me the code for both functions and I'll take a look www.steves-internet-guide.com/ask-steve I was confused by the first line var timer = msg.topic *1000; I would have expected msg.payload
@stevmoon6 жыл бұрын
Thanks for the quick response. lol YES that was the problem. Such a simple error, of coarse my output was undefined, msg.topic is a string. This was the most trouble I've ever had with 5 lines of code, and after finding my error I feel embarrassed for my post.(first time using global/flow/context/ variables in Node Red)
@stevecope6 жыл бұрын
Not to worry. I've had problems with even fewer lines of code.
@gnakfaskdm4 жыл бұрын
Is there a way to store arrays in this way?
@stevecope4 жыл бұрын
Yes. var data=[1,2]; flow.set("data".data); same with objects. I almost always uses objects when there is more than one variable too store.
@BenDover-pq8xj5 жыл бұрын
6:28 in Totally confused - where is 'data' defined ? - 'local' is created by the var and then trying to assign 'data' to it but 'data not already defined anywhere, well, that I can see ????? also, for the very old time 'C' programmers, well hobbyist bitkickers from the early days, is a Node-Red "context" var the equiv to a 'C' "static" var ????, also are 'context' vars only relavent/usable in a function node ?. I have used your tutorial for Node Red Steve, as just over a year ago I desperately needed to get websockets going in a project, what a task that was but if it was not for one of your tutorial then I would have never done it, so many thanks for that one and keep up the good work, judging by all the other comments here it seems everyone else has got it so for sure it must be me, but I just cant get what I'm missing. Thks.
@francisco-chaves6 жыл бұрын
very good
@marceloap1405 жыл бұрын
THANKS.
@timjansen73494 жыл бұрын
How to store data in a variable that is also kept after a node red restart?
@stevecope4 жыл бұрын
Tim is is possible since a release 0.19. They are stored in a variable and copied to the disc every 30secs see www.steves-internet-guide.com/node-red-variables/ (at end) for more details
@timjansen73494 жыл бұрын
@@stevecope thanks it worked :D
@frankrubben82066 жыл бұрын
tnx
@neal12366 жыл бұрын
‘ ’ means char; " " means string, count is a string ,why you use 'count'? Sorry,my English is bad.