Description

By default, Node-red's login password is the same as the gateway WEB GUI. This example applies to applications that require Node-red's login password to be different from the gateway WEB GUI and can modify Node-red's login credentials directly through Node-red.

 

 

Requirement

  • Milesight Gateway: UG56/UG65/UG67

 

Configuration

Step 1: Launch Node-RED and Import Flow Example

1. Go to App > Node-RED page to enable Node-RED program and wait for a while to load the program, click Launch button to start Node-RED web GUI.

 

2. Log in the Node-RED web GUI. The account information is the same as gateway web GUI. 

 

 

3. Click Import to import the node-red flow example by pasting the content or import the json format file.

 

 

Step 2: Node-RED Configuration

Flow structure:


Content:

[{"id":"42decf2684049ede","type":"tab","label":"Flow 4","disabled":false,"info":"","env":[]},{"id":"675876bf505cca8a","type":"inject","z":"42decf2684049ede","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":460,"wires":[["5c96e16b7e5bf9d3"]]},{"id":"5c96e16b7e5bf9d3","type":"exec","z":"42decf2684049ede","command":"echo -e \"password123\" | node-red admin hash-pw","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":480,"y":460,"wires":[["beb95d7db56b8035"],[],[]]},{"id":"e4439eafa1c45449","type":"exec","z":"42decf2684049ede","command":"cd /etc/node_red;sed -i '120s|.*|\\t\\tpassword: \"$2a$08$4Z5d9hMZ1bLDsur93SNbgObCoeNNYXUst.CKcibIH4ctiWfuGNgFS\",|'  settings.js","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":740,"y":600,"wires":[["b69df24f0924571c"],[],[]]},{"id":"c384cc9d1dd89f23","type":"inject","z":"42decf2684049ede","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":600,"wires":[["e4439eafa1c45449"]]},{"id":"b69df24f0924571c","type":"debug","z":"42decf2684049ede","name":"debug 12","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1360,"y":620,"wires":[]},{"id":"2ec8833540849fdc","type":"comment","z":"42decf2684049ede","name":"Generate new hash encryption for new password \"password123\"","info":"","x":490,"y":420,"wires":[]},{"id":"011e1fbd28bda5d2","type":"comment","z":"42decf2684049ede","name":"Modify new password for Node-Red login to password123","info":"","x":470,"y":560,"wires":[]},{"id":"80fc567dfd1227df","type":"inject","z":"42decf2684049ede","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":320,"wires":[["c2bffe983363aaae"]]},{"id":"c2bffe983363aaae","type":"exec","z":"42decf2684049ede","command":"cd /etc/node_red;sed -i '119s|.*|\\t\\tusername: \"admin123\",|'  settings.js","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":530,"y":320,"wires":[["0e574d1bae3c4e21"],[],[]]},{"id":"b6a674233fe9896f","type":"comment","z":"42decf2684049ede","name":"Modify new username for Node-Red login to admin123","info":"","x":460,"y":280,"wires":[]},{"id":"beb95d7db56b8035","type":"debug","z":"42decf2684049ede","name":"debug 11","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":460,"wires":[]},{"id":"0e574d1bae3c4e21","type":"debug","z":"42decf2684049ede","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":900,"y":320,"wires":[]},{"id":"78a0ceadac60e9d9","type":"inject","z":"42decf2684049ede","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":720,"wires":[["08e5068a565edf20"]]},{"id":"08e5068a565edf20","type":"exec","z":"42decf2684049ede","command":"reboot","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":330,"y":720,"wires":[["c87fbe3898027808"],[],[]]},{"id":"c87fbe3898027808","type":"debug","z":"42decf2684049ede","name":"debug 14","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":550,"y":740,"wires":[]},{"id":"77e305a6bfbfc83b","type":"comment","z":"42decf2684049ede","name":"Trigger a gateway reboot","info":"","x":370,"y":680,"wires":[]}]


Step 3: Deploy and Check Result

1. Click Deploy to save all node-red configurations.


2. If you need to change the login username for Node-Red, click the 1st trigger rule. ‘admin123’ can be changed to the username you want to set.


Once the changes are complete, click Deploy to save the setting and click on the 4th rule to trigger a gateway reboot for the configuration to take effect.

 

 

3. If you need to change Node-Red's login password, you need to click on the 2nd rule to generate the corresponding hash value for Node-Red's new password. ‘password123’ can be changed to the password you want to set.

 

Copy the hash password generated in the previous command into the 3rd rule ,and click Trigger to modify it.

 

Once the changes are complete, click Deploy to save the setting and click on the 4th rule to trigger a gateway reboot for the configuration to take effect.


Note: If you change username and password of the gateway login again in the gateway web interface after changing the Node-red password, then the login password of Node-red will be synchronized with the new password of the gateway, and the login username of Node-red will not be affected.

 

4. After rebooting, you could log in to Node-Red with new username or password.

 

-------END-----