sun2000-rest provides a RESTful interface for accessing the Sun2000 inverter metrics. This project uses the sun2000_modbus-library to connect to the Sun2000 inverter. Currently only read-access to the registers is implemented.
The inverter must be accessible through its internal Wifi access point providing the Modbus TCP interface that the sun2000_modbus-library connects to.
A possible scenario would be to use a Raspberry Pi connecting its Wifi to the internal Sun2000 Wifi access point, connecting the Ethernet-port to the local LAN and starting the application. The REST-API should then be accessible on the local LAN IP.
Furthermore, a Docker image is provided for platforms amd64
and arm64
, including all required
libraries, to simplify the setup.
Given the scenario using a Raspberry Pi as described above:
- Checkout the repository to a location of your choice
- Install requirements via pip:
pip install -r requirements.txt
- Set the following environment variables:
Note that the inverter's IP address is the one from the subnet provided by the inverter's Wifi access point. Usually that is 192.168.200.1.
export FLASK_APP=wsgi.py export INVERTER_HOST=[inverter IP address, usually 192.168.200.1] export INVERTER_PORT=[inverter Modbus TCP port, usually 502, or 6607 on newer firmwares] export ACCEPTED_API_KEYS=[comma separated list of one or more API keys for authorization]
- Start the application:
flask run
, the API should now be accessible onhttp://[LAN IP]:5000
.
Given the scenario using a Raspberry Pi as described above:
Run the Docker container with:
docker run -d --name sun2000-rest \
-p 5000:5000 \
-e INVERTER_HOST=[inverter IP address, usually 192.168.200.1] \
-e INVERTER_PORT=[inverter Modbus TCP port, usually 502, or 6607 on newer firmwares] \
-e ACCEPTED_API_KEYS=[comma separated list of one or more API keys for authorization] \
olivergregorius/sun2000-rest:[latest image tag]
The API should now be accessible on http://[LAN IP]:5000
.
The application can be configured setting the following environment variables:
Environment Variable | Description | Example | Default Value |
---|---|---|---|
INVERTER_HOST | Inverter IP address, usually 192.168.200.1 | 192.168.200.1 | 192.168.200.1 |
INVERTER_PORT | Inverter Modbus TCP port, usually 502, or 6607 on newer firmwares | 6607 | 6607 |
ACCEPTED_API_KEYS | Comma separated list of one or more API keys for authorization | secretApiKey,anotherSecretApiKey | |
LOG_LEVEL | Log level | DEBUG | INFO |
UWSGI_WORKERS | Set amount of workers/processes (Docker only) | 5 | 5 |
The OpenAPI endpoint specification can be found in ./docs/api-specification.yml