Is it possible to emulate pressing the Deploy button in a function node ?

928 views
Skip to first unread message

Toshi Bass

unread,
Jan 13, 2016, 4:47:45 AM1/13/16
to Node-RED
Is it possible to emulate pressing the Deploy button in a function node ? 

I have a long running issue with node-red contrib-blynk .. everything is working fine but at a seemingly random interval perhaps once in a day or perhaps once an a week the blynk server disconnects then goes into a connect / disconnect loop every 5 seconds this will go on for ever, the only way to reconnect the server is to press Deploy in node-red ... now clearly this is a issue with blynk and they have been trying to solve this issue for months but its not getting resolved and is ruining what is a otherwise a very stable app..

So what I would like to do is when I blynk goes off line (I can detect this in node-red)  start a count .. when the count reaches a set value re-Deploy node-red, obviously I want to limit the number of re-Deploys don't want to create another loop but my experience is it only ever needs one re-Deploy to solve the problem. 

Toshi

Nicholas O'Leary

unread,
Jan 13, 2016, 4:50:28 AM1/13/16
to Node-RED Mailing List
If you're running 0.12.2 or later, you can POST to /flows with the Node-RED-Deployment-Type header set to 'reload' and the runtime will reload your flows from storage and restart them.

Nick

--
http://nodered.org
---
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.
For more options, visit https://groups.google.com/d/optout.

Nicholas O'Leary

unread,
Jan 13, 2016, 4:50:46 AM1/13/16
to Node-RED Mailing List

Toshi Bass

unread,
Jan 13, 2016, 10:12:12 AM1/13/16
to Node-RED
Any chance of giving me a example flow for this, I am just not understanding Node-RED-Deployment-Type header (I am pretty dim)

like am I supposed to be using a http node or a function node

Node-RED version: v0.12.5

Nicholas O'Leary

unread,
Jan 13, 2016, 10:17:00 AM1/13/16
to Node-RED Mailing List
Here you go...

You'll may need to change the 'http request' node url to point at your own instance.

[{"id":"51461d53.aeb9e4","type":"inject","z":"a09be5e0.5f6418","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":96,"y":29,"wires":[["213813eb.dec7ec"]]},{"id":"213813eb.dec7ec","type":"function","z":"a09be5e0.5f6418","name":"","func":"msg.headers = {\n    \"Node-RED-Deployment-Type\":\"reload\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":236,"y":29,"wires":[["ac6c6bee.539398"]]},{"id":"ac6c6bee.539398","type":"http request","z":"a09be5e0.5f6418","name":"","method":"POST","ret":"txt","url":"http://localhost:1880/flows","x":376,"y":29,"wires":[["a78b2fda.5874d"]]},{"id":"a78b2fda.5874d","type":"debug","z":"a09be5e0.5f6418","name":"","active":true,"console":"false","complete":"false","x":536,"y":29,"wires":[]}]

--

Toshi Bass

unread,
Jan 13, 2016, 10:38:13 AM1/13/16
to Node-RED
OK that sheds some light on how to do Node-RED-Deployment-Type header, however even when I change the 'http request' node url I still get the same same error response ...

{"error":"unexpected_error","message":"TypeError: Object #<Object> has no method 'forEach'"}

I get the same in postman, but a simple http node with GET http://192.168.0.98:1880/flows   results with a list as expected ....

[{"type":"tab","id":"3f8608e5.c079f8","label":"Project v1 2972"},{"type":"tab","id":"63fb05f7","label":"Project v2 adf0"},{"type":"tab","id":"c6ae6186","label":"Project v3 f165"},{"type":"tab","id":"9f0ffb","label":"Project v4 0cc7"},{"id":"e854b4 etc etc.....

Walter Kraembring

unread,
Jan 14, 2016, 2:50:56 AM1/14/16
to Node-RED
Hello,
I tried this flow but it just says 'Unauthorized'

(I have Node-RED secured with passwords for both adminAuth and httpNodeAuth)



Best regards, Walter



Toshi Bass

unread,
Jan 14, 2016, 4:22:16 AM1/14/16
to Node-RED
Hi Walter, I assume from your post that the flow to "reload" the nodes worked after you modified the security section ?.

Unfortunately it doesn't help as I don't have node-red secured with passwords yet, to prove that I enter http://192.168.0.98:1880/auth/login     result {}

So I am stuck with {"error":"unexpected_error","message":"TypeError: Object #<Object> has no method 'forEach'"} unless were saying for this to work nr needs to be secured with passwords ? 

Toshi

Nicholas O'Leary

unread,
Jan 14, 2016, 4:49:11 AM1/14/16
to Node-RED Mailing List
Walter,

if the admin api has been secured then you would need to follow the steps described in the docs for getting an admin access token: http://nodered.org/docs/api/admin/oauth.html - the admin api does not use Basic Authentication. 


Toshi,

not sure what's causing that. It should have also logged a stacktrace to the console - can you share that?


--

Toshi Bass

unread,
Jan 14, 2016, 4:50:47 AM1/14/16
to Node-RED
Here's the log for the error: 

TypeError: Object #<Object> has no method 'forEach'
    at Object.module.exports.parseConfig (/usr/lib/node_modules/node-red/red/nodes/flows/util.js:52:16)
    at Object.setConfig [as setFlows] (/usr/lib/node_modules/node-red/red/nodes/flows/index.js:88:34)
    at module.exports.post (/usr/lib/node_modules/node-red/red/api/flows.js:31:18)
    at Layer.handle [as handle_request] (/usr/lib/node_modules/node-red/node_modules/express/lib/router/layer.js:95:5)
    at next (/usr/lib/node_modules/node-red/node_modules/express/lib/router/route.js:131:13)
    at /usr/lib/node_modules/node-red/red/api/auth/index.js:61:13
    at Layer.handle [as handle_request] (/usr/lib/node_modules/node-red/node_modules/express/lib/router/layer.js:95:5)
    at next (/usr/lib/node_modules/node-red/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/usr/lib/node_modules/node-red/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/usr/lib/node_modules/node-red/node_modules/express/lib/router/layer.js:95:5)


Nicholas O'Leary

unread,
Jan 14, 2016, 4:55:33 AM1/14/16
to Node-RED Mailing List
Huh, I was sure this feature went into 0.12.2 ... but I was wrong. It will be in 0.13.

My apologies for the confusion.

Toshi Bass

unread,
Jan 14, 2016, 12:08:29 PM1/14/16
to Node-RED
OK I will wait for imminent 0.13 release of coarse when you finish that pesky mountain of documentation :(

Incidentaly while I was searching for something else I came across this post from August   https://groups.google.com/d/msg/node-red/hs2Y2ljearg/t2D0pr3PDgAJ  where I asked the same question, just forgot I did that sorry !!!!!!
Reply all
Reply to author
Forward
0 new messages