/e3dc-rest

a simple REST API to access a E3DC system

Primary LanguagePythonMIT LicenseMIT

e3dc-rest

This is a simple REST API to access a E3DC system

Getting Started

This script uses a Python library which can be found here: https://github.com/fsantini/python-e3dc and exposes the values as REST API endpoints.

The API uses exposed environment variables to access the E3DC.

Configuring the E3DC correctly

  • ToDo...

Local startup

You need to export the variables so the script can read them

# IP address of your local E3DC system
export E3DC_IP_ADDRESS='192.168.1.99'
# username as used to log into the E3DC web portal
export E3DC_USERNAME='use@domain.com'
# password as used to log into the E3DC web portal
export E3DC_PASSWORD='Passw0rd'
# The E3DC RSCP Password (encryption key), as set on the device under Main Page -> Personalize -> User profile -> RSCP password
export E3DC_KEY='secretkey'
# Password to protect e3dc-rest api
export ADMIN_PASSWORD='admin'

Create a self contained environment

python3 -m venv .venv

then you can go into the new made environment and install the requirements

source .venv/bin/activate
pip3 install -r requirements.txt

Dev Webserver:

cd api
python3 api.py

or use

cd api
gunicorn --bind 0.0.0.0:8080 wsgi:app --access-logfile -

Container/Kubernetes

Prebuild images are pushed to ghcr.io/vchrisb/e3dc-rest with tags latest, sha-xxxxxx and version 0.0.x available. Latest tags can be found here: https://github.com/vchrisb/e3dc-rest/pkgs/container/e3dc-rest

Build

docker build . -t e3dc-rest

Docker

docker run --name e3dc-rest -p 8080:8080 -e E3DC_IP_ADDRESS -e E3DC_USERNAME -e E3DC_PASSWORD -e E3DC_KEY -e ADMIN_PASSWORD="admin" ghcr.io/vchrisb/e3dc-rest:latest

Kubernetes

Create Secret:

kubectl create secret generic e3dc-secret --from-literal=username='user@domain.com' --from-literal=password='password' --from-literal=ip_address='192.168.1.99' --from-literal=key='password' --from-literal=config='{}' --from-literal=admin_password='admin'

Deploy with Ingress Controller:

kubectl apply -f ingress.yml -f service-ingress.yml -f deplyoment.yml

Calling the API

curl http://admin:admin@localhost:8080/api/poll
curl -H "Content-Type: application/json"  -X POST -d '{"powerLimitsUsed": true,"maxChargePower": 1000,"maxDischargePower": 1300,"dischargeStartPower": 65}' http://admin:admin@127.0.0.1:8080/api/power_settings
curl http://admin:admin@localhost:8080/api/power_settings