MQTT input node variable topic

171 views
Skip to first unread message

esc...@missionroom.nl

unread,
Nov 23, 2017, 3:50:19 PM11/23/17
to Node-RED
I love to use mqtt on my pi
At the moment i am trying to create a standard pi setup.
Output topic is set in this setup to the hostname, all is done without editing in node red
Only part that i cannot get automated is the input of mqtt
Is there a way to set the topic of the input node in another way than it the node itself?

Colin Law

unread,
Nov 23, 2017, 4:07:41 PM11/23/17
to node...@googlegroups.com
You could make the mqtt in node subscribe to the complete range of
topics that might be of interest, then filter out the ones you don't
want in subsequent nodes.

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/5e324394-69cd-4111-9c2e-2c17daad620c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Nick O'Leary

unread,
Nov 23, 2017, 4:11:38 PM11/23/17
to Node-RED Mailing List
A not-widely known feature of node-red is that you can use environment variables to set node properties.

If you configure the MQTT In node's topic to:
   $(MY_TOPIC)

Then it will use the value of the MY_TOPIC environment variable for that node property.

This is useful when you want to deploy an identical set of flows to multiple devices, but customise each instance.

Nick


On 23 November 2017 at 21:07, Colin Law <cla...@gmail.com> wrote:
You could make the mqtt in node subscribe to the complete range of
topics that might be of interest, then filter out the ones you don't
want in subsequent nodes.

Colin

On 23 November 2017 at 20:50,  <esc...@missionroom.nl> wrote:
> I love to use mqtt on my pi
> At the moment i am trying to create a standard pi setup.
> Output topic is set in this setup to the hostname, all is done without
> editing in node red
> Only part that i cannot get automated is the input of mqtt
> Is there a way to set the topic of the input node in another way than it the
> node itself?
>
> --
> 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

> 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/5e324394-69cd-4111-9c2e-2c17daad620c%40googlegroups.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 an email to node...@googlegroups.com.

Colin Law

unread,
Nov 23, 2017, 4:13:57 PM11/23/17
to node...@googlegroups.com
Nick, does that work for all nodes? I had assumed that the node had to
be written to allow it.

Colin
>> > 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/5e324394-69cd-4111-9c2e-2c17daad620c%40googlegroups.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 an 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/CAL%3D0gLtEX7jBoUyw3q-Q-oXQSRgtUvJKYCwwzoqPo%2B7C-shgeA%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/CAF%3DvhqdC9uJfX8JEVD4S_mO7%3DXqdx11b-xj-3iu_6zTLUtikfA%40mail.gmail.com.

Nick O'Leary

unread,
Nov 23, 2017, 4:15:27 PM11/23/17
to Node-RED Mailing List
Its a feature of the runtime that automatically applies to all nodes - it looks for and substitutes env vars before each node is given its config.

Nick


>> > 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/5e324394-69cd-4111-9c2e-2c17daad620c%40googlegroups.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

>> To post to this group, send an 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/CAL%3D0gLtEX7jBoUyw3q-Q-oXQSRgtUvJKYCwwzoqPo%2B7C-shgeA%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

> 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
>
> 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 an email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Colin Law

unread,
Nov 23, 2017, 4:18:02 PM11/23/17
to node...@googlegroups.com
On 23 November 2017 at 21:15, Nick O'Leary <nick....@gmail.com> wrote:
> Its a feature of the runtime that automatically applies to all nodes - it
> looks for and substitutes env vars before each node is given its config.

Excellent, thanks.

Colin
>> >> > 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/5e324394-69cd-4111-9c2e-2c17daad620c%40googlegroups.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 an 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/CAL%3D0gLtEX7jBoUyw3q-Q-oXQSRgtUvJKYCwwzoqPo%2B7C-shgeA%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/CAF%3DvhqdC9uJfX8JEVD4S_mO7%3DXqdx11b-xj-3iu_6zTLUtikfA%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 an 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/CAL%3D0gLv-kdPCiRP%3DAkP_Yask3zaF2vMtqoTge_r3P0G9vxn1fQ%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/CAF%3DvhqdTKTKf1LpXiTrL%3DC%3Dj-zpPyC26X0_Yr0gvvSD1Rn9jwA%40mail.gmail.com.

esc...@missionroom.nl

unread,
Nov 23, 2017, 4:21:21 PM11/23/17
to Node-RED
Thanks Nick!

Thats sounds nice for other solutions that i have made for naming outputs.
Where can i find more info about environment variables?
When i google it i cannot find a clear answer how to use it


Op donderdag 23 november 2017 22:11:38 UTC+1 schreef Nick O'Leary:

> 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/5e324394-69cd-4111-9c2e-2c17daad620c%40googlegroups.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.

Nick O'Leary

