Raspberry Pi, Nagios, and a Classic

Started by midnite_andy, August 29, 2013, 10:51:42 PM

Previous topic - Next topic

TomW

#15
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


Do NOT mistake me for any kind of "expert".

( ͡° ͜ʖ ͡°)


24 Trina 310 watt modules, SMA SunnyBoy 7.7 KW Grid Tie inverter.

I thought that they were angels, but much to my surprise, We climbed aboard their starship and headed for the skies

TomW

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
Do NOT mistake me for any kind of "expert".

( ͡° ͜ʖ ͡°)


24 Trina 310 watt modules, SMA SunnyBoy 7.7 KW Grid Tie inverter.

I thought that they were angels, but much to my surprise, We climbed aboard their starship and headed for the skies

RossW

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.
3600W on 6 tracking arrays.
7200W on 2 fixed array.
Midnite Classic 150
Outback Flexmax FM80
16 x LiFePO4 600AH cells
16 x LiFePO4 300AH cells
Selectronics SP-PRO 481 5kW inverter
Fronius 6kW AC coupled inverter
Home-brew 4-cyl propane powered 14kVa genset
2kW wind turbine

windyboy

I'm new here, and also on 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.

zoneblue

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.
6x300W CSUN, ground mount, CL150Lite, 2V/400AhToyo AGM,  Outback VFX3024E, Steca Solarix PL1100
http://www.zoneblue.org/cms/page.php?view=off-grid-solar

midnite_andy

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.

midnite_andy

#21
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.

midnite_andy

#22
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.

TomW

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
Do NOT mistake me for any kind of "expert".

( ͡° ͜ʖ ͡°)


24 Trina 310 watt modules, SMA SunnyBoy 7.7 KW Grid Tie inverter.

I thought that they were angels, but much to my surprise, We climbed aboard their starship and headed for the skies

midnite_andy

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

zoneblue

#25
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))
6x300W CSUN, ground mount, CL150Lite, 2V/400AhToyo AGM,  Outback VFX3024E, Steca Solarix PL1100
http://www.zoneblue.org/cms/page.php?view=off-grid-solar

windyboy

#26
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

windyboy

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. :)

midnite_andy

#28
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.


TomW

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
Do NOT mistake me for any kind of "expert".

( ͡° ͜ʖ ͡°)


24 Trina 310 watt modules, SMA SunnyBoy 7.7 KW Grid Tie inverter.

I thought that they were angels, but much to my surprise, We climbed aboard their starship and headed for the skies