Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance and potential improvements #1

Open
KastB opened this issue Jan 9, 2025 · 0 comments
Open

Performance and potential improvements #1

KastB opened this issue Jan 9, 2025 · 0 comments

Comments

@KastB
Copy link

KastB commented Jan 9, 2025

Hi,

first of all: thank you for sharing this great project, it is really nice and works pretty well for me.
I noticed some points, which I would like to share, split up to different issues as they are independent from each other.

This issue is about the performance I experienced.
I configured an update rate of 15s, but values only changed every ~45s.

There might be two options to improve this, which could be implemented both:

  1. As far as I understand, Esphome optimizes Modbus requests by grouping multiple consecutive requests to a single one, in order to reduce traffic on the bus. This only works if there are no gaps in the registers we read. We can close gaps by either adding the information in those registers as well or "inflating" the register read request prior to a gap with the "register_count" option. Optimizing Modbus with Esphome
    With this script potential gaps are listed:
import os
import re

def extract_registers_from_file(file_path):
    registers = []
    with open(file_path, 'r') as file:
        for line in file:
            if 'address' in line:
                numbers = re.findall(r'\d+', line)
                registers.extend(numbers)
    return registers

def iterate_through_files(directory):
    all_registers = []
    for root, _, files in os.walk(directory):
        for file in files:
            if file.endswith('.yml') or file.endswith('.yaml'):
                file_path = os.path.join(root, file)
                registers = extract_registers_from_file(file_path)
                all_registers.extend(registers)
    return all_registers

if __name__ == "__main__":
    directory = 'modules'
    registers = iterate_through_files(directory)
    print("Extracted registers:", sorted(registers))
    duplicates = [reg for reg in set(registers) if registers.count(reg) > 1]
    print("Duplicate registers:", sorted(duplicates))
    registers = sorted(set(int(reg) for reg in registers))
    gaps = [(registers[i], registers[i+1]) for i in range(len(registers) - 1) if registers[i+1] != registers[i] + 1]
    print("Gaps between registers:", gaps)
  1. Alternatively or additionally, we could configure a two modbus controllers, one with a significantly higher update rate, and one with a lower one and separate "live data values" from parameters. This is what I did in my fork. Now I can reach an update rate of ~2s for measuring the power values. The downside is, that this somehow contradicts 1) a little bit, if we fragment the requested registers too much.

I'm happy with option 2), I would try to fill the gaps nevertheless as this should improve performance even more, but I'm not sure if we can agree on a target update rate and the values we consider relevant to be live data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant