HotNoob / PythonProtocolGateway

Python Protocol Gateway reads data via Modbus RTU or other protocols and translates the data for MQTT. In the long run, Python Protocol Gateway will become a general purpose protocol gateway to translate between more than just modbus and mqtt. Growatt, EG4, Sigineer, SOK, PACE
Apache License 2.0
4 stars 0 forks source link

Proper way to write to registers #39

Open utdrmac opened 2 months ago

utdrmac commented 2 months ago

What's the correct way to write to a register? I'm not seeing much documentation on this. I just want to write to the registers holding the clock on my inverter to correct the time drift (and probably DST in Nov). I'm thinking this be just a one-shot type script that I can call on a cron job, say every Sunday, to set the clock. I'm not understanding how after I set 'write = true', then where do I specify which regs and what values to write? Thanks.

HotNoob commented 1 month ago

yes, i should "write" some documentation for writing....

it's still a bit a of a work in progress. currently only single register values are writeable. ( 2 bytes )

so, because of the ambiguous nature of modbus, i have a safety feature that requires the holding register to be accurate; i plan on making a per-variable bypass \w manual verification later.

with that enabled, the writing is done via mqtt. when write is enabled, the script subscribes to {base topic}/write/{variable name}

with the eg4_v58 protocol, the holding registry map is i think a bit incomplete. the verification check is done here: https://github.com/HotNoob/PythonProtocolGateway/blob/38f1626c0a3342bcfbcb95c5d16d274a2a0c845c/classes/transports/modbus_base.py#L84

so you can bypass that if it doesn't pass, and at the very minimum you'll have to set the value range for the clock.

oh and the writable column will need to have "W" in it. i left that blank because i was unsure which registers are writable, but i think eg4 just went with the everything in the holding register is writable approach.

HotNoob commented 1 month ago

oh, i did clean up the eg4_v58 holding register a bit, i think the current version can pass the 90% check. https://github.com/HotNoob/PythonProtocolGateway/blob/main/protocols/eg4_v58.holding_registry_map.csv

utdrmac commented 3 days ago

In reading the code when write is enabled, it looks like there is a subscription for each parameter? Is there some way to filter that, so that instead of 100+ subscriptions, there's only a handful? In my case, I just want to routinely update the time as the EG4 drifts by almost a full minute over the course of a week.

HotNoob commented 3 days ago

yes, the variable_screen / mask txt files can just remove the variable all together.

alternatively, editing the protocol csv itself and changing the writable columns to WD or R for readonly. more info on csv format: https://github.com/HotNoob/PythonProtocolGateway/wiki/Creating-and-Editing-Protocols-%E2%80%90-JSON-%E2%80%90-CSV

when editing the csv, it's best to create a custom protocol so it doesnt get overwritten when updating. details on making a custom protocol: https://github.com/HotNoob/PythonProtocolGateway/wiki/Protocols#custom--editing-protocols


note to self. i think in the future, an override csv feature would be a better solution.