HTTP request bulk group assignment



  • Hi, sending a bulk request group assignment to relays, only the last relay switches on. all others just click without switching. It seems that the bulk request is too fast for the unpi 1.1. relays. Can you confirm this?


  • administrators

    Hi @juntiedt,
    can you please share your code for bulk request?

    Thanks,
    Martin



  • this is my code within node-red

    msg.url = "http://10.0.0.52:8080/bulk";
    msg.headers = '{"content-type":"application/json"}';
    msg.payload = '{"group_assignments": [{"device_type":"relay","assigned_values":{"value": 1}}]}';
    return msg;
    
    [{"id":"513c2375.8dd04c","type":"function","z":"8737dbc7.9d0da8","name":"Bulk Relay on","func":"msg.url = \"http://10.0.0.52:8080/bulk\";\nmsg.headers = '{\"content-type\":\"application/json\"}';\nmsg.payload = '{\"group_assignments\": [{\"device_type\":\"relay\",\"assigned_values\":{\"value\": 1}}]}';\nreturn msg;\n","outputs":1,"noerr":0,"x":300,"y":480,"wires":[["aeccdaf4.9f6458"]]},{"id":"aeccdaf4.9f6458","type":"http request","z":"8737dbc7.9d0da8","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"","tls":"","proxy":"","authType":"basic","x":530,"y":500,"wires":[[]]},{"id":"44fd9776.d524a8","type":"function","z":"8737dbc7.9d0da8","name":"Bulk Relay off","func":"msg.url = \"http://10.0.0.52:8080/bulk\";\nmsg.headers = '{\"content-type\":\"application/json\"}';\nmsg.payload = '{\"group_assignments\": [{\"device_type\":\"relay\",\"assigned_values\":{\"value\": 0}}]}';\nreturn msg;\n","outputs":1,"noerr":0,"x":300,"y":520,"wires":[["aeccdaf4.9f6458"]]},{"id":"79d7a128.535bb","type":"inject","z":"8737dbc7.9d0da8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":480,"wires":[["513c2375.8dd04c"]]},{"id":"507fa2db.5a945c","type":"inject","z":"8737dbc7.9d0da8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":520,"wires":[["44fd9776.d524a8"]]}]```


  • the slow version works ok

    [{"id":"fafe105b.048f4","type":"function","z":"8737dbc7.9d0da8","name":"","func":"\nvar rn = parseInt(flow.get('loops'));\nvar onoff = parseInt(flow.get('onoff'));\nmsg.payload = [rn,onoff,0]; \nreturn msg;","outputs":1,"noerr":0,"x":430,"y":300,"wires":[["7989a53f.33b07c","e711aba3.e2aa38"]]},{"id":"7989a53f.33b07c","type":"function","z":"8737dbc7.9d0da8","name":"","func":"var rmax = flow.get('count');\nvar cnt = flow.get('loops');\ncnt = cnt +1;\nflow.set('loops',cnt);\nif (cnt <= rmax){\n    return msg;\n}    ","outputs":1,"noerr":0,"x":430,"y":380,"wires":[["63b8469f.9604a8"]]},{"id":"554d2bad.2071a4","type":"function","z":"8737dbc7.9d0da8","name":"","func":"flow.set('count',8);\nflow.set('loops',1);\nflow.set('onoff', msg.payload);\nmsg.payload = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":300,"wires":[["fafe105b.048f4"]]},{"id":"63b8469f.9604a8","type":"delay","z":"8737dbc7.9d0da8","name":"","pauseType":"delay","timeout":"70","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":430,"y":340,"wires":[["fafe105b.048f4"]]},{"id":"e711aba3.e2aa38","type":"function","z":"8737dbc7.9d0da8","name":"post","func":"var rn = (msg.payload[0]).toString();\nvar rv = (msg.payload[1]).toString();\nvar rt = (msg.payload[2]).toString();\nmsg.url = \"http://10.0.0.52:8080/json/relay/\" + rn;\nmsg.headers = '{\"content-type\":\"application/json\"}';\nif (rt == \"0\"){\n    msg.payload = '{\"value\": \"' + rv +'\"}';\n}\nelse {\n    msg.payload = '{\"value\": \"' + rv +'\",\"timeout\": \"' + rt + '\"}';\n}    \nreturn msg;\n","outputs":1,"noerr":0,"x":570,"y":300,"wires":[["56eb0da5.2e5ad4"]]},{"id":"56eb0da5.2e5ad4","type":"http request","z":"8737dbc7.9d0da8","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"","tls":"","proxy":"","authType":"basic","x":730,"y":300,"wires":[[]]},{"id":"6e845bbf.8ec644","type":"inject","z":"8737dbc7.9d0da8","name":"alle Relays on","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":280,"wires":[["554d2bad.2071a4"]]},{"id":"85d78b7b.ebab08","type":"inject","z":"8737dbc7.9d0da8","name":"alle Relays off","topic":"","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":320,"wires":[["554d2bad.2071a4"]]},{"id":"f0c0d75e.a119f8","type":"ui_button","z":"8737dbc7.9d0da8","name":"","group":"fcc9c186.32f2d","order":1,"width":0,"height":0,"passthru":false,"label":"alle Relays on","tooltip":"","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"str","topic":"","x":120,"y":240,"wires":[["554d2bad.2071a4"]]},{"id":"bea16915.e5a998","type":"ui_button","z":"8737dbc7.9d0da8","name":"","group":"fcc9c186.32f2d","order":3,"width":0,"height":0,"passthru":false,"label":"alle Relays aus","tooltip":"","color":"","bgcolor":"","icon":"","payload":"0","payloadType":"str","topic":"","x":120,"y":360,"wires":[["554d2bad.2071a4"]]},{"id":"fcc9c186.32f2d","type":"ui_group","z":"","name":"","tab":"275e79b3.d6faf6","order":1,"disp":false,"width":"8","collapse":false},{"id":"275e79b3.d6faf6","type":"ui_tab","z":"","name":"R","icon":"dashboard","order":4,"disabled":false,"hidden":false}]```