On 15 February 2017 at 12:52, Jan Van den Audenaerde
<jan.vanden...@gmail.com> wrote:
> Hi Colin,
>
> 1/ State can be anything that you can store in a flow context or global
> context. E.g. you can store the timestamp of the last message received by a
> certain function node in a flow context variable.
> This will make it possible if that new function node receives a new
> message to calculate the time between the received message and the previous
> message.
I don't see how it is necessary to initialise context of that sort.
What are you going to initialise it to? Also why save that in the flow
context rather than the node context?
>
> 2/ A mapping table can be e.g. a javascript variable like ip2name = {
> "192.168.1.2" : "pi_one", "192.168.1.3": "pi_two", "192.168.1.1" :
> "my_wifi_router" };
> This variable can then be used by the different function nodes to
> convert IP addresses to meaningful names.
I would put that in settings.js, I do see your point about keeping
everything in the flow though. On the other hand there is an argument
for saying that it is *better* in settings as it means it is not
necessary to edit the flow in order to change the mapping.
Colin
>
> In this simple example we just wanted to know if a variable is initialized
> or not
> but there are more complex cases where we want to initialize a variable or
> set of variables at specific values.
> E.g. imagine where you are controlling a light switch or the temperature of
> your heating system.
> So when your raspberry pi reboots (e.g. due to temporarily power failure
> when you are on Holiday)
> you would like it to set the light switch and the temperature of your
> heating system properly.
> In those scenarios it would be good if you can explicitly set the state at
> initialization.
In those cases I strongly recommend using MQTT with Retain = true.
Then the mqtt server will automatically feed you the current value
when node-red restarts. This has the additional great advantage that
you can have multiple instances of the UI open at once and they will
all remain in sync via mqtt.
>
>> >
>> > 2/ A mapping table can be e.g. a javascript variable like ip2name = {
>> > "192.168.1.2" : "pi_one", "192.168.1.3": "pi_two", "192.168.1.1" :
>> > "my_wifi_router" };
>> > This variable can then be used by the different function nodes to
>> > convert IP addresses to meaningful names.
>>
>> I would put that in settings.js, I do see your point about keeping
>> everything in the flow though. On the other hand there is an argument
>> for saying that it is *better* in settings as it means it is not
>> necessary to edit the flow in order to change the mapping.
>>
>> Colin
>
>
> In my cases these mapping table are always specific for a certain flow so I
> would like to keep it together with the flow.
> Note also that if I want to migrate the flow to another raspberry pi then I
> can export and import the complete flow without any need to copy parts of
> the settings.js files.
> So having it in the flow - for me is definitely better than having it in the
> settings file.
In fact in the particular case you show it might be better to put them
in the servers hosts file, then you can refer to them by name
everywhere, not just in node-red.
If I were in that situation I would still use MQTT (for the
persistence and other advantages it offers). From the flow that
determines the activation/deactivation send the result to MQTT, then
separately pick it up from MQTT and send it to the pump. Note that
the latter operation need not even be in the same machine as the flow
controlling the logic.
As a matter of interest what device have you go that accepts html
requests to drive it?
Colin
Dean
So that left-most tab turns out to be false? Is that right? I can think of at least two people who are likely to disagree…. Unless the action taken is asynchronous…
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/5f239ae3-ab63-481f-9759-708478fe3391%40googlegroups.com.
Thanks for the confirmation Dave – I guess we could put a marker in there and simply update any info past that – I’ll have a play with that – clearly need to be able to update that from Node-Red… hmmm. That config node works but it only has a one-line input field which is a pain when working with large objects…
From: node...@googlegroups.com [mailto:node...@googlegroups.com] On Behalf Of Dave C-J
Sent: 24 March 2017 09:58
To: node...@googlegroups.com
Subject: Re: [node-red] Re: How to initialize flow and global context before anything else (Don't we need an Init node ?)
Well you could use settings.js to include another file... but as we don't overwrite settings.js anyway that's up to you. On first install/run we copy the default settings.js to your user dir if it doesn't exist. If it exists we don't touch it.
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
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/e_nO4L2W5P8/unsubscribe.
To unsubscribe from this group and all its topics, 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/CACXWFwLV2H9UMV9pzd%3DzsdK1kcYsxCB%2BEFzUMtAGLH-KFMi8XQ%40mail.gmail.com.
you can always write to a file from Node-RED... if that file happens to be the one you reference from settings then so be it.
--
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+unsubscribe@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/CACXWFwJPrvDaw4%2B2n%3Dm-7hFFvTDK%2BtXFBTbBXexXGbAYY1C9ww%40mail.gmail.com.
AHAH that’s what I want but I read some CLEARLY INCORRECT docs somewhere saying you could not import files into a JS file..
Yes, something like /home/pi/mysettings.js with a block of Jason in it will absolutely do it – that can be updated from Node-Red without chancing messing up the settings file… I don’t suppose you can put a try-catch around that include???
From: node...@googlegroups.com [mailto:node...@googlegroups.com] On Behalf Of Nick O'Leary
Sent: 24 March 2017 10:55
To: Node-RED Mailing List <node...@googlegroups.com>
Subject: Re: [node-red] Re: How to initialize flow and global context before anything else (Don't we need an Init node ?)
Personally, I wouldn't go about trying to dynamically modify your settings file. I would stick to the original idea of importing a separate file.
More explicitly, in your settings file you can do:
var mySettings = require("./path/to/my/own/file");
You can then write to that custom file however you choose - as long as it is kept as valid JSON or a valid node.js module file.
Nick
On 24 March 2017 at 10:17, Dave C-J <dce...@gmail.com> wrote:
you can always write to a file from Node-RED... if that file happens to be the one you reference from settings then so be it.
--
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/CACXWFwJPrvDaw4%2B2n%3Dm-7hFFvTDK%2BtXFBTbBXexXGbAYY1C9ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
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/e_nO4L2W5P8/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAF%3DvhqcMvRXJ1EWC5iDidtRSoG%2B1M_eecmr_xU2f_ifGAQ8Qyg%40mail.gmail.com.
Ok, following on from this conversation – I have put this together
http://tech.scargill.net/node-red-initialisation/
So this WORKS – but I’m not happy with the format of the data in my new redvars.js file – I cannot figure out how to just put JSON data in there (which can be created from a stringify command)… and attempts to wrap the “require” with a try-catch have failed purely because of flaws in my JS knowledge.
HOWEVER it works – and solves the problem of initialisation without messing with settings.js other than initial setup – and you can of course now safely mess with vars in the redvars file without screwing up settings.js
If anyone has time to make those two improvements (error checking and putting only a chunk of json in the redvars file) I would be very grateful and other can benefit from it as I get LOTS of people on that blog now (2,600 visitors yesterday alone).
Thanks for any help in advance guys.
Pete.
From: node...@googlegroups.com [mailto:node...@googlegroups.com] On Behalf Of Nick O'Leary
Sent: 24 March 2017 10:55
To: Node-RED Mailing List <node...@googlegroups.com>
Subject: Re: [node-red] Re: How to initialize flow and global context before anything else (Don't we need an Init node ?)
Personally, I wouldn't go about trying to dynamically modify your settings file. I would stick to the original idea of importing a separate file.
More explicitly, in your settings file you can do:
var mySettings = require("./path/to/my/own/file");
You can then write to that custom file however you choose - as long as it is kept as valid JSON or a valid node.js module file.
Nick
On 24 March 2017 at 10:17, Dave C-J <dce...@gmail.com> wrote:
you can always write to a file from Node-RED... if that file happens to be the one you reference from settings then so be it.
--
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/CACXWFwJPrvDaw4%2B2n%3Dm-7hFFvTDK%2BtXFBTbBXexXGbAYY1C9ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
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/e_nO4L2W5P8/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAF%3DvhqcMvRXJ1EWC5iDidtRSoG%2B1M_eecmr_xU2f_ifGAQ8Qyg%40mail.gmail.com.
Ok, following on from this conversation – I have put this together
http://tech.scargill.net/node-red-initialisation/
So this WORKS – but I’m not happy with the format of the data in my new redvars.js file – I cannot figure out how to just put JSON data in there (which can be created from a stringify command)… and attempts to wrap the “require” with a try-catch have failed purely because of flaws in my JS knowledge.
HOWEVER it works – and solves the problem of initialisation without messing with settings.js other than initial setup – and you can of course now safely mess with vars in the redvars file without screwing up settings.js
If anyone has time to make those two improvements (error checking and putting only a chunk of json in the redvars file) I would be very grateful and other can benefit from it as I get LOTS of people on that blog now (2,600 visitors yesterday alone).
Thanks for any help in advance guys.
Pete.
From: node...@googlegroups.com [mailto:node-red@googlegroups.com] On Behalf Of Nick O'Leary
Sent: 24 March 2017 10:55
To: Node-RED Mailing List <node...@googlegroups.com>
Subject: Re: [node-red] Re: How to initialize flow and global context before anything else (Don't we need an Init node ?)
Personally, I wouldn't go about trying to dynamically modify your settings file. I would stick to the original idea of importing a separate file.
More explicitly, in your settings file you can do:
var mySettings = require("./path/to/my/own/file");
You can then write to that custom file however you choose - as long as it is kept as valid JSON or a valid node.js module file.
Nick
On 24 March 2017 at 10:17, Dave C-J <dce...@gmail.com> wrote:
you can always write to a file from Node-RED... if that file happens to be the one you reference from settings then so be it.
--
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+unsubscribe@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/CACXWFwJPrvDaw4%2B2n%3Dm-7hFFvTDK%2BtXFBTbBXexXGbAYY1C9ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
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/e_nO4L2W5P8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@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/CAF%3DvhqcMvRXJ1EWC5iDidtRSoG%2B1M_eecmr_xU2f_ifGAQ8Qyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@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/027b01d2a4a5%249965cb30%24cc316190%24%40gmail.com.
Hi Nick
Tested, works - updating the blog now – in half an hour it should be done – and that, for now I think goes a GOOD way to solving this particular issue.
Thanks to you and Dave once again. Marvelous – no more undefined vars for me….
Pete.
From: node...@googlegroups.com [mailto:node...@googlegroups.com] On Behalf Of Nick O'Leary
Sent: 24 March 2017 14:03
To: Node-RED Mailing List <node...@googlegroups.com>
Subject: Re: [node-red] Re: How to initialize flow and global context before anything else (Don't we need an Init node ?)
Hi Peter,
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/CACXWFwJPrvDaw4%2B2n%3Dm-7hFFvTDK%2BtXFBTbBXexXGbAYY1C9ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
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/e_nO4L2W5P8/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAF%3DvhqcMvRXJ1EWC5iDidtRSoG%2B1M_eecmr_xU2f_ifGAQ8Qyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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/027b01d2a4a5%249965cb30%24cc316190%24%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
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/e_nO4L2W5P8/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAF%3Dvhqed-mk-AhwhzwGCH59rW%2BjniKyDfTzhmc1gvqgOGYFLTA%40mail.gmail.com.
s.. Here’s a better way. At the VERY START of setting.js add this..
var mySettings;
try {
mySettings = require("/home/pi/redvars.js");
} catch(err) {
mySetting = {};
}