Hello I need to get the name of my device "hostname" (is a raspberry) where is loaded Node-red.
So I need to create a payload with the name of the device (set by Pi configuration form -> "hostname" field)
Thank you
Hello I need to get the name of my device "hostname" (is a raspberry) where is loaded Node-red.
So I need to create a payload with the name of the device (set by Pi configuration form -> "hostname" field)
Thank you
an exec node set to run hostname
?
(and don't append the payload from the incoming message.)
[{"id":"da669b10.7253d8","type":"debug","z":"e9b4dddd.70115","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":60,"wires":[]},{"id":"3078162b.0ab55a","type":"exec","z":"e9b4dddd.70115","command":"hostname","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":300,"y":60,"wires":[["da669b10.7253d8"],[],[]]},{"id":"6238f928.ad4ca8","type":"inject","z":"e9b4dddd.70115","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":60,"wires":[["3078162b.0ab55a"]]}]
By "hostname", do you mean "myDeviceName"?
That is in the settings.js
file.
Add 'os:requrie('os') item to the global context... example of this is in the settings file how to do this.
Then you just do a global get to the 'os' node to get the hostname() function results. For example I do this at times in a function node...
var theHost = global.get('os').hostname().split('.')[0];
The above gets just 'host' name, ignoring any domain name element of the host FQDN (Full Qualified Doman Name) returned. So 'host' not 'host.domain.com' for example.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.