Hello!
So, I've been working on a relatively large project that includes multiple Midnite Classic 200s. I have them all hooked up with Ethernet, and while the local app is neat, it doesn't quite do what I want. mymidnite.com is pretty cool, but is low resolution (10 minute polling?) so, I wanted something a bit better.
I couldn't find any really good software for this, so, decided to just write something from scratch. I'm running it on a Debian Linux machine with a progreSQL database with 5 second polling of all relevant variables.
I've been testing it for a few days using a few of my Classics with good results, so, I released it open source under GPLv3. It's not my best work, but not bad for a couple of days of off-and-on coding.
The source code can be found here: https://github.com/wizkid057/midnitelogger
Hopefully someone else finds it useful as well. :)
Here is the README text:
midnitelogger v0.3
I wrote this program to help me log data from multiple Midnite
Classic charge controllers over their ethernet connections
using the built in modbus TCP port.
Some notes:
I've only tested this on the Classic 200. I've not tried any
other variations (because I don't own them), including the "Lite"
versions.
I've tested this with 17 Classics @ 5 second polling intervals.
The software tries to be smart about connectivity and ignores
Classics that it can't communicate with while continuing to
poll data from the others.
I chose postgres for databasing because it seems to work well
with huge numeric data sets such as this which would permit
a reasonable machine to log at ~5 second intervals for years
without much effort.
A schema output from my database is included.
This program does not write to any registers. It only reads a
couple small blocks of them to get all of the data that is
meaningful for logging.
Hopefully someone else finds this useful.
I am not affiliated with Midnite Solar.
I've only tested and compiled this on Debian Wheezy x64, but I
don't see why it wouldn't work elsewhere.
Pull requests welcome. (Please use tabs for indentation!)
It's not my prettiest code, and likely has bugs, but it seems
to work for me in testing.
----
midnitelogger v0.3 - (C) 2015 Jason Hughes (wk_fs@skie.net)
Usage: ./midnitelogger [-dboL] [--dbname=DB_NAME] [--dbuser=X] [--dbpass=X|--dbpassfile=X] [--dbhost=X] [--C=host [--C=host]...]
-d debugging output (silent otherwise)
-b fork into background after successful launch
-o output read data to console (default is csv output)
-T print csv header as first output line (for use with -o)
-H human readable local output (for use with -o, not compatible with -H)
-N do not load charge controller list from database (requires -C)
-R do not write data to database
-L local usage only, no database. (same as -R -L)
requires at least one ip/port argument (-C)
goes well with -o. db* arguments ignored
-C host IP or hostname of Midnite Classic (for use with -L), can do multiple
-i seconds polling interval in seconds (default: 5)
-O one shot (exit after first data output)
-P port port to use for modbus TCP connection (default: 502)
^ Applies to all connections (local or DB fetched)
-F temperatures in fahrenheit (only works with -H, db always in C)
--dbname=X postgres database name (-n)
--dbuser=X postgres username (-u)
--dbhost=X postgres database host/ip (default: localhost) (-h)
--dbpass=X postgres password for dbuser (-p)
--dbpassfile=X file containing password for dbuser (-f)
The program will attempt to connect to all hosts specified on the command
line or in the database. If not using -O it will periodially attempt to
reconnect to specified hosts it doesn't have a working connection to.
The program ignores valid hostnames/ips that it can not connect to.
* THE AUTHOR OF THIS SOFTWARE IS NOT AFFILIATED WITH MIDNITE SOLAR *
* USE OF THIS SOFTWARE IS AT YOUR OWN RISK. THE AUTHOR ASSUMES NO *
* RESPONSIBILITY FOR ANYTHING THAT OCCURS THAT IS UNDESIRED. *
/----------------------------------------------------------------------\
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program. If not, see www.gnu.org/licenses/ |
\----------------------------------------------------------------------/
---
Sample charge_controler_list insert:
insert into charge_controller_list (name, smallname, ip, mac, serial, deviceid) VALUES ('Midnite Classic 200 A', 'Roof', '192.168.1.101', '60:1D:0F:00:00:00', 12345, 'FFFF FFFF');
Currently most of the fields are not used by this software (and are retrievable using the IP) so, only for some future front end usage.
Sorry, I didn't make any binaries... kind of goes against the whole open source thing, IMO. Should be simple to compile. just "make". Everything it uses is pretty standard. Just need libpq installed (postgres C library).
Sample human readable output:
192.168.1.102 (2) @ 1430401481:
--- Battery: 43.6 V @ 40.1 A
--- PV: 137.0 V @ 13.4 A (VoC: 167.2)
--- PV Power: 1752 W (1.2 kWh / 29 Ah today)
--- Temps: 123.6 F (PCB) / 124.2 F (FET) / 11741.2 F (EXT)
(external sensor not actually plugged in...)
or CSV output:
local_id,host,unixtime,battery_volts,pv_volts,battery_volts_raw,pv_volts_raw,battery_amps,pv_amps,pv_voc,watts,kWh_today,Ah_today,ext_temp,int_fet_temp,int_pcb_temp,life_kWh,life_Ah,float_seconds_today,combochargestate
2,'192.168.1.102',1430429271,43.4,133.1,43.6,133.6,2.0,1.2,156.0,87,10.3,237,6505.1,45.1,50.6,201.6,4587,0,1028
Added a bunch of options so it wasn't tied to my use case.
Note to mods: If I've posted this in the wrong section, please let me know!
Enjoy! :)
I've been working on a front end for the data collected, but I'm terrible at front ends. So, I probably won't release anything along those lines.
In any case, here is a shot of some of the output from data collected with midnitelogger.
057;
Thanks for posting this.
This seems as good a spot as any to put it.
I just compiled it on my CubieTruck with Debian Jessie / Sid.
Had to install postgresql and libpq-dev on the Jessie / Sid image I have installed on it.
Haven't really tried it yet but it compiled and made a binary that runs but I never see any data. Probably not understanding the options to get the console output to test it out.
Once again, thanks for the post.
Tom
./midnitelogger -C ip_here -oLH
That should do human readable output from the IP specified. Use -P port for a nonstandard port.
Quote from: wk057 on April 30, 2015, 06:10:25 PM
./midnitelogger -C ip_here -oLH
That should do human readable output from the IP specified. Use -P port for a nonstandard port.
I figured it out once I quit multitasking and actually read your README. ;D
Sorry to mislead.
Tom
Quote from: TomW on April 30, 2015, 06:15:42 PM
Quote from: wk057 on April 30, 2015, 06:10:25 PM
./midnitelogger -C ip_here -oLH
That should do human readable output from the IP specified. Use -P port for a nonstandard port.
I figured it out once I quit multitasking and actually read your README. ;D
Sorry to mislead.
Tom
No problem! Hope you find it useful. :)
wk057, Out-freaking-standing. That is an excellent tool. I (unofficially) thank you for releasing it GPL 3 as well!
WOW! Gonna have to check this out. You might have just made a project that I was considering a WHOLE LOT SIMPLER!
I've been thinking of writing code to run on a RasPi to monitor a Classic (and an Outback FX via serial) so that I can perform different actions based on rules.
By incorporating this code, I may be able to get this off the ground. I was dreading learning how to communicate over ModBus. But this could give me what I want. I've got a GSCM-Mini that can start my generator when the Classic's AUX1 goes hot. It monitors SOC to keep the batteries from dropping too low. I'd like to be able to program a little more intelligence into that, so that the generator can be exercised periodically, and also to monitor generator run hours and send alerts for generator maintenance, etc.
Of course, since your code would be at the center of what I was doing, I would likewise release the code as GPL.
Now, just to find the modules I need to monitor the serial connection on my MATE...
Also, since the RasPi has multiple GPIO, people could use the data from the Classic to have MULTIPLE Aux outputs for diversion loads, etc.
Gonna have to look at this...
when I get time. :( too busy with the physical aspects of living off grid right now -- like building the addition on my house.
I know this is an old thread but I wanted to say thanks to wk057 for this code. I have it running on a FreeBSD system, logging data from a Classic 200. I removed the Postgres parts of the code because I don't have Postgres installed and it compiled no problem.
Regarding the "ComboChargeState" field: this looks like a field made up of multiple flags or values and I'm wondering if anyone knows what each bit means.
You should probably check out the following:
https://github.com/ClassicDIY
It is a whole bunch of projects, but the core is the ClassicMQTT which interfaces to the Classic and posts the data onto an MQTT.