Open link to execute flow

Hey gang,
I'm not sure if Dashboard is the best place to post this, but I have a Dashboard with several buttons that run different functions. Some of them are simple things like 'send magic packet (wake on lan)' or 'power-cycle USB port'.

Is there a way to create a direct link (that I can bookmark in my browser) to execute a specific flow? So if I want to power-cycle a USB port, I can just click that bookmarked link. (Bonus points if it doesn't open a new tab, like some kind of javascript:void(window.open('http://... adaptation.)

Thanks in advance,
Dax.

You can create endpoints in node-red that can be saved to bookmarks. Node-RED Cookbook : Node-RED

[edit] You can have query strings and :name parameters on the urls, which you can use in a switch node or link nodes to route to specific flows.

What do you mean by execute a specific flow? Do you mean 'send a message into the flow'? If so then just send the message. You can use a Link node to link to a different flow tab.

@E1cid Ahh, HTML endpoints! Yes, that sounds like the right kind of thing. Thanks so much, I'll read into that.

@Colin, I would like to be able to 'inject' (like pushing a button) simply by visiting a specific URL (while I'm connected to the LAN, of course, not a WWW link).

I'm kinda confused about how the http-in node should work. I added it, but I get a warning message when I go to deploy that it's not configured properly, though there are barely any settings to configure.

When I go to http://192.168.2.221:1880/ilok, nothing happens. I was expecting it to send a packet to the node it's connected to.


Look at the cookbook examples again, It shows a http in must have a corresponding http response node. With the response node you can send a payload back to the browser. This pay load could be text, json, or even a html page.
p.s. Are you running docker any other type of virtual machine?

But what if I don't need a response to the browser? (aka I just want it to 'do the thing". :slight_smile: )

You do, as that is how the http protocol works, if no response is sent then a time out error occurs. The response does not need to be configured, the http response node by default sends the OG payload and a 200 http statusCode.

Man, I feel like such a dunce. I've added the http response node, but I still get an error on deployment.

PLease export your flow and post here.
How to import/export a flow

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

Please also tell us about you system
Platform
Are you using docker? or other virtual machine.
node-red version
nodejs version

Also it looks like have extra http in nodes in the Raspberry Pi Control Centre flow tab, that are not configure, try deleting them

Also In the sidebar select config panel and select unused, if any configs are there, highlight them and press delete.

It would still be safe to confirm deploy with the error.

p.s. you may benefit from watching the essentials videos

Hi E1cid, thanks for your offer of help.
-Raspberry Pi
-No docker/VM
-Versions:
Node-RED version: v2.1.6
Node.js version: v14.18.3
Linux 5.10.103-v7l+ arm LE

[{"id":"113816ef2faa5043","type":"inject","z":"d157f38a.e4969","name":"Power-cycle iLok","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":380,"wires":[["2dbe35ba30bcfef6"]]},{"id":"3d1b6ef4d7ba8e6d","type":"trigger","z":"d157f38a.e4969","name":"","op1":"0","op2":"1","op1type":"str","op2type":"str","duration":"2","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":500,"y":380,"wires":[["ab66bf3b5d78b436"]]},{"id":"2dbe35ba30bcfef6","type":"ui_button","z":"d157f38a.e4969","name":"","group":"fb05ea75.c1a778","order":6,"width":0,"height":0,"passthru":false,"label":"Power-cycle iLok","tooltip":"","color":"","bgcolor":"green","className":"","icon":"fa-usb","payload":"true","payloadType":"bool","topic":"topic","topicType":"msg","x":330,"y":380,"wires":[["3d1b6ef4d7ba8e6d"]]},{"id":"ab66bf3b5d78b436","type":"rpi-gpio out","z":"d157f38a.e4969","name":"","pin":"18","set":true,"level":"1","freq":"","out":"out","bcm":true,"x":640,"y":380,"wires":[]},{"id":"e4275e0f2fbff120","type":"http in","z":"d157f38a.e4969","name":"power-cycle ilok","url":"/ilok","method":"get","upload":false,"swaggerDoc":"","x":140,"y":420,"wires":[["2a6a3c90fcd33d27","2dbe35ba30bcfef6"]]},{"id":"2a6a3c90fcd33d27","type":"http response","z":"d157f38a.e4969","name":"","statusCode":"","headers":{},"x":290,"y":420,"wires":[]},{"id":"fb05ea75.c1a778","type":"ui_group","name":"System Information","tab":"6513d922.c36558","order":1,"disp":true,"width":"6","collapse":false},{"id":"6513d922.c36558","type":"ui_tab","name":"Raspberry Pi Control Centre","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

The only issue see with your flow is the button node will block the inject and http in nodes, unless you check If msg arrives on input, emulate a button click: in the button node.
e.g.

[{"id":"2dbe35ba30bcfef6","type":"ui_button","z":"d1395164b4eec73e","name":"","group":"fb05ea75.c1a778","order":6,"width":0,"height":0,"passthru":true,"label":"Power-cycle iLok","tooltip":"","color":"","bgcolor":"green","className":"","icon":"fa-usb","payload":"true","payloadType":"bool","topic":"topic","topicType":"msg","x":350,"y":7260,"wires":[["3d1b6ef4d7ba8e6d"]]},{"id":"113816ef2faa5043","type":"inject","z":"d1395164b4eec73e","name":"Power-cycle iLok","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":7260,"wires":[["2dbe35ba30bcfef6"]]},{"id":"e4275e0f2fbff120","type":"http in","z":"d1395164b4eec73e","name":"power-cycle ilok","url":"/ilok","method":"get","upload":false,"swaggerDoc":"","x":160,"y":7300,"wires":[["2a6a3c90fcd33d27","2dbe35ba30bcfef6"]]},{"id":"3d1b6ef4d7ba8e6d","type":"trigger","z":"d1395164b4eec73e","name":"","op1":"0","op2":"1","op1type":"str","op2type":"str","duration":"2","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":520,"y":7260,"wires":[["643470bdb779d894"]]},{"id":"2a6a3c90fcd33d27","type":"http response","z":"d1395164b4eec73e","name":"","statusCode":"","headers":{},"x":310,"y":7300,"wires":[]},{"id":"643470bdb779d894","type":"debug","z":"d1395164b4eec73e","name":"debug 2489","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":7300,"wires":[]},{"id":"fb05ea75.c1a778","type":"ui_group","name":"System Information","tab":"6513d922.c36558","order":1,"disp":true,"width":"6","collapse":false},{"id":"6513d922.c36558","type":"ui_tab","name":"Raspberry Pi Control Centre","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Or wire the http in node after the button node.

I think what you are after is a ui_control node as that will fire an event when a page is loaded - so you could add a page for that purpose.

Alternatively, why not just use a button, instead of a link? The button fires a msg on click?

What I would like is to save a browser bookmark which executes a function directly like opening the dashboard, waiting for it to load, pressing the button, then closing it.

Create a HTTP End Point using HTTP-in --> HTTP Response
Open it in a browser and it will trigger the flow
Save a bookmark for the URL.

No dashboard required.

https://cookbook.nodered.org/http/create-an-http-endpoint

example:

2UtYrQaFYz

[{"id":"66faf5becbc5b6f2","type":"http in","z":"63d9d4c4aaf984d4","name":"","url":"/servertime","method":"get","upload":false,"swaggerDoc":"","x":710,"y":160,"wires":[["fb68cb2002faa168"]]},{"id":"fb68cb2002faa168","type":"function","z":"63d9d4c4aaf984d4","name":"get the current time","func":"const time = new Date().toLocaleString()\nmsg.payload = `It is ${time} on the Node-RED Server`\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":930,"y":160,"wires":[["129be91c0725deae","f04b2d13fcb8e2b9"]]},{"id":"129be91c0725deae","type":"http response","z":"63d9d4c4aaf984d4","name":"","statusCode":"","headers":{},"x":1140,"y":160,"wires":[]},{"id":"f04b2d13fcb8e2b9","type":"debug","z":"63d9d4c4aaf984d4","name":"response data","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1030,"y":220,"wires":[]}]

But, @joepavitt ui_control suggestion would also work

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.