Incrementing HTTP Post

#1

I have a situation where I am sending a HTTP Post command to a series of IP devices.
The IP devices have sequential IP address
For example:
192.168.1.1
192.168.1.2...
192.168.1.100

I have tried the attached flow , although the debug shows it is sending out the correct msg.url as expected the commands are not being executed in the HTTP node.

Any suggestions?


[{"id":"1e8207bc.ac5ba8","type":"function","z":"2d9d8e01.84ef32","name":"","func":"var counter = msg.payload;\nvar TxCh =global.get('TXChSelected');\nvar temp = global.get(\"HddsxRxSelected\");\nvar RX_IP = 'http://172.31.3.';\nvar  CGI_switch_command = '/cgi-bin/query.cgi?cmd=rxswitch:';\n\n\nif(counter <=10){\n    msg.payload = counter++;\n    msg.url = RX_IP+counter+CGI_switch_command+'00'+TxCh;\n    return msg;\n}\n\n\n","outputs":1,"noerr":0,"x":750,"y":300,"wires":[["9f34c62f.36f478","63630687.c39168","d252a40e.5d1058"]]},{"id":"5a835f2d.c7a11","type":"delay","z":"2d9d8e01.84ef32","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":820,"y":200,"wires":[["1e8207bc.ac5ba8"]]},{"id":"f2a266af.4562d8","type":"inject","z":"2d9d8e01.84ef32","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":590,"y":300,"wires":[["1e8207bc.ac5ba8"]]},{"id":"9f34c62f.36f478","type":"function","z":"2d9d8e01.84ef32","name":"++","func":"\n    msg.payload = msg.payload+1;\n    return msg;\n\n\n","outputs":1,"noerr":0,"x":690,"y":200,"wires":[["5a835f2d.c7a11"]]},{"id":"63630687.c39168","type":"http request","z":"2d9d8e01.84ef32","name":"Switch RX","method":"POST","ret":"txt","url":"","tls":"","x":950,"y":300,"wires":[[]]},{"id":"d252a40e.5d1058","type":"debug","z":"2d9d8e01.84ef32","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"url","x":890,"y":380,"wires":[]}]
0 Likes

#2

In order for your flow to be importable it is necessary to put a line containing three backtick characters before it, and another such line after it. You can edit your post to put them in.

0 Likes

#3

Thank you Colin for the info. I have wrapped the example code with ~~~ and it is below.

[{"id":"1e8207bc.ac5ba8","type":"function","z":"2d9d8e01.84ef32","name":"","func":"var counter = msg.payload;\nvar TxCh =global.get('TXChSelected');\nvar temp = global.get("HddsxRxSelected");\nvar RX_IP = '[http://172.31.3](http://172.31.0.3/).';\nvar CGI_switch_command = '/cgi-bin/query.cgi?cmd=rxswitch:';\n\n\nif(counter &lt;=10){\n msg.payload = counter++;\n msg.url = RX_IP+counter+CGI_switch_command+'00'+TxCh;\n return msg;\n}\n\n\n","outputs":1,"noerr":0,"x":750,"y":300,"wires":[["9f34c62f.36f478","63630687.c39168","d252a40e.5d1058"]]},{"id":"5a835f2d.c7a11","type":"delay","z":"2d9d8e01.84ef32","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":820,"y":200,"wires":[["1e8207bc.ac5ba8"]]},{"id":"f2a266af.4562d8","type":"inject","z":"2d9d8e01.84ef32","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":590,"y":300,"wires":[["1e8207bc.ac5ba8"]]},{"id":"9f34c62f.36f478","type":"function","z":"2d9d8e01.84ef32","name":"++","func":"\n msg.payload = msg.payload+1;\n return msg;\n\n\n","outputs":1,"noerr":0,"x":690,"y":200,"wires":[["5a835f2d.c7a11"]]},{"id":"63630687.c39168","type":"http request","z":"2d9d8e01.84ef32","name":"Switch RX","method":"POST","ret":"txt","url":"","tls":"","x":950,"y":300,"wires":[[]]},{"id":"d252a40e.5d1058","type":"debug","z":"2d9d8e01.84ef32","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"url","x":890,"y":380,"wires":[]}] 
0 Likes

#4

They should be backtick characters, not tildes. And make sure they are on separate lines one before and one after. You can check whether it is right by trying to import it yourself from your post. You don't need to re-post, just edit the previous post using the pen icon at the bottom of the post.

0 Likes