Skip to content

Commit

Permalink
Merge pull request #3 from Pubaluba/Threading-patch
Browse files Browse the repository at this point in the history
Threading patch
  • Loading branch information
Pubaluba authored Jan 22, 2024
2 parents c6f6db3 + 5a946d2 commit 8bfee82
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modbus4mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
from ccorp.ruamel.yaml.include import YAML
import click
import paho.mqtt.client as mqtt
import threading

from . import modbus_interface
version = "EW.0.81"
version = "EW.0.9"
MAX_DECIMAL_POINTS = 3
DEFAULT_SCAN_RATE_S = 5

Expand Down Expand Up @@ -380,8 +381,10 @@ def _load_modbus_config(self, path):
def loop_forever(self):
while True:
# TODO this properly.
self.poll()
pollthread = threading.Thread(target = self.poll, args = ())
pollthread.start()
sleep(self.config.get('update_rate', DEFAULT_SCAN_RATE_S))
pollthread.join()

def singlerun(self):
self.poll()
Expand Down

1 comment on commit 8bfee82

@pki791
Copy link

@pki791 pki791 commented on 8bfee82 Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the benefit of threading in that case?
Look my commit here pki791@8e0461c

I have done the polling timer based, to the time to next poll is calculated by (time % rate) so it always start on time.

Please sign in to comment.