unread,
Nov 23, 2017, 4:26:06 PM11/23/17
to Node-RED Mailing List
Environment variables are a standard feature of every operating system, so yes, a google search will find you a few billion results...

As you're on the Pi, assuming you're running node-red using our service scripts, then this may be of use:


At a quick glance, this may be a helpful overview:


Note, neither of those are full endorsements... just what a quick google and scan over suggest may help you.

Nick

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.

esc...@missionroom.nl

unread,
Nov 23, 2017, 5:10:11 PM11/23/17
to Node-RED
Did a small test

echo $HOSTNAME gives me "dns"

timestamp > mqtt with topic "dns"

mqtt with topic $(HOSTNAME) > debug node

This give me no output
Whats wrong??

Nick O'Leary

unread,
Nov 23, 2017, 5:11:56 PM11/23/17
to Node-RED Mailing List
You picked a bad example... HOSTNAME isn't set within the node env for reasons I looked up once but can't remember at this time of night.

Nick



--
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.

esc...@missionroom.nl

unread,
Nov 23, 2017, 5:29:37 PM11/23/17
to Node-RED
ok thansk,

tested now with FOO=BAR in /etc/profile

echo $FOO gives BAR

But no result when i enter BAR in the input mqtt and $(FOO) in the receive

When i set both input output mqtt with $(FOO) it gives in the debug node " $(FOO)"  for the topic field


Nick O'Leary

unread,
Nov 23, 2017, 5:39:02 PM11/23/17
to Node-RED Mailing List
As I mentioned, I only did a quick scan of the links I gave you. Reading the first one in more detail I see the original questioner has replied to the proposed answer saying 'it didn't work'... so some more googling is needed.


Nick



--
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.

Rogier Visser ( mission room )

unread,
Nov 23, 2017, 5:46:33 PM11/23/17
to node...@googlegroups.com
Ok i just thought that my way of notation of the value in node red was wrong because echo returned a value


I go on with google. Thanks!

esc...@missionroom.nl

unread,
Nov 24, 2017, 3:07:36 AM11/24/17
to Node-RED
But this notation is correct for using in node-red?

msg.payload = $(LOGNAME);
return msg;

Because this return that $ is not defined.




Op donderdag 23 november 2017 23:46:33 UTC+1 schreef Rogier Visser ( mission room ):

Nick O'Leary

unread,
Nov 24, 2017, 4:34:22 AM11/24/17
to Node-RED Mailing List
No.

This only applies when you set an entire node property to $(xyz):



You cannot include $(LOGNAME) as part of the property value... it must be the entire thing.

When you view the node's properties in the Info sidebar tab, it should look like this:



This does mean, however, that you cannot use the $() notation inside the Change or Switch nodes - as the 'rules' you set in them get wrapped up as an Object. This is something we'll fix in the future.





--
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.

Rogier Visser

unread,
Nov 24, 2017, 4:50:31 AM11/24/17
to node...@googlegroups.com
Thanks, $(LOGNAME) works!!

But my FOO BAR test not.

So it seems that /etc/profile is not the correct place to place this.

To be continued…. 

esc...@missionroom.nl

unread,
Nov 25, 2017, 8:19:14 AM11/25/17
to Node-RED
I cannot get it working to get the hostname or the foo-bar test
Is there maybe another way to make the mqtt node to listen to the hostname of my pi?

Colin Law

unread,
Nov 25, 2017, 8:27:58 AM11/25/17
to node...@googlegroups.com
If you just want it to use the mqtt sever on the local machine use
localhost as the mqtt server

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/b61917c6-2949-44e8-ae7a-715639dbe6dc%40googlegroups.com.

Nick O'Leary

unread,
Nov 25, 2017, 8:32:31 AM11/25/17
to Node-RED Mailing List
Based on your previous questions in this thread you mean you want it to subscribe to a topic that matches the hostname? (Rather than Colin suggests, simply connect to the broker running on localhost)

We've already established that /etc/profile doesn't work. I then linked you to another possible approach to apply env vars to the systemd profile. Searching around systemd and environment variables finds lots of suggested ways to do it.

What exactly have you tried? Exactly what edits to what files have you tried?

I'm not near a Pi today, but I can try to take a look tonight to get it working.

Nick


On 25 November 2017 at 13:27, Colin Law <cla...@gmail.com> wrote:
If you just want it to use the mqtt sever on the local machine use
localhost as the mqtt server

Colin

On 25 November 2017 at 13:19,  <esc...@missionroom.nl> wrote:
> I cannot get it working to get the hostname or the foo-bar test
> Is there maybe another way to make the mqtt node to listen to the hostname
> of my pi?
>
> --
> 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

> 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/b61917c6-2949-44e8-ae7a-715639dbe6dc%40googlegroups.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 an email to node...@googlegroups.com.

esc...@missionroom.nl

