MorningStar Logging

From The Alternative Power Network
Revision as of 19:52, 11 September 2021 by Chewie (talk | contribs) (add steps to get Grafana graphs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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:

Screenshot showing Grafana Datasources menu and configured SQLite database

Create a dashboard, and add a new widget:

Example graph showing array output

After adding all the sections you want, you can get something looking like this:

Grafana-TSMPPT.png

Feel free to contact Chewie with questions or sugestions