add source
This commit is contained in:
8
source/LICENSE
Normal file
8
source/LICENSE
Normal file
@@ -0,0 +1,8 @@
|
||||
The MIT License (MIT)
|
||||
Copyright © 2022 <copyright Flavius Moldovan>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
50
source/README.md
Normal file
50
source/README.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# solax-x3
|
||||
#### Read in real-time all parameters provided by Solax X3 solar inverter via its Modbus S-485 serial interface.
|
||||
|
||||
<br />
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* Solax X3 inverter
|
||||
* Modbus RS-485 serial adapter/interface
|
||||
* [Modbus cable](https://github.com/mkfam7/solaxx3/blob/main/diagrams/rs485_cable.png)
|
||||
* python version >= 3.8
|
||||
* This python module
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
pip install solaxx3
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
```
|
||||
from solaxx3.rs485 import SolaxX3
|
||||
|
||||
# adjust the serial port and baud rate as necessary
|
||||
s = SolaxX3(port="/dev/ttyUSB0", baudrate=115200)
|
||||
|
||||
if s.connect():
|
||||
s.read_all_registers()
|
||||
|
||||
available_stats = s.list_register_names()
|
||||
for stat in available_stats:
|
||||
print(stat)
|
||||
|
||||
battery_temperature = s.read("temperature_battery")
|
||||
print(f"\n\nBattery temperature: {s.read('temperature_battery')}")
|
||||
|
||||
|
||||
else:
|
||||
print("Cannot connect to the Modbus Server/Slave")
|
||||
exit()
|
||||
|
||||
|
||||
```
|
||||
|
||||
Project Link: [https://github.com/mkfam7/solaxx3](https://github.com/mkfam7/solaxx3)
|
||||
|
||||
|
||||
|
||||
108
source/database/collect_stats.py
Normal file
108
source/database/collect_stats.py
Normal file
@@ -0,0 +1,108 @@
|
||||
from datetime import datetime, timedelta
|
||||
from pymodbus.client import ModbusSerialClient
|
||||
from solaxx3.rs485 import SolaxX3
|
||||
import mysql.connector
|
||||
|
||||
s = SolaxX3(port="/dev/ttyUSB0", baudrate=115200)
|
||||
|
||||
database_ip = "172.17.7.77"
|
||||
|
||||
if s.connect():
|
||||
s.read_all_registers()
|
||||
|
||||
# read the stats from the inverter
|
||||
battery_capacity = s.read("battery_capacity")[0]
|
||||
feed_in_today = s.read("feed_in_energy_today")[0]
|
||||
consumtion_today = s.read("consumption_energy_today")[0]
|
||||
battery_charging = s.read("battery_power_charge1")[0]
|
||||
grid_voltage_r = s.read("grid_voltage_r")[0]
|
||||
grid_voltage_s = s.read("grid_voltage_s")[0]
|
||||
grid_voltage_t = s.read("grid_voltage_t")[0]
|
||||
run_mode = s.read("run_mode")[0]
|
||||
time_count_down = s.read("time_count_down")[0]
|
||||
inverter_ac_power = s.read("grid_power")[0]
|
||||
etoday_togrid = s.read("energy_to_grid_today")[0]
|
||||
solar_energy_today = s.read("solar_energy_today")[0]
|
||||
echarge_today = s.read("echarge_today")[0]
|
||||
energy_from_grid = s.read("energy_from_grid_meter")[0]
|
||||
energy_to_grid = s.read("energy_to_grid_meter")[0]
|
||||
power_to_ev = s.read("power_to_ev")[0]
|
||||
feed_in_power = s.read("feed_in_power")[0]
|
||||
output_energy_charge = s.read("output_energy_charge")[0]
|
||||
output_energy_today = s.read("output_energy_charge_today")[0]
|
||||
input_energy_today = s.read("input_energy_charge_today")[0]
|
||||
power_dc1 = s.read("power_dc1")[0]
|
||||
power_dc2 = s.read("power_dc2")[0]
|
||||
total_power = power_dc1 + power_dc2
|
||||
uploadTime = s.read("rtc_datetime")[0]
|
||||
uploadDate = uploadTime.date()
|
||||
|
||||
timezone_difference_from_utc = 2
|
||||
uploadTime = uploadTime - timedelta(hours=timezone_difference_from_utc, minutes=0)
|
||||
|
||||
# store the stats in the database
|
||||
mydb = mysql.connector.connect(
|
||||
host=database_ip, user="root", passwd="rootroot", database="solax"
|
||||
)
|
||||
mycursor = mydb.cursor()
|
||||
|
||||
try:
|
||||
|
||||
# create the sql statement
|
||||
sql = """REPLACE INTO solax_local (
|
||||
uploadTime,
|
||||
inverter_status,
|
||||
dc_solar_power,
|
||||
grid_voltage_r,
|
||||
grid_voltage_s,
|
||||
grid_voltage_t,
|
||||
battery_capacity,
|
||||
battery_power,
|
||||
feed_in_power,
|
||||
time_count_down,
|
||||
inverter_ac_power,
|
||||
consumeenergy,
|
||||
feedinenergy,
|
||||
power_dc1,
|
||||
power_dc2
|
||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
|
||||
values = (
|
||||
uploadTime,
|
||||
run_mode,
|
||||
total_power,
|
||||
grid_voltage_r,
|
||||
grid_voltage_s,
|
||||
grid_voltage_t,
|
||||
battery_capacity,
|
||||
battery_charging,
|
||||
feed_in_power,
|
||||
time_count_down,
|
||||
inverter_ac_power,
|
||||
energy_from_grid,
|
||||
energy_to_grid,
|
||||
power_dc1,
|
||||
power_dc2,
|
||||
)
|
||||
|
||||
mycursor.execute(sql, values)
|
||||
mydb.commit()
|
||||
|
||||
# update daily values
|
||||
sql = """REPLACE INTO solax_daily (
|
||||
uploadDate,
|
||||
feed_in,
|
||||
total_yield
|
||||
) VALUES (%s, %s, %s)
|
||||
"""
|
||||
values = (uploadDate, feed_in_today, etoday_togrid)
|
||||
mycursor.execute(sql, values)
|
||||
mydb.commit()
|
||||
|
||||
except mysql.connector.Error as error:
|
||||
print("parameterized query failed {}".format(error))
|
||||
|
||||
else:
|
||||
print("Cannot connect to the Modbus Server/Slave")
|
||||
exit()
|
||||
25
source/database/schema.sql
Normal file
25
source/database/schema.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
CREATE TABLE `solax_daily` (
|
||||
`uploadDate` date NOT NULL,
|
||||
`feed_in` float(6,1) DEFAULT NULL,
|
||||
`total_yield` float(6,1) DEFAULT NULL,
|
||||
PRIMARY KEY (`uploadDate`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
CREATE TABLE `solax_local` (
|
||||
`uploadTime` datetime NOT NULL,
|
||||
`inverter_status` tinyint(4) DEFAULT NULL,
|
||||
`dc_solar_power` smallint(6) DEFAULT NULL,
|
||||
`grid_voltage_r` smallint(6) DEFAULT NULL,
|
||||
`grid_voltage_s` smallint(6) DEFAULT NULL,
|
||||
`grid_voltage_t` smallint(6) DEFAULT NULL,
|
||||
`battery_capacity` tinyint(4) DEFAULT NULL,
|
||||
`battery_power` smallint(6) DEFAULT NULL,
|
||||
`feed_in_power` smallint(6) DEFAULT NULL,
|
||||
`time_count_down` smallint(6) DEFAULT NULL,
|
||||
`inverter_ac_power` smallint(6) DEFAULT NULL,
|
||||
`consumeenergy` float(7,1) DEFAULT NULL,
|
||||
`feedinenergy` float(7,1) DEFAULT NULL,
|
||||
`power_dc1` smallint(6) DEFAULT NULL,
|
||||
`power_dc2` smallint(6) DEFAULT NULL,
|
||||
PRIMARY KEY (`uploadTime`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
BIN
source/diagrams/rs485_cable.png
Normal file
BIN
source/diagrams/rs485_cable.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 99 KiB |
19
source/example.py
Normal file
19
source/example.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from solaxx3.rs485 import SolaxX3
|
||||
|
||||
# adjust the serial port and baud rate as necessary
|
||||
s = SolaxX3(port="/dev/ttyUSB0", baudrate=115200)
|
||||
|
||||
if s.connect():
|
||||
s.read_all_registers()
|
||||
|
||||
available_stats = s.list_register_names()
|
||||
for stat in available_stats:
|
||||
print(stat)
|
||||
|
||||
battery_temperature = s.read("temperature_battery")
|
||||
print(f"\n\nBattery temperature: {s.read('temperature_battery')}")
|
||||
|
||||
|
||||
else:
|
||||
print("Cannot connect to the Modbus Server/Slave")
|
||||
exit()
|
||||
2445
source/grafana/solax_dashboard.json
Normal file
2445
source/grafana/solax_dashboard.json
Normal file
File diff suppressed because it is too large
Load Diff
BIN
source/images/solax_dashboard.png
Normal file
BIN
source/images/solax_dashboard.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 254 KiB |
26
source/pyproject.toml
Normal file
26
source/pyproject.toml
Normal file
@@ -0,0 +1,26 @@
|
||||
# pyproject.toml
|
||||
|
||||
[build-system]
|
||||
requires = ["setuptools>=61.0.0", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "solaxx3"
|
||||
version = "0.1.0"
|
||||
description = "Read Solax X3 inverter registers via modbus interface (RS-485)"
|
||||
readme = "README.md"
|
||||
authors = [{ name = "Flavius Moldovan", email = "mkfam@protonmail.com" }]
|
||||
license = { file = "LICENSE" }
|
||||
classifiers = [
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3",
|
||||
]
|
||||
keywords = ["Solax", "solax-x3", "solaxx3", "solar inverter", "RTU", "MODBUS"]
|
||||
dependencies = [
|
||||
"pymodbus[serial] >= 3.0.0",
|
||||
]
|
||||
requires-python = ">=3.8"
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://github.com/mkfam7/solaxx3"
|
||||
3
source/setup.py
Normal file
3
source/setup.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup()
|
||||
Reference in New Issue
Block a user