unread,
Nov 25, 2017, 9:20:05 AM11/25/17
to Node-RED
Exactly Nick, thats what i am trying to do.

The env vars systemd i tried but i don't understand exactly how that should be done.
It is a little above my programming level...

Nick O'Leary

unread,
Nov 25, 2017, 9:58:08 AM11/25/17
to node...@googlegroups.com

> The env vars systemd i tried 

But what exactly did you do when you tried this? What steps did you take?

I understand you feel this is beyond your level, but we'll figure it out.

Nick


--
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.

Rogier Visser

unread,
Nov 25, 2017, 10:47:26 AM11/25/17
to node...@googlegroups.com
I placed foo=bar in the systemd and rebooted
But no result
And did a lot of google searches.
Gives me a lot node.js results but that above to me

Dave C-J

unread,
Nov 25, 2017, 10:55:42 AM11/25/17
to node...@googlegroups.com
sorry to barge in...
and add a line at the end
    export NAME=$(hostname)
then restart the Pi - (or logout and back in) you can then  type
  echo $NAME
and should see the hostname
you can then use   $(NAME)  in Node-RED fields as suggested...

However also note that it must start $( and end ) - you can't add extra pieces to that so for example
  $(NAME)/sub-topic  will not work...
If you need that sort of thing you need to change the export instead.

Colin Law

unread,
Nov 25, 2017, 10:56:10 AM11/25/17
to node...@googlegroups.com
Copy/past your systemd service here. How else are we to check that
you did it correctly?

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/etPan.5a199080.371d42fa.a5d1%40qusax.eu.

Dave C-J

unread,
Nov 25, 2017, 10:57:04 AM11/25/17
to node...@googlegroups.com
no need to mess with the systemd file....
as we will only overwrite it on an upgrade anyway....
so better to edit something we don't touch

esc...@missionroom.nl

unread,
Nov 25, 2017, 11:12:12 AM11/25/17
to Node-RED
echo $NAME works, that also works with FOO
But it doenst work when using it in node-red



Op zaterdag 25 november 2017 16:55:42 UTC+1 schreef Dave C-J:

Colin Law

unread,
Nov 25, 2017, 11:16:43 AM11/25/17
to node...@googlegroups.com
Again, show us *exactly* what you have done. When you say 'it doesn't
work' what you mean is 'what I have done doesn't work'. In order to
see what you have done you need to show us. We are not telepathic.

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/bad5877b-249b-4ad4-a9bf-5c590d9ad3cd%40googlegroups.com.

esc...@missionroom.nl

unread,
Nov 25, 2017, 11:48:14 AM11/25/17
to Node-RED
what i am doing is this: 
[{"id":"10738b8f.73c5c4","type":"inject","z":"fbc4dc2e.b4fe48","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":172,"y":176,"wires":[["5793c44d.6b93e4"]]},{"id":"69dc05de.ff121c","type":"debug","z":"fbc4dc2e.b4fe48","name":"","active":true,"console":"false","complete":"true","x":492,"y":177,"wires":[]},{"id":"122fa2fa.db3e8d","type":"mqtt in","z":"fbc4dc2e.b4fe48","name":"","topic":"$(NAME)","qos":"2","broker":"ed2e7523.8afa38","x":326,"y":85,"wires":[["69dc05de.ff121c"]]},{"id":"5793c44d.6b93e4","type":"mqtt out","z":"fbc4dc2e.b4fe48","name":"","topic":"dns","qos":"","retain":"","broker":"ed2e7523.8afa38","x":314,"y":132,"wires":[]},{"id":"7c4ed80d.d3447","type":"inject","z":"fbc4dc2e.b4fe48","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":180,"y":389,"wires":[["5c9e533d.dc3cdc"]]},{"id":"2d3fab7f.4850bc","type":"debug","z":"fbc4dc2e.b4fe48","name":"","active":true,"console":"false","complete":"true","x":500,"y":390,"wires":[]},{"id":"c8f93f57.b526e8","type":"mqtt in","z":"fbc4dc2e.b4fe48","name":"","topic":"$(LOGNAME)","qos":"2","broker":"ed2e7523.8afa38","x":344,"y":298,"wires":[["2d3fab7f.4850bc"]]},{"id":"5c9e533d.dc3cdc","type":"mqtt out","z":"fbc4dc2e.b4fe48","name":"","topic":"pi","qos":"","retain":"","broker":"ed2e7523.8afa38","x":322,"y":345,"wires":[]},{"id":"5ceeacf8.08b16c","type":"comment","z":"fbc4dc2e.b4fe48","name":"Non working","info":"dns is the hostname of the pi\n\necho $NAME returns dns in terminal","x":329,"y":44,"wires":[]},{"id":"d917b99.8391548","type":"comment","z":"fbc4dc2e.b4fe48","name":"Working","info":"","x":325,"y":258,"wires":[]},{"id":"ed2e7523.8afa38","type":"mqtt-broker","z":"","broker":"mqtt.local","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":""}]


