Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

I recently figured out how to communicate from a Linux or Mac OS X computer to a SunSaver MPPT over MODBUS using a Meterbus to Serial Converter (MSC).

I posted the basics for doing this on a wordpress blog: http://westyd1982.wordpress.com/
«134

Comments

  • lamplight
    lamplight Solar Expert Posts: 368 ✭✭✭✭✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    very cool thanks for sharing it with everyone!! (wish i had one to make use of :)
  • notsobright
    notsobright Solar Expert Posts: 247 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    thats awsome! Ive only just started playing arround with linux and an old WRT54G in hopes of being able to do something similiar to what you have someday.

    I have the Morning Star Sun Saver Duo controller so I saved your link info and will be trying it out first chance I get. Thanks!

    nice work, thanks for posting.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    I just posted a complete example of how to read all of the SunSaver MPPT's Read Input Registers via a MODBUS connection.

    See http://westyd1982.wordpress.com/
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    I've now been successful in using a MODBUS connection to both read from and write to a Morningstar SunSaver MPPT and a Morningstar SureSine-300. Access to these devices is a great way to make a web-based system monitor.

    I've posted examples that read and process all of the RAM, EEPROM, and Log Registers on the SunSaver MPPT and print out the results. I also posted an example that reads and processes all of the RAM and EEPROM Log Registers on the SureSine-300 and prints out the results.

    See http://westyd1982.wordpress.com/
  • notsobright
    notsobright Solar Expert Posts: 247 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300
    westyd1982 wrote: »
    I've now been successful in using a MODBUS connection to both read from and write to a Morningstar SunSaver MPPT and a Morningstar SureSine-300. Access to these devices is a great way to make a web-based system monitor.

    I've posted examples that read and process all of the RAM, EEPROM, and Log Registers on the SunSaver MPPT and print out the results. I also posted an example that reads and processes all of the RAM and EEPROM Log Registers on the SureSine-300 and prints out the results.

    See http://westyd1982.wordpress.com/

    I cant belive this topic didnt get more attention.. Im looking forward to experimenting with your program asap for a web-based system monitor too but now that you have forged the way the possibilities with using morningstar equipment has now been greatly expanded!


    Thanks Again this is fantastic!
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    If anyone is using this open source software, this past weekend, I updated the example and all the code for the SunSaver MPPT and SureSine-300 to work with the latest version of libmodbus (3.0.2). It looks like libmodbus will be a supported package that can be easily installed in the Debian-based Linux distributions in the upcoming version later this year.
  • unyalli
    unyalli Solar Expert Posts: 121 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    Hello westyd, I'm having trouble compiling on Ubuntu 12.04 LTS. I installed libmodbus5 and linmodbus-dev. modbus.h has an include for modbus-rtu.h and modbus-rtu.h has modbus_new_rtu in it but....

    root@jjsolar:~/sunsaver# cc `pkg-config --cflags --libs libmodbus` sunsaver.c -o sunsaver
    /tmp/ccGlFOxA.o: In function `main':
    sunsaver.c:(.text+0x34): undefined reference to `modbus_new_rtu'
    sunsaver.c:(.text+0x8e): undefined reference to `modbus_set_slave'
    sunsaver.c:(.text+0x9d): undefined reference to `modbus_connect'
    sunsaver.c:(.text+0xb1): undefined reference to `modbus_strerror'
    sunsaver.c:(.text+0xdb): undefined reference to `modbus_free'
    sunsaver.c:(.text+0x10c): undefined reference to `modbus_read_registers'
    sunsaver.c:(.text+0x12c): undefined reference to `modbus_strerror'
    sunsaver.c:(.text+0x160): undefined reference to `modbus_close'
    sunsaver.c:(.text+0x16f): undefined reference to `modbus_free'
    collect2: ld returned 1 exit status

    I get this. Any chance you have a bit of time to look at this? If not do you have an idea where I can ask about this?

    Thanks for this code even if I don't get it working.

  • BB.
    BB. Super Moderators, Administrators Posts: 33,431 admin
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    Westy has not been on the forum since December of 2012--You might try sending him a PM--Or one of us moderators can send an email if you don't get a reply.

    -Bill
    Near San Francisco California: 3.5kWatt Grid Tied Solar power system+small backup genset
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    I think you have a library set up issue. The errors you are getting are because the compiler isn't finding the libmodbus library. If you haven't already, I think you need to install the pkg-config utility to have the complier link to the library. As an alternative, you might also try cc sunsaver.c -o sunsaver -lmodbus.
    unyalli wrote: »
    Hello westyd, I'm having trouble compiling on Ubuntu 12.04 LTS. I installed libmodbus5 and linmodbus-dev. modbus.h has an include for modbus-rtu.h and modbus-rtu.h has modbus_new_rtu in it but....

    root@jjsolar:~/sunsaver# cc `pkg-config --cflags --libs libmodbus` sunsaver.c -o sunsaver
    /tmp/ccGlFOxA.o: In function `main':
    sunsaver.c:(.text+0x34): undefined reference to `modbus_new_rtu'
    sunsaver.c:(.text+0x8e): undefined reference to `modbus_set_slave'
    sunsaver.c:(.text+0x9d): undefined reference to `modbus_connect'
    sunsaver.c:(.text+0xb1): undefined reference to `modbus_strerror'
    sunsaver.c:(.text+0xdb): undefined reference to `modbus_free'
    sunsaver.c:(.text+0x10c): undefined reference to `modbus_read_registers'
    sunsaver.c:(.text+0x12c): undefined reference to `modbus_strerror'
    sunsaver.c:(.text+0x160): undefined reference to `modbus_close'
    sunsaver.c:(.text+0x16f): undefined reference to `modbus_free'
    collect2: ld returned 1 exit status

    I get this. Any chance you have a bit of time to look at this? If not do you have an idea where I can ask about this?

    Thanks for this code even if I don't get it working.

  • unyalli
    unyalli Solar Expert Posts: 121 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    Thanks Westyd, I have your code compiling on my Raspberry PI now.

    I'm using a Raspy Juice daughter board for up conversion of the 3.3v RS232 via MAX3232 chip. I'm getting an almost immediate connection timed out message. Everyone I've found using your code is using an USB to Serial converter. Does libmodbus need more than TX/RX data and ground? Does it need DTR/DSR or RTS/CTS?
  • waynefromnscanada
    waynefromnscanada Solar Expert Posts: 3,009 ✭✭✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300
    I cant belive this topic didnt get more attention.. Im looking forward to experimenting with your program asap for a web-based system monitor too but now that you have forged the way the possibilities with using morningstar equipment has now been greatly expanded!
    Thanks Again this is fantastic!

    I would love to use it, unfortunately living out here in the sticks I wasn't able to get the proper signal voltage level conversion module or connector cable with it built in, so finally gave up trying. The program would open up OK on the computer and it looked as if it were about to work, but in the end, no communication was possible with the controller. :cry:
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    A number of people have requested that I post the code I use to create the web-based monitoring system for my SunSaver MPPTs and SureSine-300. I posted it only as an example at: http://westyd1982.wordpress.com/.

    In the past, I've been reluctant to post it, because it is not user friendly - it has hard-coded file paths spread throughout (I tried to note these with comments). To make any use of it, you need to be able to program in C, be able to configure your web server software, be able to work with cron files, and be able to do basic Linux/Unix administration. It is just an example of what you can do if you can program and want to get data from your MODBUS devices and display them on a web page.

    You can see my web site in action at: http://rosebud.homedns.org/voltmeter.html

    - Tom
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300
    unyalli wrote: »
    Thanks Westyd, I have your code compiling on my Raspberry PI now.

    I'm using a Raspy Juice daughter board for up conversion of the 3.3v RS232 via MAX3232 chip. I'm getting an almost immediate connection timed out message. Everyone I've found using your code is using an USB to Serial converter. Does libmodbus need more than TX/RX data and ground? Does it need DTR/DSR or RTS/CTS?

    I think your problem is probably a hardware interface problem with the Morningstar MSC. It provides isolation from the MeterBus network, so it needs power from both sides. The MeterBus side through the RJ-11 cable and the serial port side from the signal lines - DTR (pin 4) & DTS (pin 7). I use a USB to Serial cable.

    The sheet that came with my MSC has notes at the bottom under the serial port diagram that say:

    1. RS-232 GND is NOT the same ground as RJ-11! The MSC is fully opto-isolated on all pins.
    2. + power must be asserted on DTR and/or RTS pins
    3. - power must be asserted on RTS and/or RX pins
  • inetdog
    inetdog Solar Expert Posts: 3,123 ✭✭✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300
    westyd1982 wrote: »
    1. RS-232 GND is NOT the same ground as RJ-11! The MSC is fully opto-isolated on all pins.
    2. + power must be asserted on DTR and/or RTS pins
    3. - power must be asserted on RTS and/or RX pins
    Any indication of what voltage levels are looked for? RS-232 itself supports a wide range of voltages, from +/- 3 up to +/- 15 volts. And presumably they need both + with respect to RS-232 ground and - with respect to RS-232 ground to be able to power the output RS-232 signal(s).
    SMA SB 3000, old BP panels.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300
    inetdog wrote: »
    Any indication of what voltage levels are looked for? RS-232 itself supports a wide range of voltages, from +/- 3 up to +/- 15 volts. And presumably they need both + with respect to RS-232 ground and - with respect to RS-232 ground to be able to power the output RS-232 signal(s).

    I'm not sure what voltages would work. I'd guess the MSC has a built-in voltage regulator to give its internal components the proper voltages to operate, but I don't know. If you are trying a setup like this, it might be worth trying to contact Morningstar's technical support about supplying power from the computer side. I've used a cheap USB-to-serial cable for a few years with no trouble.
  • unyalli
    unyalli Solar Expert Posts: 121 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300
    westyd1982 wrote: »
    I think your problem is probably a hardware interface problem with the Morningstar MSC. It provides isolation from the MeterBus network, so it needs power from both sides. The MeterBus side through the RJ-11 cable and the serial port side from the signal lines - DTR (pin 4) & DTS (pin 7). I use a USB to Serial cable.

    The sheet that came with my MSC has notes at the bottom under the serial port diagram that say:

    1. RS-232 GND is NOT the same ground as RJ-11! The MSC is fully opto-isolated on all pins.
    2. + power must be asserted on DTR and/or RTS pins
    3. - power must be asserted on RTS and/or RX pins

    There ya go. I'm sure I read this at some point but in all the research I've been doing it was lost. I'm receiving this USB to serial adapter today. Thanks for posting the full code and allowing us to use it. I'm reading through the source and have found (I believe) the areas I need to change before compiling.

    Are you charging the same battery bank with both sunsavers?
  • waynefromnscanada
    waynefromnscanada Solar Expert Posts: 3,009 ✭✭✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300
    unyalli wrote: »
    I'm receiving this USB to serial adapter today.

    Thank you for posting this link. I've just ordered one online and look forward to it's use with my TS-MPPT-60 :D
  • unyalli
    unyalli Solar Expert Posts: 121 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    Yahoo success!! :D I am now creating a new log at 5 seconds after midnight then logging the stats I'm interested in every 5 minutes. Remoting this machine via ssh and tailing this log I can watch my system and my load is 0.33 amps. Previously I remoted my old HP laptop running xp and msview and the load was 1.2 amps. Thank you Westyd.

    I'm going to revel in my success for a while then start playing with the web page code.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    I'm glad it is working for you. If you need an example, the web page code is also does logging. I have logs for my system in one form or another since my system started 2009. I also find the daily graphs useful. I have occasionally written programs to analyze my annual or monthly power usage and generation from the data in the log files.

    Good luck and enjoy.

    - Tom
  • unyalli
    unyalli Solar Expert Posts: 121 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    Need to modify my last post. The PI is not drawing 0.33 amps, it's drawing 0.20 amps. I still had the laptop plugged in. It was off but maintaining it's battery.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    I significantly updated and simplified the web page example for displaying the data from a single SunSaver MPPT. It is one of those projects that started out as something else, has been going on for about four years, and it needed a thorough cleaning.

    It should now be a lot easier to set up. I removed all the hard coded file paths spread thoughout the files, cut it down so it just displays the data from a single SunSaver MPPT, renamed some of files so they make more sense, and made a single header file that has the basic serial port and file path information in one place. See the README file for more information. The web page example is posted at: http://westyd1982.wordpress.com/.

    With a little work, it should be relatively easy to adapt this example (and the other text-based examples) to work with the SunSaver Duo or the Tristar products.
  • unyalli
    unyalli Solar Expert Posts: 121 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    Most excellent Tom, thank you sir.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300
    unyalli wrote: »
    Most excellent Tom, thank you sir.

    Please let me know if it works for you.

    Thanks.

    - Tom
  • Muskoka
    Muskoka Solar Expert Posts: 103 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT and SureSine-300

    Need help....

    I have a SureSine, SunSaver Duo, Tristar TS-60, Tristar TS-MPPT, and I'm running Ubuntu Linux, but I'm not getting anywhere. How do I get these "Basic Examples" to work. I did install the libmodbus library. I have a PC MeterBus Adapter, and a Serial to USB cable that I use for connecting to the TS-60. I'm not well versed in getting programs to run in Linux, so if you could offer some help and get me at least started, I would appreciate it. I have gone through the read me files, it may as well be a foreign language.

    Glen

    Edit: I do use MSView in Ubuntu through Wine, so I can monitor and setup the MPPT controller over my network that way, it works fine. I've never been able to get the SureSine to work though with MSView, when I scan for devices it's never found.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for Morningstar Devices
    Muskoka wrote: »
    Need help....

    I have a SureSine, SunSaver Duo, Tristar TS-60, Tristar TS-MPPT, and I'm running Ubuntu Linux, but I'm not getting anywhere. How do I get these "Basic Examples" to work. I did install the libmodbus library. I have a PC MeterBus Adapter, and a Serial to USB cable that I use for connecting to the TS-60. I'm not well versed in getting programs to run in Linux, so if you could offer some help and get me at least started, I would appreciate it. I have gone through the read me files, it may as well be a foreign language.

    Glen

    Edit: I do use MSView in Ubuntu through Wine, so I can monitor and setup the MPPT controller over my network that way, it works fine.

    Open the file you are trying to compile (e.g., nano sunsaverduotest.c). Make sure the serial port path and MODBUS address is correct for your setup. I have put the command line instruction for compiling each "Basic Example" in the opening set of comments. For example for the sunsaverduotest, the command:

    cc `pkg-config --cflags --libs libmodbus` sunsaverduotest.c -o sunsaverduotest

    needs to be run in the directory that contains sunsaverduotest.c. To run the executable file, you need to type:

    ./sunsaverduotest

    On my computer I have to run this command as a super user to have access to the serial port. I could change the serial port security on my computer to allow any user access, but I haven't.

    You have three of the Morningstar devices that I wasn't able to test the examples on. Please let me know if you have success getting the basic examples to run.

    - Tom
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for Morningstar Devices

    Last night I put together basic examples of where I would start in trying to communicate with each of the Morningstar devices that support MODBUS comminication. These include the Morningstar Relay Driver, SunSaver Duo, SunSaver MPPT, SureSine-300, TriStar MPPTs, and TriStar PWMs. The basic examples read the first five RAM registers of each device and print out the results. If you have success getting the program to print out information from the device, you know you have a working connection to the device, and then can write or modify a program (like my web page example) to work with your device.

    For more details see: http://westyd1982.wordpress.com/
  • Muskoka
    Muskoka Solar Expert Posts: 103 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for Morningstar Devices

    Thanks Tom...

    Here's the error I get when I try to compile it. Don't know where to go from here.

    Attachment not found.

    Glen

    Edit: libmodbus5 was the library installed in Ubuntu.

    Edit2: Tried another way and got this:

    modbus.h: No such file or directory
    compilation terminated.
  • unyalli
    unyalli Solar Expert Posts: 121 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for Morningstar Devices

    I may be dealing with this my self soon. On Ubuntu 12.04 LTS I got these errors. On my Raspberry PI with Raspbian wheezy no problems. I wonder if 10.04 LTS would work.
  • Muskoka
    Muskoka Solar Expert Posts: 103 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for Morningstar Devices

    I just tried compiling and running a Hello World program "tutorial" and it worked fine, first time I ever tried this, yahoo. I tried the suresinetest.c again and got the same error, "modbus.h no such file or directory".

    Here it is for other newbies like me...

    http://www.ubuntugeek.com/how-to-install-c-and-c-compilers-in-ubuntu-and-testing-your-first-c-and-c-program.html

    Glen
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for Morningstar Devices
    Muskoka wrote: »
    Edit: libmodbus5 was the library installed in Ubuntu.

    Edit2: Tried another way and got this:

    modbus.h: No such file or directory
    compilation terminated.

    The errors look like the compiler can't find the libmodbus library.

    I don't have Debian Wheezy (Debian 7) installed on my computer yet, so I don't have access to the package. You definitely need the development version of the package libmodbus-dev which will install the header files including modbus.h. Since I don't have libmodbus-dev from the package system, I don't know what is required to link to the libmodbus library. I would try cc suresinetest.c -o sunsinetest -lmodbus as an alternative.

    If it doesn't work, I recommend looking through the Debian Source Package info on the right side at: http://packages.debian.org/wheezy/libmodbus-dev

    Also in a previous post, you said that you can't see your SureSine using MSView. I'd guess you need to get this working to make sure you can connect to the SureSine at all. Make sure the SureSine is set for MODBUS comminications. Also make sure you set the MODBUS address properly in suresinetest.c. I think I left it at 0x02, and your's is probably 0x01. I'll fix this in the examples tonight.