Skip to content

Commit

Permalink
Merge pull request #5 from mdrocan/minor_enhancements
Browse files Browse the repository at this point in the history
Minor enhancements
  • Loading branch information
mdrocan authored Sep 9, 2023
2 parents 3845fb7 + a26842c commit e602636
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
megalinter-reports/
.ruff_cache
api.txt
config.json
test_env
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@

## Architecture

By default the script uses the URL defined in a file called 'api.txt'.
By default the script uses a config file 'config.json', a template is [here](config.json.templete).
Currently there are two settings to be defined: URL and maximum capacity.

There's also a possibility to use a example response message in a Docker environment:
- You must edit the Python source and comment/uncomment the necessary lines in the script.
- The Docker setup can be found from [here](web_server).

- The Dockerfile can be found from [here](web_server).
- Example message message [here](web_server/GetPowerFlowRealtimeData.fcgi).
- If you use the Docker environment the URL must be defined like your Docker environment has been
started up. For example: '<http://localhost:8080/GetPowerFlowRealtimeData.fcgi>'.

## Next steps

Expand Down
6 changes: 6 additions & 0 deletions config.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"fronius": {
"url": "http://xxx.xxx.xxx.xxx/solar_api/v1/GetPowerFlowRealtimeData.fcgi",
"max_capacity": "xxxx"
}
}
18 changes: 13 additions & 5 deletions fronius.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""
Importing data from the Fronius device.
"""
import json # pylint: disable=import-error
import requests # pylint: disable=import-error
from requests.exceptions import HTTPError # pylint: disable=import-error
from numerize import numerize # pylint: disable=import-error

with open("api.txt", "r", encoding="utf8") as file:
URL = file.read().rstrip()
with open("config.json", "r", encoding="utf8") as config_file:
config = json.load(config_file)

# URL = "http://localhost:8080/GetPowerFlowRealtimeData.fcgi"
URL = config["fronius"]["url"]
MAX_C = config["fronius"]["max_capacity"]


def check_values():
Expand All @@ -22,8 +24,14 @@ def check_values():

print("Timestamp:", jsondata["Head"]["Timestamp"])

currently = numerize.numerize(jsondata["Body"]["Data"]["Site"]["P_PV"], 2)
print("Currently:", currently, "Wh")
currently = jsondata["Body"]["Data"]["Site"]["P_PV"]
if currently is None:
currently = 0
print("Currently:", currently, "W")
print("From max capacity:", "0%")
else:
percentage = currently / MAX_C * 100
print("From max capacity:", round(percentage, 1), "%")

today = numerize.numerize(jsondata["Body"]["Data"]["Site"]["E_Day"], 2)
print("Today:", today, "Wh")
Expand Down

0 comments on commit e602636

Please sign in to comment.