Step by Step Setup

Feb 13, 2011 at 6:00 AM
Edited Feb 13, 2011 at 11:23 PM

Hi - First of all - thanks for writting this library.

I am having trouble getting this to work with my GuruPlug Server.

python and python serial are installed.

I have connected my plug to the CMS2000 via a USB to RS232 cable and have cloned the hg repo.

I entered the pv directory(located at root) and after verifying that the tty interface is ttyUSB0 i typed at the command prompt :

sheevaplug-debian:/pv/pv# python pv /dev/ttyUSB0
python: can't open file 'pv': [Errno 2] No such file or directory

So this is pretty obious so I re-read the README and it seems I have to create a file named pv containing the following

import pv
pv.debug()
pv.debug_color()
import serial
port = serial.Serial('/dev/ttyUSB0')
port.open()
from pv import cms
inv = cms.Inverter(port)
    inv.reset()                    # Reset all communications on the serial connection
    sn = inv.discover()            # Look for connected devices
    if sn is None:
        print "Inverter is not connected."
        sys.exit(1)
    ok = inv.register(sn)        # Associates the inverter and assigns default address
    if not ok:
        print "Inverter registration failed."
        sys.exit(1)
            print inv.version()
            param_layout = inv.param_layout()
    parameters = inv.parameters(param_layout)
    for field in parameters:
        print "%-10s: %s" % field

    status_layout = inv.status_layout()
    status = inv.status(status_layout)
    for field in status:
        print "%-10s: %s" % field
            from pv import pvoutput
    api_key = ''
    system_id = 123
    conn = pvoutput.Connection(api_key, system_id)
    connection object:
    import time
    status = dict(status)
    conn.add_status(
            time.strftime('%Y%m%d'),
            time.strftime('%H:%M'),
            energy_exp=status['E-Total'],
            power_exp=status['Pac'],
            cumulative=True)
    print conn.get_status()

 

I then run the script again and get this error.

 

sheevaplug-debian:/pv/pv# python pv /dev/ttyUSB0
  File "pv", line 9
    inv.reset()                                 # Reset all communications on the serial connection
    ^

 

I am confused as to what to do next as I am a little unfamiliar with python.

 

 

NOTE: All the pvoutput details have been input correctly into the pvoutput.pv script.

Any help would be very much appreciated.

Feb 14, 2011 at 10:59 AM

To write your script, you'll need to have the 'pv' directory containing __init__.py in the same directory as your script. So the directory should look something like this:

D:\code>dir
 Volume in drive D is Dev
 Volume Serial Number is 5CF9-FB10

 Directory of D:\code

11/02/2011  10:10 PM    <DIR>          .
11/02/2011  10:10 PM    <DIR>          ..
11/02/2011  10:10 PM                87 myscript.py
11/02/2011  10:10 PM    <DIR>          pv
               1 File(s)             87 bytes
               3 Dir(s)  52,963,958,784 bytes free

D:\code>

 

When you get the Python error while running your script, please also include the error message. There should be another message after that line that says something like "IndentationError: ..." I'm guessing that you have an indentation related error, judging by the position of the cursor indicating the position of the error.

When writing Python code, it's important to have all correct indentation for the code. Python uses indentation to tell it whether it's inside a loop, function etc. rather than using {braces}.

To fix your IndentationError, simply remove the abnormal tabbing at line 9 (and all subsequent lines) and try again.

Feb 17, 2011 at 12:39 AM
Ok - thanks- I will look into this tonight.

On 14/02/2011 9:59 PM, EdmundTse wrote:

From: EdmundTse

To write your script, you'll need to have the 'pv' directory containing __init__.py in the same directory as your script. So the directory should look something like this:

D:\code>dir
Volume in drive D is Dev
Volume Serial Number is 5CF9-FB10

Directory of D:\code

11/02/2011 10:10 PM <DIR> .
11/02/2011 10:10 PM <DIR> ..
11/02/2011 10:10 PM 87 myscript.py
11/02/2011 10:10 PM <DIR> pv
1 File(s) 87 bytes
3 Dir(s) 52,963,958,784 bytes free

D:\code>

