Andrew, maybe this will help you understand W
hat is going on: A guide to understanding 'Persistent Context'
Thanks Paul.
(Is it me or what?)
My config file - extract:
functionGlobalContext: {
// os:require('os'),
// octalbonescript:require('octalbonescript'),
// jfive:require("johnny-five"),
// j5board:require("johnny-five").Board({repl:false})
},
That is the closest I can get to what is in the link:
contextStorage: {
storeName : { module: "storeModule" }
},
Please explain why I am not seeing what I should/want to see.
What are you trying to accomplish ?
This part:
contextStorage: {
storeName : { module: "storeModule" }
},
Only explains how it is used, read the post further.
storeModule
: Node-RED provides two built-in store modules:memory
andlocalfilesystem
. It is also possible to create custom store plugins. You must specify localfilesystem (or your own custom module) to make the data persistent. For details on creating custom modules, see the api pages.
I'm not trying to accomplish anything.
I just read the help for the template
node and I couldn't understand what was written down and what it means.
The names used in the example posted and what I see in my config file aren't the same.
Or I can't see them as the same. If the latter is true, I have another problem which as yet I haven't identified.
This may be my biggest sticking point.
Can someone re-word this using the store
option but not using the word STORE as that seems to be confusing me.
It is a store, some space that contains things, or by definition:
something that is stored or kept for future use
In a very small way I get what you are saying, but 90% of me isn't.
The kink is the word STORE. I get that it can be a place where things are stored. Noun.
But the parsing system is stuck on the verb meaning.
So it isn't working for me when I try to read and understand it.
It seems it is a problem I need to fix. I need to work on it from my end.
I'll stop wasting your time.
You are missing the point:
It is a noun.
If you want food, you go to the food-store, because it is kept there.
As Dave tried to explain - you may need to add this to your settings.js if your node-red was initially installed before version 0.19.0
this is the format of the contextStore option
contextStorage: {
storeName : { module: "storeModule" }
},
you can use what ever name you want for storeName
, you could call it 'andrew'. Than would mean that if you wanted to use it in a function node you would use flow.get("foo", "andrew")
.
if you use default
for the storeName
in settings.js
you don't need to provide it in the statements.
But, and I really want to stress this point, you only need to do this if you want to enable the Persistable Context option.
You don't need to do that.
If your flow is working Iād not break it.
@dceejay, @knolleary, @zenofmud, @bakman2 and others.
Ok, I had a night's sleep on the problem and this is what I now have resolved:
flow[store].name
That is where I fall over in a heap understanding.
It wasn't until post #15 that it was mentioned that this/these lines were not put in the config because I was upgrading from a previous version.
Post #18 it was said that things are STORED, but to be more precise:
I think THIS is the most up to date thinking which still has me confused.
The word store can be a noun or a verb.
You go into a store to buy things and when you find that for which you are searching you buy it and leave the store.
So drilling down to the next level:
I go into a store to buy some food.
When I leave the store I don't have store. I have food.
So when the line:
flow[store].name
is used the names use are so wrong it is blowing my mind.
flow[food].name
maybe.
But then there are still two questions:
What part is the .name
and why the [ ]
around the name?
The [ ]
imply to me from past use that it is an array.
eg: somthing[0], something [1], something[2]
and so on.
So although I am wrong in my thinking, anyone else who thinks like me is in for a real hard time trying to parse how to structure that line. What is what.
I am not trying to be difficult. I am merely saying what I am seeing and how confused I am because of it.
Anyway, I'll try to move on from it as I really don't have any persistent variables. Though: "sure as eggs" I will soon need them.
I go into a store to buy some food .
So read it like: You go to the store to get a variable, which store ? the store you specify and was defined in settings.js (as was pointed out earlier: this part of the configuration does not exist when upgrading)
Example stores:
contextStorage: {
default : { module: "memory" },
storeInFile: { module: "localfilesystem"},
memoryOnly : { module: "memory" }
},
I don't understand the focus on this "store" thing, because you can use persistent variables and still don't have to deal with the "store"
To expand on this, relating it back to the original question about the Template node, if you had context configured as described in @bakman2's reply, you could then use:
{{flow[storeInFile].foo}}
To retrieve the flow context variable foo
that had been saved in the storeInFile
store.
You ask why is it that syntax... We'll, because that's the syntax we have.
If you don't have any contextStorage configured, then your context values will be stored in the default memory-only store. And in that case, you don't have to tell NR which store to use because there is only one.
Again: I must agree with what you say.
But for a noob like me it is confusing.
{{flow[storeInFile].foo}}
Would maybe have gone a long way to reduce the confusion for me. I honestly can't say.
But again - and remember: I am not trying to be difficult - with the syntax history I have seen I would have made it more like:
{{flow.storeInFile[foo]}}
Maybe:
{{flow.storeInFileName[foo]}}
That way it is shown you have the filename which is used (set if the settings.js file) and what it is (as a sort of array) you want to get.
Sorry I have seemed to be so stubborn about it. It was just so confusing because I wasn't brought up on that kind of syntax and how I saw it: it was confusing.
Thanks to all who helped. Really.
I'm not going to say I will suddenly get it. But I have been shown what it means I will have to remember this quirk in what to do. Because as I have said, it is most likely not going to be long before I am using persistent variables who survive a reboot.
And then you still don't have to deal with it, consider yourself lucky
Yeah, but when I get to that bridge I want to be as knowledgeable as possible before then.
Because: though not that difficult, I am sure you can appreciate from this whole debarcle (spelling?) it is not going to be smooth for me.