Skip to content

Commit

Permalink
Docker and Kubernetes support.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronjbrown committed Jan 11, 2022
1 parent 7f8de89 commit 4308643
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 14 deletions.
22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Specific files
Dockerfile
.dockerignore
.gitignore
.DS_Store
.git
.idea
kubernetes/
scripts/Growatt.lua
test/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
build
dist
venv
venv3
*.egg-info/
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3

WORKDIR /opt/PyGrowatt

copy . .
RUN pip install --no-cache-dir -r requirements.txt .

WORKDIR /opt/PyGrowatt/scripts
ENTRYPOINT [ "python" ]
CMD [ "growatt_pvoutput.py", "--config", "/opt/PyGrowatt/scripts/config.ini" ]
62 changes: 48 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,71 @@
# PyGrowatt
PyGrowatt extends [PyModbus](https://github.com/riptideio/pymodbus) to implement the custom modbus protocol used by [Growatt](https://www.ginverter.com/) solar inverters with [ShineWiFi-X](https://www.ginverter.com/Monitoring/10-630.html) modules. PyGrowatt can be used to communicate with a solar inverter, decode energy data, and upload it to services such as [PVOutput](https://pvoutput.org/).
PyGrowatt extends [PyModbus](https://github.com/riptideio/pymodbus) to implement the custom modbus protocol used by [Growatt](https://www.ginverter.com/) solar inverters with [ShineWiFi-X](https://www.ginverter.com/Monitoring/10-630.html) modules. PyGrowatt provides custom ModbusRequest and ModbusResponse objects for use with PyModbus.

PyGrowatt can be used to communicate with a solar inverter, decode energy data, and upload it to services such as [PVOutput](https://pvoutput.org/). An example script is included to start a TCP server listening on port 5279 and wait for an inverter to connect. Once an inverter connects, the server will parse the received energy data and periodically upload the data to PVOutput.

## Installation
### PyGrowatt Python Module
Download the repository and use [pip](https://pip.pypa.io/en/stable/) to install PyGrowatt:
### Download the repository
```bash
git clone https://github.com/aaronjbrown/PyGrowatt.git
cd PyGrowatt
```

### Edit the configuration
```bash
cp scripts/config.ini.example scripts/config.ini
vi scripts/config.ini
```
### Python Module _(optional)_
Use [pip](https://pip.pypa.io/en/stable/) to install PyGrowatt to the local system:
```bash
pip install -r requirements.txt .
```
To install for all users on the system, run pip as root:
```bash
sudo pip install -r requirements.txt .
```
### Growatt Wireshark Dissector:

### Docker Container _(optional)_
Build a [Docker](https://www.docker.com/) container:
```bash
docker build -t pygrowatt .
```
By default, the container runs the example ```growatt_pvoutput.py``` script.

### Kubernetes Deployment _(optional)_
To deploy in a minikube instance:
```bash
# Ensure minikube is installed
brew install minikube

#Start minikube and configure it to use the local Docker environment
minikube start

# Point your shell to minikube's docker-daemon (in each terminal)
eval $(minikube -p minikube docker-env)

# Build the Docker container (as above) in minikube's docker-daemon
docker build -t pygrowatt .

# Apply the kubernetes deployment template
kubectl apply -f kubernetes/pygrowatt-deployment.yaml

# Forward ports from your localhost to your minikube instance
kubectl port-forward --address 0.0.0.0 services/pygrowatt-service 5279:5279
```

### Growatt Wireshark Dissector _(optional)_
Copy the ```Growatt.lua``` file into the [Wireshark Plugins folder](https://www.wireshark.org/docs/wsug_html_chunked/ChPluginFolders.html). For example on MacOS:
```bash
mkdir -p ~/.config/wireshark/plugins
cp PyGrowatt/scripts/Growatt.lua ~/.config/wireshark/plugins
cp scripts/Growatt.lua ~/.config/wireshark/plugins
```

## Usage
PyGrowatt provides custom ModbusRequest and ModbusResponse objects for use with PyModbus.

An example script is included to start a TCP server listening on port 5279 and wait for an inverter to connect. Once an inverter connects, the server will parse the received energy data and periodically upload the data to PVOutput. To use this script, first you will need to create a configuration file:
To use the example PVOutput script you will need to enter your `Apikey` and `SystemId` in the configuration file, then execute the script:
```bash
cd scripts
cp config.ini.example config.ini
vi config.ini
```
You will need to enter your `Apikey` and `SystemId`, then you can execute the script:
```bash
python growatt_wifi.py
python growatt_pvoutput.py --config config.ini
```
Finally, you need to configure the ShineWifi-X module to communicate with the computer running this script. You will also need to configure the computer running this script with a static IP address.

Expand Down
36 changes: 36 additions & 0 deletions kubernetes/pygrowatt-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pygrowatt-deployment
labels:
app: pygrowatt
spec:
replicas: 1
selector:
matchLabels:
app: pygrowatt
template:
metadata:
name: pygrowatt
labels:
app: pygrowatt
spec:
containers:
- name: pygrowatt-container
image: pygrowatt
imagePullPolicy: Never
ports:
- containerPort: 5279
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: pygrowatt-service
spec:
selector:
app: pygrowatt
ports:
- port: 5279
targetPort: 5279
type: LoadBalancer

0 comments on commit 4308643

Please sign in to comment.