# How to control the frequency of a message in modbus dynamically

**URL:** <https://discourse.nodered.org/t/how-to-control-the-frequency-of-a-message-in-modbus-dynamically/22130>\
**Category:** General\
**Created:** [23 February 2020 10:53 UTC](https://discourse.nodered.org/t/how-to-control-the-frequency-of-a-message-in-modbus-dynamically/22130 "2020-02-23T10:53:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![smithtek](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smithtek/32/17411_2.png) [@smithtek](https://discourse.nodered.org/u/smithtek)\
**Post date:** [23 February 2020 10:53 UTC](https://discourse.nodered.org/t/how-to-control-the-frequency-of-a-message-in-modbus-dynamically/22130/1 "2020-02-23T10:53:45Z")

</div>

Hi.  
I have searched high and low for a node that could handle this but nothing seemed to be available.  
Im using the Modbus getter nodes. You can control the polling frequency by injecting the input of the getter nodes with any message. using the core inject node you can set it up and leave it to poll indefinetly.

Im trying to find a way i can dynamically alter the speed of the polling.  
The end scenario will be a mqtt input node passing a msg object with a number payload. the number will control the polling dynamically. The output payload will speed up and down as per the value i send.

Does anyone know of a node capable of doing this or would i need to write this in a function node ?

Thanks

---

<div class="post-metadata">

**Author:** ![smithtek](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smithtek/32/17411_2.png) [@smithtek](https://discourse.nodered.org/u/smithtek)\
**Post date:** [25 February 2020 05:45 UTC](https://discourse.nodered.org/t/how-to-control-the-frequency-of-a-message-in-modbus-dynamically/22130/2 "2020-02-25T05:45:04Z")

</div>

Anyone have any ideas ?

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [25 February 2020 07:50 UTC](https://discourse.nodered.org/t/how-to-control-the-frequency-of-a-message-in-modbus-dynamically/22130/3 "2020-02-25T07:50:54Z")

</div>

First thing I would think of is using a `delay` node and some kind of loop where you set the delay property to your needs. You would need the start the loop once at start-up using a trigger node.

Basically something like:

```auto
[{"id":"8abca4e5.2422e","type":"inject","z":"c154316d.413728","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":310,"y":280,"wires":[["fdac95ba.4bc3c8"]]},{"id":"fdac95ba.4bc3c8","type":"delay","z":"c154316d.413728","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":520,"y":280,"wires":[["f1687e0d.6dea38"]]},{"id":"137b8350.1c0e0d","type":"debug","z":"c154316d.413728","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":280,"wires":[]},{"id":"3102c38b.63b7b4","type":"change","z":"c154316d.413728","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"1000","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":400,"wires":[["fdac95ba.4bc3c8"]]},{"id":"f1687e0d.6dea38","type":"function","z":"c154316d.413728","name":"(modbus get)","func":"\nreturn msg;","outputs":1,"noerr":0,"x":740,"y":280,"wires":[["3102c38b.63b7b4","137b8350.1c0e0d"]]}]

```

Needs some fine tuning and some extra nodes to control the loop (break behavior), but should give the general idea.

---

<div class="post-metadata">

**Author:** ![smithtek](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smithtek/32/17411_2.png) [@smithtek](https://discourse.nodered.org/u/smithtek)\
**Post date:** [26 February 2020 12:56 UTC](https://discourse.nodered.org/t/how-to-control-the-frequency-of-a-message-in-modbus-dynamically/22130/4 "2020-02-26T12:56:43Z")

</div>

Thanks Kuema.  
Delay node it is. I was hoping there was a node that packed all the functions.

Here is the flow. Works well. The idea is to replace the slider with Mqtt.

```auto
[{"id":"8edb54a2.4f9348","type":"inject","z":"49c5393e.540eb8","name":"","topic":"","payload":"Poll","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":210,"y":120,"wires":[["dc08b636.516748"]]},{"id":"dc08b636.516748","type":"delay","z":"49c5393e.540eb8","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":360,"y":180,"wires":[["b976b2b1.9da97"]]},{"id":"5f2ce01c.9f2ac","type":"debug","z":"49c5393e.540eb8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":180,"wires":[]},{"id":"bef1b27b.ec59f","type":"change","z":"49c5393e.540eb8","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"number","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":300,"wires":[["dc08b636.516748"]]},{"id":"b976b2b1.9da97","type":"function","z":"49c5393e.540eb8","name":"(modbus get)","func":"\nreturn msg;","outputs":1,"noerr":0,"x":580,"y":180,"wires":[["5f2ce01c.9f2ac","bef1b27b.ec59f"]]},{"id":"9427554a.eff3c8","type":"ui_slider","z":"49c5393e.540eb8","name":"","label":"slider","tooltip":"","group":"9180e33e.1a4c2","order":0,"width":0,"height":0,"passthru":true,"outs":"all","topic":"msg.delay","min":"1000","max":"10000","step":"1000","x":250,"y":360,"wires":[["28bb28d5.293468"]]},{"id":"28bb28d5.293468","type":"change","z":"49c5393e.540eb8","name":"","rules":[{"t":"set","p":"number","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":360,"wires":[[]]},{"id":"9180e33e.1a4c2","type":"ui_group","z":"","name":"Solar","tab":"2d5d3e80.108712","order":1,"disp":true,"width":"6","collapse":false},{"id":"2d5d3e80.108712","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 April 2020 12:56 UTC](https://discourse.nodered.org/t/how-to-control-the-frequency-of-a-message-in-modbus-dynamically/22130/5 "2020-04-26T12:56:47Z")

</div>

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