Through Plant Monitor, a tool to obtain data from the PV plant inverters, Plant Monitor will connect directly to your inverter via Modbus TCP.
The tool is designed to allow any inverter enabled for Modbus TCP to be consulted by using its own Modbus register map file.
To store the data consulted in the inverters, you can use TimescaleDB. Finally, a control panel tool is needed to visualize the stored data, such as Grafana
The Inverter must be accessible on the network using TCP.
This script should work on most Inverters that talk Modbus TCP. You can customise your own modbus register file.
Install the required Python libraries for pymodbus
pip install -r requirements.txt
Requires python >= 3.5
Testing requires:
ALTER USER myuser CREATEDB;
)createdb orm_test
.env.example
as .env.testing
and change the contentconf/config.example.py
as conf/config.py
and change the contentconf/config_meteologica.example.yaml
as conf/config_meteologica.yaml
and change the contentA series of mock, modbus sensors are available under testingtools
.
Both client and server modbus can be simulated.
Any change on the schema will modify ORM/schema.sql
whenever
you run the test or explicitly run scripts/update_schema.py
.
Those changes should be transfered to a new yoyo migration.
yoyo new -m "Some description"
Review and provide a forward and backward sql command for the step.
Download or clone this repository to your local workstation. Install the required libraries (see Pre-requisites section above).
Update the config.py with your values, such as the Inverter's IP address, port, inverter model (which corresponds to the modbus register file) and the register addresses Plant Monitor should scan from. Update the .env files with values of your setup (use .env.example as reference to create .env.devel and .env.production).
Setup the database
psql -U postgres -h localhost
CREATE database plants;
\c plants
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
To apply migrations to the database
yoyo apply -d postgres://postgres:mypassword@localhost/plants ORM/yoyo
To write all solar events for a plant run:
$ python -m scripts.sun_events -p Alibaba
you can know the options running
$ python -m scripts.sun_events --help
And to download the solargis modeling irradiation and power from their api you can do
python -m scripts.solargis --help
python -m scripts.solargis 'postgres://user:password@host:port/dbname" <solargis_key> 2022-12-01 2022-12-18 <site_id>
dates are inclusive and the dbapi has to be single quoted if it contains special characters. Data is stored in table satellite_readings.
To run the api locally
~$ uvicorn api_server.plantmonitor_api:api --reload
[fcgi-program:plantmonitor_api]
socket=tcp://localhost:8000
command=/home/plantmonitor/Envs/plantmonitor/bin/uvicorn --fd 0 api_server.plantmonitor_api:api
numprocs=4
process_name=uvicorn-%(process_num)d
environment=PATH="/home/plantmonitor/Envs/plantmonitor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
stdout_logfile=/var/log/supervisor/api_plantmonitor.log
stderr_logfile=/var/log/supervisor/api_plantmonitor_stderr.log
stdout_logfile_maxbytes=0
stderr_logfile_maxbytes=0
autostart=true
autorestart=true
directory=/home/plantmonitor/somenergia/plantmonitor
user=plantmonitor
git fetch
git rebase master
workon plantmonitor
pip install -r requirements.txt ; python ./setup.py develop
yoyo apply
cd queries/; ./publish.sh name_of_view.sql
multitail /var/log/supervisor/plantmonitor_stderr.log /var/log/supervisor/api_plantmonitor*
sudo supervisorctl restart all
python check_db_connection.py
At the moment we are using psycopg2-binary to simplify the installation process. However at some point we will switch and you will need to install libpq-dev via apt. Changing between psycopg2 and psycopg2-binary requires force reinstalling psycopg2. Also be certain that the postgresql installation works with the timescale extension and its postgres configuration.
sudo apt install python3.7-dev
3.7 or the version you're using
sudo apt install python3-apt --reinstall