Nick O'Leary

unread,
Nov 25, 2017, 11:49:40 AM11/25/17
to node...@googlegroups.com

And what have you got in /etc/profile?


On Sat, 25 Nov 2017, 16:48 , <esc...@missionroom.nl> wrote:
what i am doing is this: 
[{"id":"10738b8f.73c5c4","type":"inject","z":"fbc4dc2e.b4fe48","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":172,"y":176,"wires":[["5793c44d.6b93e4"]]},{"id":"69dc05de.ff121c","type":"debug","z":"fbc4dc2e.b4fe48","name":"","active":true,"console":"false","complete":"true","x":492,"y":177,"wires":[]},{"id":"122fa2fa.db3e8d","type":"mqtt in","z":"fbc4dc2e.b4fe48","name":"","topic":"$(NAME)","qos":"2","broker":"ed2e7523.8afa38","x":326,"y":85,"wires":[["69dc05de.ff121c"]]},{"id":"5793c44d.6b93e4","type":"mqtt out","z":"fbc4dc2e.b4fe48","name":"","topic":"dns","qos":"","retain":"","broker":"ed2e7523.8afa38","x":314,"y":132,"wires":[]},{"id":"7c4ed80d.d3447","type":"inject","z":"fbc4dc2e.b4fe48","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":180,"y":389,"wires":[["5c9e533d.dc3cdc"]]},{"id":"2d3fab7f.4850bc","type":"debug","z":"fbc4dc2e.b4fe48","name":"","active":true,"console":"false","complete":"true","x":500,"y":390,"wires":[]},{"id":"c8f93f57.b526e8","type":"mqtt in","z":"fbc4dc2e.b4fe48","name":"","topic":"$(LOGNAME)","qos":"2","broker":"ed2e7523.8afa38","x":344,"y":298,"wires":[["2d3fab7f.4850bc"]]},{"id":"5c9e533d.dc3cdc","type":"mqtt out","z":"fbc4dc2e.b4fe48","name":"","topic":"pi","qos":"","retain":"","broker":"ed2e7523.8afa38","x":322,"y":345,"wires":[]},{"id":"5ceeacf8.08b16c","type":"comment","z":"fbc4dc2e.b4fe48","name":"Non working","info":"dns is the hostname of the pi\n\necho $NAME returns dns in terminal","x":329,"y":44,"wires":[]},{"id":"d917b99.8391548","type":"comment","z":"fbc4dc2e.b4fe48","name":"Working","info":"","x":325,"y":258,"wires":[]},{"id":"ed2e7523.8afa38","type":"mqtt-broker","z":"","broker":"mqtt.local","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":""}]


--
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.

esc...@missionroom.nl

unread,
Nov 25, 2017, 11:54:56 AM11/25/17
to Node-RED
sorry forget that...

export NAME=$HOSTNAME

export FOO=BAR


is what i have added 



Op zaterdag 25 november 2017 17:49:40 UTC+1 schreef Nick O'Leary:

And what have you got in /etc/profile?


