Skip to content

Commit

Permalink
add fronius and other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
janleenders committed Jan 8, 2023
1 parent 302b0c2 commit 4a963aa
Show file tree
Hide file tree
Showing 11 changed files with 689 additions and 169 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ The design is based on the following requirements:

Product backlog items
---------------------
- Further development of the reports functionality in the webservice.
- Exception handling when no solar datastream is available. Also, make it configurable in the config file
- Try to make it 'running out of the box'
- Add instructions to get the cron service within linux running
- Additional development of the reports functionality in the webservice.
- Create the first version of the control functionality
- Add additional control on the quality of the configuration file input, to enhance the stability of the application.

Installation, general steps
---------------------------
- Create directory within which the application will be installed. f.e. : '/home/pi/myhome'
- Create directory within which the application will be installed. f.e. : '/home/<user>/myhome' .
The <user> can be any user you have defined. The myhome.config file uses user 'pi'. You are free to change this.
- Copy the application files (including the application directory structure) into this directory.
- Edit the parameter values in the config file myhome.config (in the root of the application directory). You are allowed to rename this file. Make sure you use the correct filename when defining the cron jobs.
- Make sure you install the following software on your rasberry pi:
Expand All @@ -47,18 +51,28 @@ Installation, general steps

- Add two lines to the crontab definitions ( sudo crontab -e) :

@reboot python3 /home/pi/myhome/p1r/reader.py /home/pi/myhome/myhome.config >> /home/pi/myhome/log/reader.log
@reboot python3 /home/pi/myhome/ws/site.py /home/pi/myhome/myhome.config >> /home/pi/myhome/log/site.log
@reboot python3 /home/<user>/myhome/py/reader.py /home/<user>/myhome/myhome.config >> /home/<user>/myhome/log/reader.log
@reboot python3 /home/<user>/myhome/py/site.py /home/<user>/myhome/myhome.config >> /home/<user>/myhome/log/site.log

As you can see the parameterfile is passed to the python code using the first argument during startup of the application services.

- See to it that the cron service is configured correctly. This is not always the case! This service can be configured using the following steps for the Raspberry pi:

Log in to your pi
switch to root user using 'sudo bash'
start the cron service by running '/etc/init.d/cron start'
edit file '/etc/rc.local' and add the following line before 'exit 0':
/etc/init.d/cron start
reboot your system: shutdown -r now
After reboot, check whether your cron job is started: 'ps aux | grep cron'.
Also check the log tail of '/var/log/syslog' : cat /var/log/syslog | tail

- Restart your raspberry pi (from commandline: shutdown -r now) and wait a couple of minutes

- Check whether the services are running using the command:
ps aux | grep reader
ps aux | grep site

Make sure that the cron service within Debian running.

- By now you should be able to see data in the database. Go to sqlite3 <database name> and check this:
- select * from p1_channel_detail order by tst desc limit 10;
Expand Down
5 changes: 4 additions & 1 deletion myhome.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ interval_data_details_m3 = [300] # in seconds
interval_data_summary = [3600] # in seconds
database = [db/P1R.db] # relative w.r.t. the folder path
logging = [log/] # relative w.r.t. the folder path
solar_path = [http://192.168.2.4/api/v1/production] # url to get solar data
solar_path = [http://192.168.2.4] # ip address url (without trailing slash) to get solar data
solar_system = [enphase] # solar system version which you are using. Supported systems are:
enphase
fronius
serial_port_name = [/dev/ttyUSB0] # identification of the serial port where the data comes in.

31 changes: 31 additions & 0 deletions py/package_reader/solar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Name: solar.py
# Author: Jan Leenders
# Description:
# Defines the function(s) to get the solar data (only for supported systems). Currently:
# enphase
# fronius
#

import requests
import json

session = requests.Session() # setup a session on behalf of requests to solar system

def get_datapoint(solar_system, solar_request_path ):
return_value= {'actual': 0.0, 'total': 0.0}

try:
if solar_system == 'enphase':
watt_production_data = session.get(solar_request_path + '/api/v1/production').text
return_value['actual'] = json.loads(watt_production_data)["wattsNow"]
return_value['total'] = float(json.loads(watt_production_data)["wattHoursLifetime"]) / 1000 # should be in kWh
if solar_system == 'fronius':
watt_production_data = session.get(solar_request_path +
'/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System&DataCollection=CommonInverterData').text
return_value['actual'] = json.loads(watt_production_data)["Body"]["Data"]["PAC"]
return_value['total'] = float(json.loads(watt_production_data)["Body"]["Data"]["TOTAL_ENERGY"]) / 1000 # should be in kWh

except Exception:
pass

return return_value
Loading

0 comments on commit 4a963aa

Please sign in to comment.