When you get the Python error while running your script, please also include the error message. There should be another message after that line that says something like "IndentationError: ..." I'm guessing that you have an indentation related error, judging by the position of the cursor indicating the position of the error.

When writing Python code, it's important to have all correct indentation for the code. Python uses indentation to tell it whether it's inside a loop, function etc. rather than using {braces}.

To fix your IndentationError, simply remove the abnormal tabbing at line 9 (and all subsequent lines) and try again.

Feb 19, 2011 at 12:11 AM
Edited Feb 19, 2011 at 12:15 AM

I first installed pydev into eclipse - fixed my tabbing(there were many errors), cloned the repo and started again fresh.

Below are the errors.

 

sheevaplug-debian:/pv# python myscript.py
Traceback (most recent call last):
File "myscript.py", line 7, in
from pv import cms
File "/pv/pv/cms.py", line 61
except struct.error as e:
^
SyntaxError: invalid syntax

 

Here are the files in my project:

/myscript.py : http://pastebin.com/z4LgTSYn (I removed my details from lines 9 and 30)

/pv/cms.py : http://pastebin.com/SPFhmJp3

/pv/pvoutput.py : http://pastebin.com/qHuHVEPC (I removed my details from lines 32 and 33)

/pv/__init__.py : was not modified

Feb 19, 2011 at 7:42 AM

That syntax error is due to using an older version of Python. The syntax "except struct.error as e:" was introduced since Python 2.6 to resolve common error handling syntax-related errors.

I would suggest upgrading to the latest version of Python (2.7.1), but if you insist on using the older version of Python, simply change the word "as" on that line to a comma ",".

Feb 20, 2011 at 3:51 AM

Ok - so that was a major headache. I had to compile 2.7.1 and there were missing modules galore. All resolved now.

 

So I do #python -V and get python2.7.1. Yah.

pv# python myscript.py
SEND -> aaaa010000000004000159
SEND -> aaaa010000000000000155
RECV <- aaaa0000010000800a30393130424f30373636040d OK
SEND -> aaaa0100000000010c30393130424f3037363600010391
RECV <- aaaa000101000081010601de OK
Traceback (most recent call last):
  File "myscript.py", line 21, in 
    for field in parameters:
NameError: name 'parameters' is not defined

So I start to celebrate and then I cried. So I google a little and find that http://docs.python.org/tutorial/errors.html says that it is not actually a fatal error.

I check my pvoutput.org and the new data was not added.

1. So what is the next step please?

2. Also - will I run this as a cron daily or should it be every minute?

3. Does this send the sum or the difference between checking the CMS2000?

Thanks for the help so far- so close now :-)

Feb 21, 2011 at 11:44 AM

Would you like to share some context around line 21 in your script? It would be easier to tell you what might be missing.

Looking just at the communication between your computer and the inverter, it seems that you're not querying the inverter for its parameter layout, and not querying for its parameters first, before trying to decode the parameters. Please check your steps and try again.

Feb 21, 2011 at 10:12 PM
Edited Feb 22, 2011 at 3:12 AM
EdmundTse wrote:

Would you like to share some context around line 21 in your script? It would be easier to tell you what might be missing.

Looking just at the communication between your computer and the inverter, it seems that you're not querying the inverter for its parameter layout, and not querying for its parameters first, before trying to decode the parameters. Please check your steps and try again.

Whoops- yes ofcourse. Lines 29 and 30 were edited to remove my pvoutput.org details. http://pastebin.com/iktgawUQ

I double checked the readme.txt and it seems that everything wasnt in order.

 

