Difference between revisions of "MorningStar Logging"
Jump to navigation
Jump to search
(Recording and graphing MorningStar Charge Controllers) |
m (add steps to get Grafana graphs) |
||
Line 26: | Line 26: | ||
);</nowiki> | );</nowiki> | ||
* Install [https://github.com/dodo5522/tsmppt60_driver/ this guy's python module] | * Install [https://github.com/dodo5522/tsmppt60_driver/ this guy's python module] | ||
− | * Install [https://grafana.com/ Grafana] | + | * Install [https://grafana.com/ Grafana], and the SQLite Data Source plugin |
* create TSMPPT.py to use the python module to get the results (where the x's are the IP address): | * create TSMPPT.py to use the python module to get the results (where the x's are the IP address): | ||
<nowiki> | <nowiki> | ||
Line 86: | Line 86: | ||
* Use Grafana to create a dashboard and then graph the values you want: | * Use Grafana to create a dashboard and then graph the values you want: | ||
+ | Add the datasource: | ||
+ | [[File:Grafana-DataSources.png|thumb|600px|center|Screenshot showing Grafana Datasources menu and configured SQLite database]] | ||
+ | Create a dashboard, and add a new widget: | ||
+ | [[File:Grafana-TSMPPT-examplegraph.png|thumb|600px|center|Example graph showing array output]] | ||
+ | After adding all the sections you want, you can get something looking like this: | ||
[[File:Grafana-TSMPPT.png|thumb|600px|center]] | [[File:Grafana-TSMPPT.png|thumb|600px|center]] | ||
Feel free to contact [[User:Chewie|Chewie]] with questions or sugestions | Feel free to contact [[User:Chewie|Chewie]] with questions or sugestions |
Latest revision as of 20:52, 11 September 2021
The larger MorningStar Charge Controllers allow logging via MODBUS and MODBUS/tcp to their windows-based GUI. This is ok, but doesn't save it in a particularly cross-platform format. There is also a hardware device to allow SNMP polling, but this adds >£100 to the installation. Using my TSMPPT 60, this guy's python module, cron and Grafana, I was able to reliably log data to an SQLite DB and make some nice shiny graphs.
There will be more efficient ways to do the following, but this works and is stable.
- Create your DB. I am using 1 table per array to keep things separate, but you might want to add a field for array name if you want all controllers to be logged in the same table. In SQLite, paste the following:
CREATE TABLE 'Array1' ( 'time' text PRIMARY key, 'BatteryVoltage' REAL, 'TargetVoltage' REAL, 'HeatSinkTemp' int, 'BatteryTemp' int, 'LEDState' int, 'ChargeState' int, 'KWHours' int, 'AmpHours' REAL, 'ChargeCurrent' REAL, 'OutputPower' REAL, 'ArrayVoltage' REAL, 'ArrayCurrent' REAL, 'SweepVoc' REAL, 'SweepPmax' REAL );
- Install this guy's python module
- Install Grafana, and the SQLite Data Source plugin
- create TSMPPT.py to use the python module to get the results (where the x's are the IP address):
#!/usr/bin/python3 import tsmppt60_driver as ts import json print(json.dumps(ts.SystemStatus("xxx.xxx.xxx.xxx").get(False)))
- Use something like the following script to query the values returned by the above and then add it to the database created earlier. Note that it uses a temporary file (but can be called anything and put anywhere you like that's writeable)
#!/bin/bash cd /home/xxxxxxx/bin polldate=( $(date --iso-8601=seconds)) db="array.db" table="Array1" ./TSMPPT.py | jq > TSMPPT.json BatteryVoltage=( $(cat TSMPPT.json | jq '."Battery Voltage".value')) TargetVoltage=( $(cat TSMPPT.json | jq '."Target Voltage".value')) HeatSinkTemp=( $(cat TSMPPT.json | jq '."Heat Sink Temperature".value')) BatteryTemp=( $(cat TSMPPT.json | jq '."Battery Temperature".value')) LEDState=( $(cat TSMPPT.json | jq '."LED State".value')) ChargeState=( $(cat TSMPPT.json | jq '."Charge State".value')) KWHours=( $(cat TSMPPT.json | jq '."Kilowatt Hours".value')) AmpHours=( $(cat TSMPPT.json | jq '."Amp Hours".value')) ChargeCurrent=( $(cat TSMPPT.json | jq '."Charge Current".value')) OutputPower=( $(cat TSMPPT.json | jq '."Output Power".value')) ArrayVoltage=( $(cat TSMPPT.json | jq '."Array Voltage".value')) ArrayCurrent=( $(cat TSMPPT.json | jq '."Array Current".value')) SweepVoc=( $(cat TSMPPT.json | jq '."Sweep Voc".value')) SweepPmax=( $(cat TSMPPT.json | jq '."Sweep Pmax".value')) echo $polldate echo BatteryVoltage: $BatteryVoltage echo TargetVoltage: $TargetVoltage echo HeatSinkTemp: $HeatSinkTemp echo BatteryTemp: $BatteryTemp echo LEDState: $LEDState echo ChargeState: $ChargeState echo KWHours: $KWHours echo AmpHours: $AmpHours echo ChargeCurrent: $ChargeCurrent if [ "$ChargeCurrent" = "-0" ] then ChargeCurrent=0 echo ChargeCurrent: $ChargeCurrent fi echo OutputPower: $OutputPower echo ArrayVoltage: $ArrayVoltage echo ArrayCurrent: $ArrayCurrent echo SweepVoc: $SweepVoc echo SweepPmax: $SweepPmax sqlite3 array.db "INSERT INTO $table(time, BatteryVoltage, TargetVoltage, HeatSinkTemp, BatteryTemp, LEDState, ChargeState, KWHours, AmpHours, ChargeCurrent, OutputPower, ArrayVoltage, ArrayCurrent, SweepVoc, SweepPmax) VALUES ('$polldate', $BatteryVoltage, $TargetVoltage, $HeatSinkTemp, $BatteryTemp, $LEDState, $ChargeState, $KWHours, $AmpHours, $ChargeCurrent, $OutputPower, $ArrayVoltage, $ArrayCurrent, $SweepVoc, $SweepPmax);"
- Schedule it in a user cron. I run it every minute:
*/1 * * * * ~/bin/TSMPPT2sqlite > ~/bin/TSMPPT2sqlite.log
- Use Grafana to create a dashboard and then graph the values you want:
Add the datasource:
Create a dashboard, and add a new widget:
After adding all the sections you want, you can get something looking like this:
Feel free to contact Chewie with questions or sugestions