Package: rctclient
rctclient - Python implementation of the RCT Power GmbH "Serial Communication Protocol"This Python module implements the "Serial Communication Protocol" by RCT Power GmbH, used in their line of solar
inverters. Appart from the API, it also includes a registry of object IDs and a command line tool. For development, a
simple simulator is included.This project is not in any way affiliated with or supported by RCT Power GmbH.DocumentationBelow is a quickstart guide, the project documentation is onRead the Docs.InstallingInstall and update usingpip:$ pip install -U rctclientTo install the dependencies required for the CLI tool:$ pip install -U rctclient[cli]ExampleLet's read the current battery state of charge:importsocket,select,sysfromrctclient.frameimportReceiveFrame,make_framefromrctclient.registryimportREGISTRYasRfromrctclient.typesimportCommandfromrctclient.utilsimportdecode_value# open the socket and connect to the remote device:sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)sock.connect(('192.168.0.1',8899))# query information about an object ID (here: battery.soc):object_info=R.get_by_name('battery.soc')# construct a frame that will send a read command for the object ID we want, and send itsend_frame=make_frame(command=Command.READ,id=object_info.object_id)sock.send(send_frame)# loop until we got the entire response frameframe=ReceiveFrame()whileTrue:ready_read,_,_=select.select([sock],[],[],2.0)ifsockinready_read:# receive content of the input bufferbuf=sock.recv(256)# if there is content, let the frame consume itiflen(buf)>0:frame.consume(buf)# if the frame is complete, we're doneifframe.complete():breakelse:# the socket was closed by the device, exitsys.exit(1)# decode the frames payloadvalue=decode_value(object_info.response_data_type,frame.data)# and print the result:print(f'Response value:{value}')Reading values from the command lineThe module installs therctclientcommand (requiresclick). The subcommandread-valuesreads a single value from
the device and returns its output. Here is a call example using the object ID with verbose output:$ rctclient read-value --verbose --host 192.168.0.1 --id 0x959930BF
#413 0x959930BF battery.soc         SOC (State of charge)              0.29985150694847107Without--verbose, the only thing that's printed is the received value. This is demonstrated below, where the--nameparameter is used instead of the--id:$ rctclient read-value --host 192.168.0.1 --name battery.soc
0.2998138964176178This makes it suitable for use with scripting environments where one just needs some values. If--debugis added
before the subcommands name, the log level is set to DEBUG and all log messages are sent tostderr, which allows for
scripts to continue processing the value on stdout, while allowing for observations of the inner workings of the code.Generating the documentationThe documentation is generated using Sphinx, and requires that the software be installed to the local environment (e.g.
via virtualenv). With a local clone of the repository, do the following (activate your virtualenv before if so
desired):$ pip install -e .[docs,cli]
$ cd docs
$ make clean htmlThe documentation is put into thedocs/_build/htmldirectory, simply point your browser to theindex.htmlfile.The documentation is also auto-generated after every commit and can be found athttps://rctclient.readthedocs.io/.