I had nested the lines 18-20 inside the prior for loop via tabbing. So they were failing and due to being exited before being read. :-( (the updated script is there)

Now i receive the following result which has also updated the pvoutput.org site. WONDERFUL

 

python myscript.py
SEND -> aaaa010000000004000159
SEND -> aaaa010000000000000155
RECV <- aaaa0000010000800a30393130424f30373636040d OK
SEND -> aaaa0100000000010c30393130424f3037363600010391
RECV <- aaaa000101000081010601de OK
SEND -> aaaa01000001010300015a
RECV <- aaaa000101000183403120203230303041312e303020202020434d532032303030202020 2050484f454e495854454320202020202030393130424f30373636000000000000333630300dc0 O K
1 2000A1.00 CMS 2000 PHOENIXTEC 0910BO07663600
SEND -> aaaa010000010101000158
RECV <- aaaa000101000181064041444546470375 OK
SEND -> aaaa01000001010400015b
RECV <- aaaa0001010001840c05dc003c080c0a50133d13d304a8 OK
SEND -> aaaa01000001010300015a
RECV <- aaaa000101000183403120203230303041312e303020202020434d532032303030202020 2050484f454e495854454320202020202030393130424f30373636000000000000333630300dc0 O K
1 2000A1.00 CMS 2000 PHOENIXTEC 0910BO07663600
Fac-Max : 50.75
Fac-Min : 49.25
Vac-Min : 206.0
Vac-Max : 264.0
Vpc-start : 150.0
T-start : 60
SEND -> aaaa010000010100000157
RECV <- aaaa00010100018014004041424344454748494a4c78797a7b7c7d7e7f08c4 OK
SEND -> aaaa010000010102000159
RECV <- aaaa0001010001822801080be800050949138c0072ffff0000639f000015930001000000 00000000000000000000000000080e OK
Vpv : 304.8
Vac : 237.7
Error : 0
Zac : 65535
Iac : 0.5
Pac : 114
Fac : 50.04
h-Total : 5523
Mode : 1
Temp-inv : 26.4
E-Total : 2550.3
20110222,08:50,0,114,NaN,NaN,0.075

 

Thank you so much Edmund for your help and this amazing script.  Can you please answer a couple parting questions?

1. Does this script clear the CMS2000 of data? I mean after it submits the data to pvoutput.org is a counter reset to zero? (How does it know how much was generated in the between updates?)

2. How often should i run this script? Every 5 minutes/hour?(I see add status is 5/10 min periods here http://www.pvoutput.org/help.html#api-addoutput and that even though you have a 'add_output def the script only uses add_status...or am i reading it wrong?)

3. In my output i have NaN,NaN on the last line. It is resulting in my pvoutput.org update appearing to have generated no kWh usage. Why is this saying its Not a Number? How can I fix this or is it a non-issue? (id like to fix it). As you can see below the Energy colums and average power are zero....

Uploaded with ImageShack.us

 

Thanks.

Feb 23, 2011 at 9:54 AM

1. pv 0.2 will only query the inverter for information. It does not make any changes to the inverter settings or counters.

2. Run it as often as you would like to get updates. pvoutput.org limits the time resolution to 10 minute intervals. (or is it 5 minutes now?) AddOutput I believe is designed to be used as an end-of-day summary of all statuses generated over the day. When I wrote this library, I really just wanted to plot the instantaneous power as a function of time.

3. Those two NaN's refer to energy and power imported, and are for when you have a way of measuring your power intake as well as output.

4. You'll notice that pvoutput.org doesn't show the average output power (the green line in the graphs). This is because the service is designed to work with other inverters that are able to report a daily total energy generated in Wh. It appears that pvoutput.org cannot calculate total energy based on instantaneous power.

Mar 2, 2011 at 9:40 PM

Edmund - thank-you so much for the detailed reply(sorry for getting back to you so late).

 

1. Ah-makes sense.

2. You are allowed 5 to ten minute increments - pvoutput then averages it to the closest 10minute period.

3. Mmm - interseting. The CMS2000 can't do this I suppose.

4. Yes I only saw the dark green line on other peoples graphs. I understand now.

 

Ok - so I wrote a new script to run nightly that reports the daily output. I am having difficulty with it but it kind of works - I added a weather summary into it that comes from the www.bom.gov.au website(this works fine). Ill try again on the weekend to get it completed.

 

Ill let commit it to this project after I finish it along with my other revisions like logging to a file.(Is that ok?)

Mar 4, 2011 at 9:41 AM

Sure. I think I'll add another section of the repository for applications built around the library, such as having a ready-to-go app for monitoring, and even getting weather info.

Although, I'd really like to have time to make this library an installable (so people don't get confused as to how to use it as is) and then do manual calculation of energy output in order to activate more of pvoutput's features.