On Sat, 25 Nov 2017, 16:48 , <esc...@missionroom.nl> wrote:
what i am doing is this: 
[{"id":"10738b8f.73c5c4","type":"inject","z":"fbc4dc2e.b4fe48","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":172,"y":176,"wires":[["5793c44d.6b93e4"]]},{"id":"69dc05de.ff121c","type":"debug","z":"fbc4dc2e.b4fe48","name":"","active":true,"console":"false","complete":"true","x":492,"y":177,"wires":[]},{"id":"122fa2fa.db3e8d","type":"mqtt in","z":"fbc4dc2e.b4fe48","name":"","topic":"$(NAME)","qos":"2","broker":"ed2e7523.8afa38","x":326,"y":85,"wires":[["69dc05de.ff121c"]]},{"id":"5793c44d.6b93e4","type":"mqtt out","z":"fbc4dc2e.b4fe48","name":"","topic":"dns","qos":"","retain":"","broker":"ed2e7523.8afa38","x":314,"y":132,"wires":[]},{"id":"7c4ed80d.d3447","type":"inject","z":"fbc4dc2e.b4fe48","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":180,"y":389,"wires":[["5c9e533d.dc3cdc"]]},{"id":"2d3fab7f.4850bc","type":"debug","z":"fbc4dc2e.b4fe48","name":"","active":true,"console":"false","complete":"true","x":500,"y":390,"wires":[]},{"id":"c8f93f57.b526e8","type":"mqtt in","z":"fbc4dc2e.b4fe48","name":"","topic":"$(LOGNAME)","qos":"2","broker":"ed2e7523.8afa38","x":344,"y":298,"wires":[["2d3fab7f.4850bc"]]},{"id":"5c9e533d.dc3cdc","type":"mqtt out","z":"fbc4dc2e.b4fe48","name":"","topic":"pi","qos":"","retain":"","broker":"ed2e7523.8afa38","x":322,"y":345,"wires":[]},{"id":"5ceeacf8.08b16c","type":"comment","z":"fbc4dc2e.b4fe48","name":"Non working","info":"dns is the hostname of the pi\n\necho $NAME returns dns in terminal","x":329,"y":44,"wires":[]},{"id":"d917b99.8391548","type":"comment","z":"fbc4dc2e.b4fe48","name":"Working","info":"","x":325,"y":258,"wires":[]},{"id":"ed2e7523.8afa38","type":"mqtt-broker","z":"","broker":"mqtt.local","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":<span style="color:#080" class="m_-9104060393041007338styled-by-pret

Colin Law

unread,
Nov 25, 2017, 12:18:19 PM11/25/17
to node...@googlegroups.com
What does
echo $NAME
show?
Copy/paste the terminal o/p from the command please.
What happens when you run the flow?

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/7d56ed0f-729a-4edf-aa3d-2e6510307d5a%40googlegroups.com.

esc...@missionroom.nl

unread,
Nov 25, 2017, 12:25:20 PM11/25/17
to Node-RED

pi@dns:~ $ echo $NAME

dns

pi@dns:~ $ echo $FOO

BAR

pi@dns:~ $ 


when is run the flow the working example returns:
{"topic":"pi","payload":"1511630630029","qos":0,"retain":false,"_msgid":"b4cc1329.7a44f"}

The non working example returns nothing, no error, no result, just nothing

Op zaterdag 25 november 2017 18:18:19 UTC+1 schreef Colin Law:

Colin Law

unread,
Nov 25, 2017, 12:40:46 PM11/25/17
to node...@googlegroups.com
On 25 November 2017 at 17:25, <esc...@missionroom.nl> wrote:
> pi@dns:~ $ echo $NAME
>
> dns
>
> pi@dns:~ $ echo $FOO
>
> BAR
>
> pi@dns:~ $
>
>
> when is run the flow the working example returns:
> {"topic":"pi","payload":"1511630630029","qos":0,"retain":false,"_msgid":"b4cc1329.7a44f"}
>
> The non working example returns nothing, no error, no result, just nothing

The flow you posted shows for the working node the topic $(LOGNAME)
but you haven't shown us what echo $LOGNAME
shows. Instead you have shown us $FOO, are you sure you have not got
confused about names somewhere?

Are you setting the environment vars up in /etc/profile? They must be
set before node-red is started.

Colin
> https://groups.google.com/d/msgid/node-red/f92500bf-207e-4126-ad26-d4c395f757fc%40googlegroups.com.

esc...@missionroom.nl

unread,
Nov 25, 2017, 1:20:13 PM11/25/17
to Node-RED
Sorry, i added logname to show what is working and what not.
When i echo logname i get this

pi@dns:~ $ echo $LOGNAME

pi

pi@dns:~ $ 




The environment vars up in /etc/profile
are set and after that i rebooted the pi

I dont have any names confused 
In the example that FOO echos BAR, but is not working with the mqtt topic when i add these to test it


Op zaterdag 25 november 2017 18:40:46 UTC+1 schreef Colin Law:

Colin Law

unread,
Nov 25, 2017, 4:32:10 PM11/25/17
to node...@googlegroups.com
You mean it works if the topic is specified in an environment variable
LOGNAME but not when it is in an environment variable called NAME?
That seems very odd to me.

To see what the node is actually subscribing to, if on the mqtt server
machine, you add to the end of /etc/mosquitto/mosquitto.conf the line
log_type all
then restart mosquitto:
sudo systemctl restart mosquitto
and watch the log file (/var/log/mosquitto/mosquitto.log) then you
will see everything that happens, including subscribe and publish
requests. In particular you will see lines like
Received SUBSCRIBE from mqtt_7a48dae8.4f57e4
dns (QoS 2)
and when you click your inject you will see the publish message.
the subscribe will happen each time you restart node-red.

Colin
> https://groups.google.com/d/msgid/node-red/d9a86644-c2dc-4f75-9bd8-b62112972d81%40googlegroups.com.

esc...@missionroom.nl

unread,
Nov 25, 2017, 4:46:43 PM11/25/17
to Node-RED
LOGNAME is a variable that is set by the pi 
NAME is set by myself.

isnt that the problem?

The test with mqtt i need to check tomorrow 

Op zaterdag 25 november 2017 22:32:10 UTC+1 schreef Colin Law:

Colin Law

unread,
Nov 25, 2017, 5:26:07 PM11/25/17
to node...@googlegroups.com
Ah, I see what you mean. Maybe your variable is not set in the
environment used when node-red is started. Try running node red in the
terminal by stopping it with systemctl then running node-red in the
.node-red folder in the terminal after checking that NAME is setup.

Colin
> https://groups.google.com/d/msgid/node-red/27cbb3df-1ccc-44dc-b740-c99525968a74%40googlegroups.com.

esc...@missionroom.nl

unread,
Nov 25, 2017, 5:45:50 PM11/25/17
to Node-RED
Sorry but i really don't understand how or what to do now exactly, sorry...

Op zaterdag 25 november 2017 23:26:07 UTC+1 schreef Colin Law:

Zenofmud

unread,
Nov 25, 2017, 6:15:57 PM11/25/17
to node...@googlegroups.com
I just tried playing with this and I also see this problem. $(HOSTNAME) does not work. Here is the echo of $LOGNAME and $HOSTNAME. MQTT is installed on another pi on the same network.

pi@opencv:~ $ echo $LOGNAME
pi
pi@opencv:~ $ echo $HOSTNAME
opencv

Here is an image of the test flows (the export of the flows is at the bottom):


The name of the MQTT nodes are the topic names. The bottom MQTT_IN node subs to all topics.

Case 1: Pressing the ‘test pi’ inject node I get three (3) debug messages:
11/25/2017, 6:08:56 PMnode: debug test $(LOGNAME)pi : msg : Object
object
topic"pi"
payload"test pi"
qos0
retainfalse
_msgid"2c262c34.896f04"
11/25/2017, 6:08:56 PMnode: debug everythingpi : msg : Object
object
topic"pi"
payload"test pi"
qos0
retainfalse
_msgid"b05c30db.09e01"
11/25/2017, 6:08:56 PMnode: debug test pipi : msg : Object
object
topic"pi"
payload"test pi"
qos0
retainfalse
_msgid"36db7753.22fec8"
So using the topic ‘pi’ it is seen by the MQTT-IN nodes using the topic  ‘pi’, ‘$(LOGNAME)’ and ‘#’

CASE 2: Pressing the ‘test $(LOGNAME)’ inject node I get three (3) debug messages:
11/25/2017, 6:10:11 PMnode: debug test $(LOGNAME)pi : msg : Object
object
topic"pi"
payload"test $(LOGNAME)"
qos0
retainfalse
_msgid"a5e34f08.6fad1"
11/25/2017, 6:10:11 PMnode: debug everythingpi : msg : Object
object
topic"pi"
payload"test $(LOGNAME)"
qos0
retainfalse
_msgid"f25aafdf.03619"
11/25/2017, 6:10:11 PMnode: debug test pipi : msg : Object
object
topic"pi"
payload"test $(LOGNAME)"
qos0
retainfalse
_msgid"c243a377.a2308"
So using the topic ‘$(LOGNAME)’ it is seen by the MQTT-IN nodes using the topic ‘pi’, ‘$(LOGNAME)’ and ‘#’

CASE 3: Pressing the ‘test opencv’ inject node I get two (2) debug messages:
11/25/2017, 6:10:41 PMnode: debug everythingopencv : msg : Object
object
topic"opencv"
payload"test opencv"
qos0
retainfalse
_msgid"69ca5441.b4572c"
11/25/2017, 6:10:41 PMnode: debug test opencvopencv : msg : Object
object
topic"opencv"
payload"test opencv"
qos0
retainfalse
_msgid"d6957eee.a63c4"
So using the topic ‘opencv’ it is seen by the MQTT-IN nodes using the topic ‘opencv’  and ‘#’
NOTE: the topic is ‘opencv'

Pressing the ‘test $(HOSTNAME)’ inject node I get two (2) debug messages:
11/25/2017, 6:11:41 PMnode: debug test $(HOSTNAME)$(HOSTNAME) : msg : Object
object
topic"$(HOSTNAME)"
payload"test $(HOSTNAME)"
qos0
retainfalse
_msgid"527ede97.04baa"
11/25/2017, 6:11:41 PMnode: debug everything$(HOSTNAME) : msg : Object
object
topic"$(HOSTNAME)"
payload"test $(HOSTNAME)"
qos0
retainfalse
_msgid"5cf09ffd.e4a14"
So using the topic ‘$(HOSTNAME)’ it is seen by the MQTT-IN nodes using the topic ‘$(HOSTNAME)’  and ‘#’
NOTE: the topic is now $(HOSTNAME)

For some reason, not all environmental variables are being processed correctly.

Test flow:
[{"id":"b790860a.ede18","type":"inject","z":"db434db0.ef47a8","name":"","topic":"","payload":"test opencv","payloadType":"str","repeat":"","crontab":"","once":false,"x":130,"y":260,"wires":[["d4e91a67.6be408"]]},{"id":"4bea8966.8b5048","type":"debug","z":"db434db0.ef47a8","name":"debug test  $(HOSTNAME)","active":true,"console":"false","complete":"true","x":820,"y":320,"wires":[]},{"id":"4f03edb6.8ece0c","type":"mqtt in","z":"db434db0.ef47a8","name":"","topic":"$(HOSTNAME)","qos":"2","broker":"30cce66c.5a7b6a","x":560,"y":320,"wires":[["4bea8966.8b5048"]]},{"id":"d4e91a67.6be408","type":"mqtt out","z":"db434db0.ef47a8","name":"","topic":"opencv","qos":"","retain":"","broker":"30cce66c.5a7b6a","x":360,"y":260,"wires":[]},{"id":"64aef2d0.a9a07c","type":"inject","z":"db434db0.ef47a8","name":"","topic":"","payload":"test $(LOGNAME)","payloadType":"str","repeat":"","crontab":"","once":false,"x":150,"y":140,"wires":[["9762c7ed.909758"]]},{"id":"afcac2ac.15e79","type":"debug","z":"db434db0.ef47a8","name":"debug test $(LOGNAME)","active":true,"console":"false","complete":"true","x":810,"y":140,"wires":[]},{"id":"ae20348b.8238f","type":"mqtt in","z":"db434db0.ef47a8","name":"","topic":"$(LOGNAME)","qos":"2","broker":"30cce66c.5a7b6a","x":550,"y":140,"wires":[["afcac2ac.15e79"]]},{"id":"9762c7ed.909758","type":"mqtt out","z":"db434db0.ef47a8","name":"","topic":"$(LOGNAME)","qos":"","retain":"","broker":"30cce66c.5a7b6a","x":340,"y":140,"wires":[]},{"id":"fe6c5b57.979a2","type":"debug","z":"db434db0.ef47a8","name":"debug everything","active":true,"console":"false","complete":"true","x":790,"y":400,"wires":[]},{"id":"b593c09f.eb0b","type":"mqtt in","z":"db434db0.ef47a8","name":"","topic":"#","qos":"2","broker":"30cce66c.5a7b6a","x":530,"y":400,"wires":[["fe6c5b57.979a2"]]},{"id":"3a58d923.6f642e","type":"debug","z":"db434db0.ef47a8","name":"debug test opencv","active":true,"console":"false","complete":"true","x":790,"y":260,"wires":[]},{"id":"2b031771.a46af","type":"mqtt in","z":"db434db0.ef47a8","name":"","topic":"opencv","qos":"2","broker":"30cce66c.5a7b6a","x":530,"y":260,"wires":[["3a58d923.6f642e"]]},{"id":"b505f937.061e38","type":"inject","z":"db434db0.ef47a8","name":"","topic":"","payload":"test $(HOSTNAME)","payloadType":"str","repeat":"","crontab":"","once":false,"x":150,"y":320,"wires":[["40e35da0.7006b4"]]},{"id":"40e35da0.7006b4","type":"mqtt out","z":"db434db0.ef47a8","name":"","topic":"$(HOSTNAME)","qos":"","retain":"","broker":"30cce66c.5a7b6a","x":380,"y":320,"wires":[]},{"id":"3dbd0d32.1eecca","type":"inject","z":"db434db0.ef47a8","name":"","topic":"","payload":"test pi","payloadType":"str","repeat":"","crontab":"","once":false,"x":110,"y":80,"wires":[["8007a817.2fea38"]]},{"id":"83bf049a.de15f","type":"debug","z":"db434db0.ef47a8","name":"debug test pi","active":true,"console":"false","complete":"true","x":770,"y":80,"wires":[]},{"id":"1a57c275.6bf236","type":"mqtt in","z":"db434db0.ef47a8","name":"","topic":"pi","qos":"2","broker":"30cce66c.5a7b6a","x":530,"y":80,"wires":[["83bf049a.de15f"]]},{"id":"8007a817.2fea38","type":"mqtt out","z":"db434db0.ef47a8","name":"","topic":"pi","qos":"","retain":"","broker":"30cce66c.5a7b6a","x":310,"y":80,"wires":[]},{"id":"30cce66c.5a7b6a","type":"mqtt-broker","z":"","broker":"hillst.local","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"”}]




Nick O'Leary

unread,
Nov 25, 2017, 6:20:00 PM11/25/17
to Node-RED Mailing List
Hi,

(Zenofmud: please see my response near at the start of this chain... for some reason I forget, HOSTNAME is not made available within node's process.env object - that's just a particular node.js thing).

right, I have manually verified on my Pi what does and doesn't work. Here are the facts.

I can confirm that editing /etc/profile does not help. Things set in there are available in a regular terminal session, but they are not set for a process running under systemd.

I have found an approach for setting env vars for systemd processes that does work (without editing the original service file), which I'll detail at the end of this email.

But, I completely forgot there is a VERY simple way to do this that doesn't involve any systemd stuff

1. Edit your node-red settings file (/home/pi/.node-red/settings.js) and add the following (above the module.exports lines):

    process.env.HOSTNAME = require('os').hostname();

2. restart Node-RED. Et Voila - $(HOSTNAME) now works.

You can set any env var you want under the `process.env` object.

My apologies for not remembering that a day ago!



Nick

-----------------------

For completeness, the approach for setting env vars under systemd is as follows:

1. Create the directory /etc/systemd/system/nodered.service.d

    sudo mkdir -p /etc/systemd/system/nodered.service.d

2. Edit the file /etc/systemd/system/nodered.service.d/local.conf with the following contents:


[Service]
Environment="FOO=Test"


3. restart the systemd daemon and restart node-red

    sudo systemctl daemon-reload 
    node-red-stop
    node-red-start

But - with this approach $HOSTNAME isn't available either, so you can't readily get ahold of the hostname.







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.

Zenofmud

unread,
Nov 25, 2017, 6:27:29 PM11/25/17
to node...@googlegroups.com
Nick,
A minute after I hit send, I went back and look at the page you linked to and saw that yup, HOSTNAME wasn’t defined. When are they going to add unsend to emails (sheepish grin). I have verified that your solution works and hopefully this will solve the issue for Roiger.

Thanks Nick

Paul

esc...@missionroom.nl

unread,
Nov 25, 2017, 6:32:31 PM11/25/17
to Node-RED
JIHAAA it's working!
I can go to the bed now ;-)
Thanks Nick!
I really appreciate your help! And of course also a thanks to Colin and Paul!

It's doing now what i wanted it to do!

Zenofmud

unread,
Nov 25, 2017, 7:51:15 PM11/25/17
to node...@googlegroups.com
Nick,
One quick followup (as I’m trying to write an example) - can you access the environment variable in a function node? I’ve been searching and trying a bunch of things, but haven’t succeeded yet (if ever). If so, how?
Thanks 
Paul

--
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.

Nick O'Leary

unread,
Nov 25, 2017, 7:56:06 PM11/25/17
to node...@googlegroups.com

Hi Paul,

You  have to add process.env to functionGlobalContext as you would any other property not part of the default Function scope.

Nick


Zenofmud

unread,
Nov 26, 2017, 8:29:12 AM11/26/17
to node...@googlegroups.com
Ok, after a couple hours experimenting and googleing...can you give me an example where I could set a variable like SECRETMSG and use it in a function node. Lets sayI edit settings.js and add
process.env. SECRETMSG = “Nick and Dave are awesome”;

I know I can use it in nodes like the MQTT nodes using $(SECRETMSG)

But when you say "You  have to add process.env to functionGlobalContext…” what does that mean for a variable?
And what format would it be used in the function node i.e.:
var mymsg = $(SECRETMSG); 
or var mymsg = process.env.SECRETMSG;

nothing I’ve tried so far has worked. :>(

Thanks
Paul

p.s. I’ll write this all up when I get it to work.
On Nov 25, 2017, at 7:55 PM, Nick O'Leary <nick....@gmail.com> wrote:

functionGlobalContext
seceret

Nick O'Leary

unread,
Nov 26, 2017, 11:27:07 AM11/26/17
to Node-RED Mailing List
Hi Paul,

Are you familiar with the use of functionGlobalContext? https://nodered.org/docs/writing-functions#global-context
 
In your settings file, there's a property called functionGlobalContext that can be used to make things available within the Function node.

You can add something to functionGlobalContext to make process.env available:

     functionGlobalContext: {
        env: process.env
     }


Then, in your function node:

    var env = global.get('env');
    msg.payload = env.SECRETMSG;
    return msg;

And in a Change node, you should be able to use the 'global' type set to 'env.SECRETMSG'

Nick



--
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.

Dave C-J

unread,
Nov 26, 2017, 1:11:20 PM11/26/17
to Node-RED

That's NOT a secret !!!!
8-)

Zenofmud

unread,
Nov 26, 2017, 1:47:25 PM11/26/17
to node...@googlegroups.com
All right!! I got it working!! Thanks and Dave your right, it is not a secret (GRIN).
Paul
On Nov 26, 2017, at 11:26 AM, Nick O'Leary <nick....@gmail.com> wrote:

SECRETMSG

Zenofmud

unread,
Nov 30, 2017, 8:43:57 AM11/30/17
to node...@googlegroups.com
For anyone referencing this in the future, I just created a flow of examples - Using environmental variables (system or user defined) - and added it to the flows page.

Paul
> --
> 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/3B231B8B-ECDA-4F35-8DEA-540D3E635E2E%40zenofmud.org.
Reply all
Reply to author
Forward
0 new messages