How to Store Data In Node Red Variables

  Рет қаралды 84,443

Steve Cope

Steve Cope

Күн бұрын

Пікірлер: 49
@willo300
@willo300 Жыл бұрын
I'm a beginner to Node Red and wondered how variables are implemented. Great guide and extremely useful 👍
@the_tux
@the_tux 2 жыл бұрын
Great explenation. Simple, to the point and no yakety-yaking along. Somewhere YT still seems to have good content...
@d_sellers1
@d_sellers1 3 жыл бұрын
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.
@TheHellis
@TheHellis 4 жыл бұрын
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.
@tarunarya1780
@tarunarya1780 3 жыл бұрын
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.
@inbarajananbu8649
@inbarajananbu8649 5 жыл бұрын
Well explained.. First time am seeing someone explaining about the scope in detail.. Very useful 👍
@agsonethetube
@agsonethetube 3 жыл бұрын
Your videos are a great help
@stsmith1975
@stsmith1975 4 жыл бұрын
Excellent videos Steve. Many thanks
@jibinjosemathewjibinjosema7617
@jibinjosemathewjibinjosema7617 5 жыл бұрын
I am extremely thankful to you Sir, you explained everything very well and in detail...
@alainjacob925
@alainjacob925 4 жыл бұрын
Hi Steve, many thanks for your explanation.
@doubando
@doubando 3 жыл бұрын
Thank you sir, very informative and exactly what Ive been looking for
@johnwilson3918
@johnwilson3918 3 жыл бұрын
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).
@johnwilson3918
@johnwilson3918 3 жыл бұрын
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.
@leonsteiner8412
@leonsteiner8412 2 жыл бұрын
ne explained , better than my teacher
@uweri_3851
@uweri_3851 6 жыл бұрын
very well explained. Hope we get much more videos from you.
@erikjorpes1325
@erikjorpes1325 6 жыл бұрын
Useful. Thanks for your guides related Node Red, Mosquitto and others.
@succubiuseisspin3707
@succubiuseisspin3707 3 жыл бұрын
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 ? :-)
@arifkarisman1016
@arifkarisman1016 5 жыл бұрын
Thank you mr.. soory mr.. how but method reset user object , with flow and global reset ???..
@humbertolagomarsino8107
@humbertolagomarsino8107 5 жыл бұрын
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)
@lfmtube
@lfmtube 4 жыл бұрын
Thank you very much. Great video and very instructive!
@douglas491
@douglas491 5 жыл бұрын
Amazing explanation. Thank you.
@guicmbh
@guicmbh 5 жыл бұрын
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
@stevecope
@stevecope 5 жыл бұрын
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?
@guicmbh
@guicmbh 5 жыл бұрын
@@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?
@stevecope
@stevecope 5 жыл бұрын
@@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?
@enricorighetto3302
@enricorighetto3302 5 жыл бұрын
Grazie molto chiaro, very well explained.
@TheJrahhal
@TheJrahhal 5 жыл бұрын
I was wondering if you show how the reset function works?
@stevecope
@stevecope 5 жыл бұрын
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
@TheJrahhal
@TheJrahhal 5 жыл бұрын
@@stevecope awesome, thank you!
@timfries398
@timfries398 5 жыл бұрын
very well done, thanks!
@michaelmcnaughton1535
@michaelmcnaughton1535 6 жыл бұрын
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.
@stevecope
@stevecope 6 жыл бұрын
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
@stevecope
@stevecope 6 жыл бұрын
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
@michaelmcnaughton1535
@michaelmcnaughton1535 6 жыл бұрын
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.
@rjh8888
@rjh8888 4 жыл бұрын
Thank you.
@stevmoon
@stevmoon 6 жыл бұрын
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.
@stevecope
@stevecope 6 жыл бұрын
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
@stevmoon
@stevmoon 6 жыл бұрын
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)
@stevecope
@stevecope 6 жыл бұрын
Not to worry. I've had problems with even fewer lines of code.
@gnakfaskdm
@gnakfaskdm 4 жыл бұрын
Is there a way to store arrays in this way?
@stevecope
@stevecope 4 жыл бұрын
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-pq8xj
@BenDover-pq8xj 5 жыл бұрын
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-chaves
@francisco-chaves 6 жыл бұрын
very good
@marceloap140
@marceloap140 5 жыл бұрын
THANKS.
@timjansen7349
@timjansen7349 4 жыл бұрын
How to store data in a variable that is also kept after a node red restart?
@stevecope
@stevecope 4 жыл бұрын
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
@timjansen7349
@timjansen7349 4 жыл бұрын
@@stevecope thanks it worked :D
@frankrubben8206
@frankrubben8206 6 жыл бұрын
tnx
@neal1236
@neal1236 6 жыл бұрын
‘ ’ means char; " " means string, count is a string ,why you use 'count'? Sorry,my English is bad.
Using the JavaScript MQTT Websockets Client- Part 2
12:18
Steve Cope
Рет қаралды 15 М.
How to create a data table in Node RED Dashboard
20:02
Opto Video
Рет қаралды 66 М.
Elza love to eat chiken🍗⚡ #dog #pets
00:17
ElzaDog
Рет қаралды 22 МЛН
Wait for it 😂
00:19
ILYA BORZOV
Рет қаралды 11 МЛН
Node-Red Variables (Context data)- Part 2
11:28
Steve Cope
Рет қаралды 7 М.
Raspberry Pi IoT Server Tutorial: InfluxDB, MQTT, Grafana, Node-RED & Docker
12:32
Learn Embedded Systems
Рет қаралды 234 М.
How to use MQTT in Node-Red: basics, examples, tip & tricks
29:21
Csongor Varga
Рет қаралды 45 М.
Advanced Node-RED & MySQL tips and techniques
49:26
Opto Video
Рет қаралды 48 М.
05-65 (Node-RED project) Variables (Global, Flow, Node)
22:44
Tech Explorations
Рет қаралды 27 М.
The Node-Red Message Object for Beginners
7:13
Steve Cope
Рет қаралды 48 М.
Storing data into variables | Node-RED Essentials | Tutorial
13:20
Let's Automate
Рет қаралды 8 М.
How to use context storage in Node-RED to save data
13:07
Opto Video
Рет қаралды 28 М.
MQTT in Node RED: Building a Dashboard and Logging Data
20:33
High Voltages
Рет қаралды 42 М.
How to Node-RED!
12:58
bitluni
Рет қаралды 376 М.
Elza love to eat chiken🍗⚡ #dog #pets
00:17
ElzaDog
Рет қаралды 22 МЛН