A Forum run by Enthusiasts of MidNite Solar

The Open Source software/hardware corner => Raspberry PI => Topic started by: midnite_andy on August 29, 2013, 10:51:42 PM

Title: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on August 29, 2013, 10:51:42 PM
Hi Everyone,
I will be demonstrating my custom monitoring project here. I finally received a Pi here at MidNite's engineering lab and I have some tricks to show off.  I am using a Classic we use for development up here in the engineering lab.

Nagios is the industry standard in IT infrastructure monitoring! I will apply Nagios software which is free and open-source to monitor a Classic installation over the network or internet.
http://www.nagios.org (http://www.nagios.org)

Of course we are working with Rasperry Pi here:
http://www.raspberrypi.org/ (http://www.raspberrypi.org/)
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on August 29, 2013, 10:57:59 PM
I am starting on a fresh Pi with default Raspbian (wheezy) software. Here is how to install Apache and Nagios.

pi@raspberrypi ~ $ sudo apt-get install nagios3

Nagios will ask to install the Apache web server also.  The software will ask for the nagiosadmin password.  After the software is installed, I determine my Raspberry Pi's IP address and then open the default web page on another machine in my LAN network.

pi@raspberrypi ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:73:45:6c 
          inet addr:192.168.1.169  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:64571 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18094 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:46243726 (44.1 MiB)  TX bytes:1516661 (1.4 MiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:102 errors:pi@raspberrypi ~ $ sudo cp ./work/nagios_modcache.cfg /usr/local/modcache0 dropped:0 overruns:0 frame:0
          TX packets:102 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:9852 (9.6 KiB)  TX bytes:9852 (9.6 KiB)

Here are the screenshots of http://192.168.1.169 and http://192.168.1.169/nagios3 (user: nagiosadmin / pass: *****)
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on August 29, 2013, 11:18:26 PM
I am going to dive right into the good stuff before we go back and clean things up.  At MidNite we have a Classic charge controller in our engineering lab.

I am going to use Nagios to monitor this Classic.  In steps:
1. Write Modbus caching program in Python.
2. Install and configure Modbus caching program as a Cron job.
3. Configure Nagios alerts
4. Install and configure Nagios graphs

Let me explain the Modbus caching program.  The Classic allows only one Modbus network connection to be used by monitoring software.  In order to allow multiple programs running on the Pi access to the Modbus register data, my Modbus caching program will connect to the Classic at a regular interval and download a list of desired registers to be stored locally.  When a program wants access to Classic data, the cache file can be used in place of connecting to the Classic.  The cache is updated in a Cron script at a configurable interval.  Any number of Classic charge controllers can be cached, with each one having a different cache file.

This is Python code and will require the pymodbus module.  I am now going to install the modcache program in the folder /usr/local/modcache and get it configured to run as a Cron job on the Pi.

I am going to install modcache files in the directory /usr/local/modcache.  I will copy the files in one at a time to show how they are setup and used.

Install the pymodbus module by following the directions at their web page or install the distribution package:
https://code.google.com/p/pymodbus/ (https://code.google.com/p/pymodbus/)

pi@raspberrypi ~ $ sudo apt-get install python-pymodbus

Now create the directory, copy in the Python files, and make them executable.

pi@raspberrypi ~ $ sudo mkdir /usr/local/modcache

Modcache is the program that does the caching of the registers.
pi@raspberrypi ~ $ sudo cp ./work/modcache.py /usr/local/modcache
pi@raspberrypi ~ $ sudo chmod +x /usr/local/modcache/modcache.py

Readmod is a program that reads the cached registers.
pi@raspberrypi ~ $ sudo cp ./work/readmod.py /usr/local/modcache
pi@raspberrypi ~ $ sudo chmod +x /usr/local/modcache/readmod.py

Now I need to setup the Cron script for Modcache.  In order to make this easy to call with Cron, I have created a Bash script to take care of some details.

File: modcache_engclassic.sh
#!/bin/bash
MCHOST=192.168.1.62
MODCACHEPATH=/usr/local/modcache/modcache.py
CACHEDIR=/usr/local/modcache
$MODCACHEPATH --cachefile $CACHEDIR/$MCHOST.csv --registerfile $CACHEDIR/$MCHOST.reg --ip $MCHOST


This Bash script would be copied with the IP address changed if I wanted to monitor a second (or more) Classic.  The IP address of the Classic here at MidNite's engineering lab is 192.168.1.62.  Just copy that puppy in there.

pi@raspberrypi ~ $ sudo cp ./work/modcache_engclassic.sh /usr/local/modcache/
pi@raspberrypi ~ $ sudo chmod +x /usr/local/modcache/modcache_engclassic.sh

I need a list of registers to grab.  Here is your most basic register list to be extended later:
File: 192.168.1.62.reg
BATT_VOLTS,4114
PV_VOLTS,4115
BATT_WATTS,4118
INFO_FLAGS_L,4129
INFO_FLAGS_H,4130
BATT_TEMP,4131
FET_TEMP,4132
PCB_TEMP,4133


pi@raspberrypi ~ $ sudo cp ~/work/192.168.1.62.reg /usr/local/modcache/

Lets try running modcache_engclassic.sh to see what the cache file looks like.

pi@raspberrypi /usr/local/modcache $ sudo ./modcache_engclassic.sh
pi@raspberrypi /usr/local/modcache $ cat 192.168.1.62.csv
BATT_TEMP,266
BATT_VOLTS,511
BATT_WATTS,0
FET_TEMP,309
INFO_FLAGS_H,12800
INFO_FLAGS_L,12292
PCB_TEMP,372
PV_VOLTS,1578
Status,Success
Time,1377731093.080432


The cache file is called 192.168.1.62.csv and it contains the registers that grabbed including battery temperature and battery volts in tenths of a unit.  The Status entry is “Success” to indicate that modcache.py was able to get data from the Classic.  The Time entry is a timestamp that will allow checking the cache file for age as well as if the data is valid.

Now I install the modcache_engclassic.sh in Cron to do the regular monitoring.

pi@raspberrypi ~ $ sudo vim /etc/crontab

Add the following line with comments to the file /etc/crontab and save:

# Check Modbus devices every 4 minutes
# We set Nagios to check every 5 (that way Nagios stays a little behind the updates)
*/4 *   * * *   root    /usr/local/modcache/modcache_engclassic.sh

Now restart Cron to save the changes:
pi@raspberrypi ~ $ sudo service cron restart

Now you should see that the /usr/local/modcache/192.168.1.62.csv file's timestamp is updated every 4 minutes with new values.  The next task is to setup the Nagios check scripts to check the Modbus registers in the cache file for warnings or faults.  I chose to write these in Bash.

Copy in the new files.

pi@raspberrypi ~ $ sudo cp ./work/check_mc_bit.sh /usr/local/modcache
pi@raspberrypi ~ $ sudo cp ./work/check_mc_perfdata.sh /usr/local/modcache
pi@raspberrypi ~ $ sudo cp ./work/check_mc_scale.sh /usr/local/modcache
pi@raspberrypi ~ $ sudo cp ./work/check_mc.sh /usr/local/modcache
pi@raspberrypi ~ $ sudo cp ./work/nagios_modcache.cfg /usr/local/modcache
pi@raspberrypi ~ $ sudo chmod +x /usr/local/modcache/*.sh

A Nagios check script is a script that verifies that something is working properly and then returns 0 for OK, 1 for Warning, 2 for Critical, and 3 for Unknown.  Our check scripts will check for the presence of faults at the Classic and report those to Nagios.

We also have to define the Nagios command formats which are in the nagios_modcache.cfg file.  In order for Nagios to use this file we have to create a symbolic link to the Nagios directory.

pi@raspberrypi ~ $ sudo ln -s /usr/local/modcache/nagios_modcache.cfg /etc/nagios-plugins/config/modcache.cfg

Finally, we can setup the Classic in the Nagios hosts list and list all of the checks we want to perform.

pi@raspberrypi ~ $ sudo cp ./work/midnite_devices.cfg /usr/local/modcache
pi@raspberrypi ~ $ sudo ln -s /usr/local/modcache/midnite_devices.cfg /etc/nagios3/conf.d/midnite_devices.cfg

Reload the Nagios configuration files.

pi@raspberrypi /etc/nagios3/conf.d $ sudo service nagios3 reload

OK, here is the screenshot, things are not perfect yet.  There is more to be done.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: Westbranch on August 29, 2013, 11:24:24 PM
Looks good Andy, can you make a parallel posting with all the new acronyms.  you started losing me with nagios then Cron and BASH...?


thanks
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on August 30, 2013, 12:41:20 AM
Now to install the nagiosgraph plugin.  Download the latest source files from http://sourceforge.net/projects/nagiosgraph/files/

Install a required package:
pi@raspberrypi ~/work/nagiosgraph/nagiosgraph-1.4.4 $ sudo apt-get install librrds-perl

Unpack the nagiosgraph-1.4.4.tar.gz file in a temporary directory.  Run the install script to check for the required dependencies.

pi@raspberrypi ~/work/nagiosgraph/nagiosgraph-1.4.4 $ ./install.pl --check-prereq
checking required PERL modules
  Carp...1.20
  CGI...3.52
  Data::Dumper...2.130_02
  File::Basename...2.82
  File::Find...1.19
  MIME::Base64...3.13
  POSIX...1.24
  RRDs...1.4007
  Time::HiRes...1.972101
checking optional PERL modules
  GD... ***FAIL***
checking nagios installation
  found nagios at /usr/sbin/nagios3
checking web server installation
  found apache at /usr/sbin/apache2

It looks like we have everything but the optional PERL modules.  So run the nagiosgraph installation script.  The default values should work for all of the settings.  But do select “y” to modify the Nagios and Apache configurations at the end so that we don't have to do that manually.

pi@raspberrypi ~/work/nagiosgraph/nagiosgraph-1.4.4 $ ./install.pl --layout debian

Oops, looks like we need one more program:
pi@raspberrypi ~ $ sudo apt-get install bc

Also, change the update period to 5 minutes at the end of /etc/nagios3/nagios.cfg:
service_perfdata_file_processing_interval=5

Now I can restart Apache:
pi@raspberrypi ~ $ sudo service nagios3 restart
pi@raspberrypi ~ $ sudo service apache2 restart

I have some problems, the plots aren't showing, so I am going to work on the settings to see if I can figure it out.

Change the following lines in /etc/nagios3/nagios.cfg:
check_external_commands=1
process_performance_data=1


Run the following commands to setup the external command processing:
pi@raspberrypi ~ $ sudo service nagios3 stop
pi@raspberrypi ~ $ sudo dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
pi@raspberrypi ~ $ sudo dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3
pi@raspberrypi ~ $ sudo service nagios3 start

Success!  My battery temperature is now showing up in the plots.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on August 30, 2013, 01:10:47 AM
Thanks for the interest Westbranch, I will try to put in some more explanation after I finish the big stuff.
-Andy
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: TomW on August 30, 2013, 08:26:51 AM
Quote from: Westbranch on August 29, 2013, 11:24:24 PM
Looks good Andy, can you make a parallel posting with all the new acronyms.  you started losing me with nagios then Cron and BASH...?


thanks

I am not Andy, nor do I play him on TV..

Been using Linux for a couple decades and Debian and variants for most of that time.  I never used Nagios but I can address a few of the "new acronyms".

CRON is a system in Linux that runs programs at a specified time. Very handy and I use it quite regularly.

bash is a Linux "shell interpreter"  it processes your commands / scripts. There are several but it seems bash is the most common.

Just what I can help with now.

Andy, have you experienced any Classic communication lock outs running Naglios on the PI? I ask because Ross and I are hunting them down here. I stopped using my PI over ethernet to the Classic and am testing our theory that it is either the PI or the PI and the Classic together that gets errors that lock out communications.  Been running Ross' script on an X86 laptop Ubuntu install with no errors for a few days where the PI doing the logging would have been locked out of the Classic and the Local App would have been blocked., also.

Tom
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on August 30, 2013, 12:43:55 PM
TomW,
I just got this up and running yesterday.  I have not seen any unexpected behavior regarding the Classic.  I suspect that the problem is simply that too many connections are being opened with the Classic at one time.  It can be a bit tricky, which is why I created the modcache.py register caching program.  I will keep you updated.

Today I have changed the following line in /etc/nagios3/nagios.cfg:
command_check_interval=15s

Here are some screenshots of the Pi's web page from this morning:
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: TomW on August 30, 2013, 01:04:07 PM
Quote from: midnite_andy on August 30, 2013, 12:43:55 PM
TomW,
I just got this up and running yesterday.  I have not seen any unexpected behavior regarding the Classic.  I suspect that the problem is simply that too many connections are being opened with the Classic at one time.  It can be a bit tricky, which is why I created the modcache.py register caching program.  I will keep you updated.

Andy;

Well I am installing nagio3 and will try running it from the PI and see what develops. If it works OK I can eliminate the PI / Classics as the issue.

Thanks.

Tom
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on August 30, 2013, 01:42:35 PM
Good luck!  I would consider this an advanced level DIY project.  I have included all my files, you will need to change a few things here and there for your system.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: TomW on August 30, 2013, 01:59:02 PM
Quote from: midnite_andy on August 30, 2013, 01:42:35 PM
Good luck!  I would consider this an advanced level DIY project.  I have included all my files, you will need to change a few things here and there for your system.

Andy,

Well, typical of a Debian derived system the non repository application installation failed. Lots of files not found and not anywhere on the system. Too "advanced" for today to test the theory of the issues with ethernet comms. Took forever to run the apt installation process, too

Nice idea but, as you say, not exactly "easy" on my install of wheezy. And it changed where my web directory lives. Dirty trick, that one.

Back to the laptop. :o

Tom
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on August 30, 2013, 04:29:28 PM
A few more changes:

Here is the new text in my/etc/nagios3/conf.d/services_nagios3.cfg file:
# check that web services are running
define service {
        host_name                       localhost
        service_description             HTTP
        check_command                   check_http
        use                             generic-service
        notification_interval           0 ; set > 0 if you want to be renotified
}

# check that ssh services are running
define service {
        host_name                       localhost
        service_description             SSH
        check_command                   check_ssh
        use                             generic-service
        notification_interval           0 ; set > 0 if you want to be renotified
}


Here is my new /etc/nagios3/conf.d/hostgroups_nagios2.cfg file:

# Some generic hostgroup definitions

# A list of your Raspberry Pi servers.
define hostgroup {
        hostgroup_name  pi-servers
        alias           Raspberry Pi Servers
        members         localhost
}



Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: zoneblue on August 31, 2013, 03:09:04 AM
Can you say something about why you chose nagios? Is it something like mango?

Tom, what about using stephenvs python script as a backend for your raspberry test. I was thinking of trying it on the cubie to rule out newmodbus. Pythons not my thing but i figure i could hack it enough to dump the registers betw 4100 and 4300 easy enough. Just not enough hours ni the day.

apt-get install python-pymodbus, then run the python script out of cron.

https://github.com/continuumsecurity/IslandManager/blob/master/scripts/classic.py
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: RossW on August 31, 2013, 06:26:44 AM
Quote from: zoneblue on August 31, 2013, 03:09:04 AM
Tom, what about using stephenvs python script as a backend for your raspberry test. I was thinking of trying it on the cubie to rule out newmodbus.

Tom said to me in IRC 8 hrs ago:

"well, after 4 days and no commerrors I tentatively pronounce your script fine on X86 based hardware"

Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on August 31, 2013, 08:47:08 PM
Hi zoneblue,
I chose Nagios, because it is easily extensible through its plugin interface, supports plotting through nagiosgraph and is free.  I have used Mango in the past and it is a great product that is more directly suited to this kind of monitoring.  We may have to do a Mango posting and get together a Mango script for all of the Classic registers.

Have a look at the script I made called modcache.py and readmod.py.  I attached the files a few postings up in a zip file.  You can see how I do exactly what you are talking about regarding pymodbus and Cron.

Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: TomW on August 31, 2013, 10:47:50 PM
Quote from: midnite_andy on August 31, 2013, 08:47:08 PM

Have a look at the script I made called modcache.py and readmod.py.  I attached the files a few postings up in a zip file.  You can see how I do exactly what you are talking about regarding pymodbus and Cron.

Andy;

Grabbed that .zip file. Not much of a Python user but it worked when adjusted for my Classics addresses.

Once again the difference between "address #" and "Register #" confused me.

The python script references address I guess and the registers.csv file is a comma separated pair of "Value Name", address ?

I got used to calling by register # with Ross' script because that is how the Official documents reference the values so I need to relearn that bit. IE: you call 4114 for Batt_Volts using Ross' script we call 4115 for Batt_Volts. No biggie but might be confusing.

Thanks for the share. Going to see how it runs on the Pi here. Not going to try to get nagios running so any ideas on how to get Python to write to a single, expanding log file?

If this turns out to be Pi related hardware issues I will be very disappointed.  :o If it is Ross' script I figure he will fix it if I ask nicely.  ;D

Tom


Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: TomW on August 31, 2013, 11:15:43 PM
Andy;

modcache.py worked "out of the box" on my Ubuntu 11.10 laptop.

I installed the python-pymodbus package it needed on the Pi.

When I run it on the Pi I get this error:


tomw@pi ~/PYTHON $ ./modcache.py
Traceback (most recent call last):
  File "./modcache.py", line 151, in <module>
    if (int(row[1]) == blockStart+len(blockKeys)):
IndexError: list index out of range


I have zero clue / experience with Python so not sure where to look for the problem?

Any pointers?

Thanks.

Tom
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: RossW on August 31, 2013, 11:35:37 PM
Quote from: TomW on August 31, 2013, 10:47:50 PM
If it is Ross' script I figure he will fix it if I ask nicely.  ;D

If it is, I've no idea how I'll find it - since the same source compiled and run under FreeBSD and your own Linux but running on X86 hardware hasn't locked up yet in the 4 months I've been running it 24/7.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: windyboy on September 01, 2013, 03:36:38 PM
I'm new here, and also on http://OpenEnergyMoniter.org (http://openenergymoniter.org) where I'm waiting for my first arduino/Pi kit for monitering house energy usage. Just wondered if you guys here ad seen it ? And its anything like nagius ?

Anyway just incase you hadn't ;) Not meaning to spam or anything, but thought it might be interesting and related.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: zoneblue on September 01, 2013, 05:04:56 PM
I had previously taken a look at openenergymonitor, the correct address is http://openenergymonitor.org/. Maybe you know more about it and can enlighten me, but i ruled it out, because of:
-rf focus. i want a wired solution
-sensor inputs all seem to geared to AC, whereas most of our stuff is dc

Can you shed any light on those.?

We are pretty close to a rPi standalone solution.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on September 03, 2013, 12:49:46 PM
Here are more screenshots showing the Nagios page with the PV volts and Battery Watts, daily, weekly, monthly, and yearly plots.  Yearly plots are off the screen I guess.  This is after a few days so there is some data now.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on September 03, 2013, 01:24:42 PM
Hi TomW,

You probably need to create a register file.  Here is the help for Modcache.py:

usage: modcache.py [-h] [-c CACHEFILE] [-r REGISTERFILE] [-i IP] [-p PORT]

A utility for caching Modbus TCP holding registers.

optional arguments:
  -h, --help            show this help message and exit
  -c CACHEFILE, --cachefile CACHEFILE
                        Cache path
  -r REGISTERFILE, --registerfile REGISTERFILE
                        Register list path
  -i IP, --ip IP        Modbus device IP address
  -p PORT, --port PORT  Modbus device port


The CACHEFILE is a file that the output is stored in csv format.  This is created by modcache.

The REGISTERFILE is a csv list of names and register numbers.  You create this to tell modcache what registers to grab.
for example:
BATT_VOLTS,4114
PV_VOLTS,4115
BATT_WATTS,4118
INFO_FLAGS_L,4129
INFO_FLAGS_H,4130
BATT_TEMP,4131
FET_TEMP,4132
PCB_TEMP,4133


IP is the Classic IP and PORT is probably 502 which is the default.

Edit:
I think in order to follow the guideline for the difference between a Modbus Address and a Register, I should have called this file the address file.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on September 03, 2013, 01:34:43 PM
Here is the office ruling on the whole Address VS. Register terminology.  Sorry, I probably got it all confused in modcache.py.

Note on addresses vs. registers:
The modbus specification adds one (1) to the “address” sent to the unit in the packet command to access a “register”. This is so that modbus registers start at 1 rather than 0. The main Classic address map starts at register 4101 but the packet itself sends out address 4100.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: TomW on September 03, 2013, 04:23:38 PM
Quote from: midnite_andy on September 03, 2013, 01:24:42 PM
Hi TomW,

You probably need to create a register file.  Here is the help for Modcache.py:

usage: modcache.py [-h] [-c CACHEFILE] [-r REGISTERFILE] [-i IP] [-p PORT]

A utility for caching Modbus TCP holding registers.

optional arguments:
  -h, --help            show this help message and exit
  -c CACHEFILE, --cachefile CACHEFILE
                        Cache path
  -r REGISTERFILE, --registerfile REGISTERFILE
                        Register list path
  -i IP, --ip IP        Modbus device IP address
  -p PORT, --port PORT  Modbus device port



Andy;

It has a register.csv file, even tried calling it with -r register.csv same error.


tomw@pi ~/PYTHON $ ./modcache.py
Traceback (most recent call last):
  File "./modcache.py", line 151, in <module>
    if (int(row[1]) == blockStart+len(blockKeys)):
IndexError: list index out of range
tomw@pi ~/PYTHON $ cat registers.csv
BATT_VOLTS,4114
INFO_FLAGS_L,4129
INFO_FLAGS_H,4130
BATT_TEMP,4131
FET_TEMP,4132
PCB_TEMP,4133



My laptop with Ubuntu has python 2.7.2+

The Pi has python 2.7.3
Thanks for the info.

Tom
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on September 03, 2013, 04:35:42 PM
Then I'm not sure what your problem is.  Here is my output:
pi@raspberrypi /usr/local/modcache $ sudo ./modcache.py -c test.out -r 192.168.1.62.reg -i 192.168.1.62
pi@raspberrypi /usr/local/modcache $ cat 192.168.1.62.reg
BATT_VOLTS,4114
PV_VOLTS,4115
BATT_WATTS,4118
INFO_FLAGS_L,4129
INFO_FLAGS_H,4130
BATT_TEMP,4131
FET_TEMP,4132
PCB_TEMP,4133
pi@raspberrypi /usr/local/modcache $ cat test.out
BATT_TEMP,245
BATT_VOLTS,536
BATT_WATTS,32
FET_TEMP,472
INFO_FLAGS_H,45568
INFO_FLAGS_L,12292
PCB_TEMP,425
PV_VOLTS,1549
Status,Success
Time,1378240376.094436
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: zoneblue on September 04, 2013, 06:55:33 PM
Tom,

I altered stephenvs python script. Maybe try see it it works on the pi, its a single file, returns regsiters from 4101 to 4300. Run it out of cron every minute and parse results to your db. Or were you using newmobus to write periodically to a file? I forget.


#!/usr/bin/python

# USAGE
# apt-get install python-pymodbus
# chmod 0755 readclassic.py
# ./readclassic.py 192.168.0.223
# 4101: 1174
# 4102: 2013
# 4103: 1032
# 4104: 0
# etc

from pymodbus.client.sync import ModbusTcpClient
import sys

HOST= str(sys.argv[1])
client = ModbusTcpClient(HOST)

def connect():
        global client
        connected = 0
        count = 0
        while (not connected):
                resp = client.connect()
                if (resp == False):
                        time.sleep(10)
                else:
                        connected = 1
                count = count + 1

def close():
        global client
        client.close()

#doesnt seem to like reading more than 123 addresses at a time
rq = client.read_holding_registers(4100,100)
for x in range(0,100):
        reg= 4100 + x + 1
        val = rq.registers[x]
        print(str(reg)+": "+str(val))

rq = client.read_holding_registers(4200,100)
for x in range(0,100):
        reg= 4200 + x +1
        val = rq.registers[x]
        print(str(reg)+": "+str(val))
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: windyboy on September 06, 2013, 03:52:37 AM
Quote from: zoneblue on September 01, 2013, 05:04:56 PM
I had previously taken a look at openenergymonitor, the correct address is http://openenergymonitor.org/. Maybe you know more about it and can enlighten me, but i ruled it out, because of:
-rf focus. i want a wired solution
-sensor inputs all seem to geared to AC, whereas most of our stuff is dc

Can you shed any light on those.?

We are pretty close to a rPi standalone solution.

EDIT, to connect the sensors directly to PI or base station is of course also possible and not complicated at all. If you need things simpler, less sensors and no wireless. I'm not trying to convince anyone of anything here, just getting into things myself
Well I'll have to look more closly at rPi solution that is going on here as well. Personally I need the AC and DC and was adapting the sensing side module to measure DC V and A etc but to use the rest of the infrastructure they have. I really like the loging and visualization part they have... Heres an example of one of the dev's I think, and his monitoring of loging/visulasation. Its monitor PV panels/hotwater... and is all configureable, not differcult once you get your head around. But I'll have to look now at rPi and see how thats working :)

Happy to add more etc if it helps, I'm just after a solution for myself :) which has to be open and modifiable by me
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: windyboy on September 06, 2013, 04:15:07 AM
I'm trying to understand how your interfacing with the classic and nagios (Which is seems to me you need to payfor if you want anything but basic functionality and I can't yet find the source code for the core, or even if you want a database back end I was just looking at the products page/table of features, but don't know might be wrong)

anyway where can I find out how the rPi is interfaced to the classic ? Are current/Voltage or all data just coming from the clasic (if so it would be really easy for me I think to also put that same data into the openenergymonitor db etc, also which git account can I find the source ?

I understand if there is no documentation beyound this thread, no problem, I've skimmed it but can read more closely to answer those questions myself if its not documented anywhere yet. :)
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: midnite_andy on September 06, 2013, 11:20:55 AM
All that is required is the Nagios open-source core and free plugins.  Really, Nagios is just one example.  I could have done this with Icinga, or Munin, or a combination.

The rPi is using a Cron script that runs every 4 minutes to call the Classic and gets a list of Modbus registers.  Nagios simply checks the list which is provided as a file that updates every 4 minutes on the rPi.  Any program could use the list and the data.

The Python source files are posted above.

Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: TomW on September 06, 2013, 11:44:42 AM
Quote from: zoneblue on September 04, 2013, 06:55:33 PM
Tom,

I altered stephenvs python script. Maybe try see it it works on the pi, its a single file, returns regsiters from 4101 to 4300. Run it out of cron every minute and parse results to your db. Or were you using newmobus to write periodically to a file? I forget.


blue;

Can you post a link to this? I know I saw it here but cannot seem to find it back.

Thanks.

Tom
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: windyboy on September 06, 2013, 12:09:39 PM
Quote from: midnite_andy on September 06, 2013, 11:20:55 AM
All that is required is the Nagios open-source core and free plugins.  Really, Nagios is just one example.  I could have done this with Icinga, or Munin, or a combination.

The rPi is using a Cron script that runs every 4 minutes to call the Classic and gets a list of Modbus registers.  Nagios simply checks the list which is provided as a file that updates every 4 minutes on the rPi.  Any program could use the list and the data.

The Python source files are posted above.
Thanks Andy

I went back and read the first post properly and it seems very simply and straight forward :) With that csv file its simple for any of the front ends to be used to take in the data. I'm just looking at where I'd do it in openEnergyMonitor code...

I havn't yet got my Midnight clasic, but seeing these kind of things and understanding the charger better is one of the biggest reasons why I'm wanting to get this charger.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: ClassicCrazy on February 08, 2014, 05:10:08 PM
I am trying to get this running on the Raspberry Pi. From the first page of instructions
Lets try running modcache_engclassic.sh to see what the cache file looks like.

pi@raspberrypi /usr/local/modcache $ sudo ./modcache_engclassic.sh
pi@raspberrypi /usr/local/modcache $ cat 192.168.1.62.csv
BATT_TEMP,266
BATT_VOLTS,511
BATT_WATTS,0
FET_TEMP,309
INFO_FLAGS_H,12800
INFO_FLAGS_L,12292
PCB_TEMP,372
PV_VOLTS,1578
Status,Success
Time,1377731093.080432

But when I run it I get this
pi@raspberrypi /usr/local/modcache $  cat 192.168.2.103.csv
BATT_TEMP,0
BATT_VOLTS,0
BATT_WATTS,0
FET_TEMP,0
INFO_FLAGS_H,0
INFO_FLAGS_L,0
PCB_TEMP,0
PV_VOLTS,0
Status,Error
Time,1391896138.290171


In the modcache.py file
PROGRAM_DESCRIPTION = 'A utility for caching Modbus TCP holding registers.'
DEFAULT_PATH = 'cache.csv'
DEFAULT_RPATH = 'registers.csv'
DEFAULT_IP = '192.168.2.103'
DEFAULT_PORT = 502
DEFAULT_ADDRESS = 4100
DEFAULT_COUNT = 1


Do I need to change the default IP to the Classic IP  ( which is what I put in there ) . Not sure what is causing the error reading . I think I had the other Classic default IP address changed in File: modcache_engclassic.sh

I am new to linux and Raspberry Pi and just starting to get an understanding of how to do these things.

Thanks for any help

Larry



Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: TomW on February 08, 2014, 05:31:44 PM
Larry;

I messed with that awhile but abandoned it.

I "think" the registers.csv has to have a list of the registers to retrieve.

I use RossW's application on a Pi myself but that .csv file probably needs some info included in it?

Tom
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: ClassicCrazy on February 08, 2014, 05:40:52 PM
Where do I find RossW's program ? Seems like I saw it talked about but that was before I started getting my feet wet in Linux stuff. 
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: TomW on February 08, 2014, 05:49:12 PM
Quote from: ClassicCrazy on February 08, 2014, 05:40:52 PM
Where do I find RossW's program ? Seems like I saw it talked about but that was before I started getting my feet wet in Linux stuff. 

I  poked him on this so I think he will come in with a link to the newest compiled version. He is busy and I do not have the link for it handy.

Tom
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: RossW on February 08, 2014, 08:08:13 PM
Quote from: TomW on February 08, 2014, 05:49:12 PM
Quote from: ClassicCrazy on February 08, 2014, 05:40:52 PM
Where do I find RossW's program ? Seems like I saw it talked about but that was before I started getting my feet wet in Linux stuff. 

I  poked him on this so I think he will come in with a link to the newest compiled version. He is busy and I do not have the link for it handy.

Yeah, was out on the chainsaw, cleaning up after a tree decided to come down. (heat stress).
(About 5' dia about 60' long. Did a lot of damage to other trees, fences etc on the way down).

http://support.rossw.net/midnite/ hopefully has a binary you can just download and run.

Lets know if not so we can try to sort you out!
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: ClassicCrazy on February 08, 2014, 08:46:44 PM
Quote from: RossW on February 08, 2014, 08:08:13 PM
Quote from: TomW on February 08, 2014, 05:49:12 PM
Quote from: ClassicCrazy on February 08, 2014, 05:40:52 PM


Yeah, was out on the chainsaw, cleaning up after a tree decided to come down. (heat stress).
(About 5' dia about 60' long. Did a lot of damage to other trees, fences etc on the way down).

http://support.rossw.net/midnite/ hopefully has a binary you can just download and run.

Lets know if not so we can try to sort you out!

Okay - I did a wget and have it on the Raspberry Pi now. Do I have to do anything else to make it run ?  I tried looking at it with the Leafpad viewer but just one line of nothing intelligible shows up.
Okay I don't think it downloaded correctly that other way so am using the raspberry pi browser to download it and will see if that works .

Too bad about the trees falling over but at least you must be warmer there than in Wisconsin now !
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: RossW on February 08, 2014, 08:55:20 PM
Quote from: ClassicCrazy on February 08, 2014, 08:46:44 PM
Okay - I did a wget and have it on the Raspberry Pi now. Do I have to do anything else to make it run ?

./newmodbus -p 192.168.1.62    might show you something.

./newmodbus -?      should print some cryptic help.

Quote
Too bad about the trees falling over but at least you must be warmer there than in Wisconsin now ![/color][/size][/font]

39.6C outside now, 40.8C yesterday (a little over 105F). We're expecting a few warm days. The worst part is when it doesn't cool down overnight (stayed over 85F). (With no aircon, it's hard to cool down when you've been outside working)
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: ClassicCrazy on February 08, 2014, 09:07:48 PM
Well it was minus 20 F here last night and that has been common this winter and another inch of snow today . Spring will come sometime .

So I downloaded it again using the browser on Raspberry but same results. When I downloaded it on my windows computer and looked at it with notepad it showed a file.
pi@raspberrypi ~ $ ls -i1
49047 Desktop
36668 libmodbus-3.0.3.tar.gz
268027 libmodbus-3.0.5
33152 libmodbus-3.0.5.tar
36957 libmodbus-3.0.5.tar.gz
36974 linuxsucks
33309 linuxsucks.c
42476 modcache_rev-_08282013.zip
36973 newmodbus-ARM
37085 newmodbus-ARM0
49058 ocr_pi.png
48965 python_games
33312 sunsaver.c
37641 sunsavertest
32604 sunsavertest.c
pi@raspberrypi ~ $ ./newmodbus -?
-bash: ./newmodbus: No such file or directory
pi@raspberrypi ~ $ ./newmodbus -p 192.168.1.62
-bash: ./newmodbus: No such file or directory
pi@raspberrypi ~ $
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: RossW on February 08, 2014, 09:29:41 PM
Quote from: ClassicCrazy on February 08, 2014, 09:07:48 PM
So I downloaded it again using the browser on Raspberry but same results. When I downloaded it on my windows computer and looked at it with notepad it showed a file.

36973 newmodbus-ARM
37085 newmodbus-ARM0

pi@raspberrypi ~ $ ./newmodbus -?
-bash: ./newmodbus: No such file or directory

The file needs to be renamed from "newmodbus-ARM" to "newmodbus", but more concerning is why both your files are different sizes, and neither of them is the same size as the original!

The file should be 27125 bytes long.
The MD5 signature is f4d183a2571a2c1107da40fdf4cd7fec
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: ClassicCrazy on February 08, 2014, 09:41:49 PM
Quote from: RossW on February 08, 2014, 09:29:41 PM
Quote from: ClassicCrazy on February 08, 2014, 09:07:48 PM


The file needs to be renamed from "newmodbus-ARM" to "newmodbus", but more concerning is why both your files are different sizes, and neither of them is the same size as the original!

The file should be 27125 bytes long.
The MD5 signature is f4d183a2571a2c1107da40fdf4cd7fec

Okay success by renaming it ! Always something simple in linux that takes me a long time to figure out.
pi@raspberrypi ~ $ ./newmodbus -p 192.168.2.103
CLASSIC Display Panel 1.0.19, RossW
State Resting because PV Input Voltage lower than Battery V
Firmware 1758
ClassicTime 20:38:40  08/02/2014
    0 Watts out
25.0 Volts (Battery)
  8.7 Volts (PV)
  0.0 Amps (Battery)
  1.0 kWh today (37 amphours)
pi@raspberrypi ~ $
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: ClassicCrazy on February 08, 2014, 09:45:13 PM
Oh - and glad I saw in another post that I had to close Local Status App to get it to work

Thanks for your help Ross - I will see if I can figure anything else out via the help file which also displays now
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: Highflyer on February 14, 2014, 09:30:48 PM
Andy, Tom, Ross, and all:

I am new here.  I am a beta testing a Kid (or two).  I am going to get a PI or two for several functions I want at my remote solar sites.  Does the Kid have the same information available via a data dump?  I understand busses, registers, addresses and programming, or at least I have in the past. ;D

Thanks for any help.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: ClassicCrazy on February 14, 2014, 11:12:48 PM
Brian - my understanding is that the Kid does not have any type of communication or monitoring other than the firmware updates and what the LCD display does.  Though I think I have read somewhere it may somehow be technically possible to get it to spit out some sort of serial output in the future nothing is on the horizon at this point.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: Highflyer on February 15, 2014, 09:22:27 AM
CC,
Thanks for the info.  I still need the PI for the other functions, so it will get worked on and if the KID's data becomes available, that will be even better.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: boB on February 17, 2014, 03:58:10 AM

I am pretty sure that having RS232 available will be handy with the Kid.

Not modbus.  And not sure exactly when it might be useful.

boB
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: 2twisty on April 02, 2016, 10:16:26 AM
Waking this thread from the dead.

Has there been any changes to this? I'd love to see some software that can bridge the communications gap between all the manufacturers. 

My "dream app" is a raspi-based app that can monitor and control (by altering settings) both my classic, my GSCM-Mini Gen sgart module and my outback VFX3648.  There are opportunities to have much better control of the system based on loads and complex rules.

Sadly, I don't have the programming chops (or time) to pull that off.  My programming skills are best used to integrate existing modules. I bet you Midnite could make money on such an integration between the varied comm protocols.
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: schroew on October 11, 2020, 10:09:22 PM
This is cool! Has anyone tried running ELK on a Raspberry PI unit? I am think that would be interesting with the capabilities of Logstash for data manipulation and Kibana for visualization.
W
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: ClassicCrazy on October 11, 2020, 10:36:56 PM
Quote from: schroew on October 11, 2020, 10:09:22 PM
This is cool! Has anyone tried running ELK on a Raspberry PI unit? I am think that would be interesting with the capabilities of Logstash for data manipulation and Kibana for visualization.
W

There is a lot better Raspberry Pi project than this - the one that connects to Classic and makes MQTT Data available to Grahams Classic Monitoring app for android that has great graphics and other info . But once the Classic data is in the Pi as MQTT you can do whatever you want with that in other programs using Node Red or however you want to distribute it.
http://midniteftp.com/forum/index.php?topic=4849.0

Larry
Title: Re: Raspberry Pi, Nagios, and a Classic
Post by: schroew on October 11, 2020, 11:09:34 PM
Thx, I will check that out.