Hello,
I needs some tips to send me in the right direction. I'm working on a plugin for one of my modbus sensors. I have a challenge that between messages there is unfortunately a 100 ms delay needed. I want to write this plugin by using the python plug framework. On this page you will find the following: "Waiting or sleeping. Plugins are single threaded so the whole plugin system will wait."
Obviously this is not what I want. Does anyone have tips on how to properly solve this with the python plug framework for Domoticz?
Python plugin wait/sleep challenge
Moderator: leecollings
Python plugin wait/sleep challenge
Last edited by neptunus on Wednesday 20 February 2019 18:32, edited 1 time in total.
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Python plugin waity/sleep challenge
@neptunus,
If you post your plugin source people can comment but generally you have 2 choices to avoid stalling the Python Framework:
If you post your plugin source people can comment but generally you have 2 choices to avoid stalling the Python Framework:
- Use the built in connection objects for reading and writing (recommended)
- If you are using an existing library to do a lot of work for you you could consider running it on a separate thread. Depends on your Python coding skills.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Re: Python plugin waity/sleep challenge
@DnpwwoDnpwwo wrote: ↑Tuesday 19 February 2019 12:10 @neptunus,
If you post your plugin source people can comment but generally you have 2 choices to avoid stalling the Python Framework:but if the 100ms is pretty constant I wouldn't worry about it, its not a significant delay.
- Use the built in connection objects for reading and writing (recommended)
- If you are using an existing library to do a lot of work for you you could consider running it on a separate thread. Depends on your Python coding skills.
I have multiply messaged that need the 100ms delay. To be precise I need to read 86 variables of the slave device. Did means a delay of ~9 seconds for one slave. I need to read 3 of them, 26 seconds significant a delay. For now, there is no point in sharing the code (btw. I would not be a problem to do so at a later moment). Must first have a good idea to solve this properly.
I will study connection objects. Is there a good example of how to use the connection object in which external hardware is read from another python script?
- Dnpwwo
- Posts: 819
- Joined: Sunday 23 March 2014 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Melbourne, Australia
- Contact:
Re: Python plugin wait/sleep challenge
@neptunus,
The framework can communicate with a lot of things, serial ports, TCP/IP, UDP/IP etc so the questions is how do you connect to your Python script not can it be done.
@MichealCervantez,
What are you trying to do with it? (or is this clickbait?)
The framework can communicate with a lot of things, serial ports, TCP/IP, UDP/IP etc so the questions is how do you connect to your Python script not can it be done.
@MichealCervantez,
What are you trying to do with it? (or is this clickbait?)
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Who is online
Users browsing this forum: No registered users and 1 guest