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

13

Comments

  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT
    Ive still got some old WRT54GS with serious hardware mods (64mb RAM & micro SD card storage) and it seems possible.. run from SD or possibly mod the firmware.

    A Linksys router with these specs can even run a full blown linux, although you would have to figure out how to load it. It might be easier to use a small linux computer like a Raspberry Pi (see http://www.adafruit.com/category/105).
  • notsobright
    notsobright Solar Expert Posts: 247 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT
    westyd1982 wrote: »
    A Linksys router with these specs can even run a full blown linux, although you would have to figure out how to load it. It might be easier to use a small linux computer like a Raspberry Pi (see http://www.adafruit.com/category/105).

    it might be but I dont have one laying around or any experience at all with them. I hope to change that at some point but even then I would still like to run your software on the WRT54GS since I will be using it as a repeater anyway so if I can figure out how it would save current draw of another device running on the very limited system I have.

    I read your wordpress site again and noticed you mention this: "I also replaced my Linksys NSLU2 with a much faster Sheevaplug (rewired to run from a DC source) running Debian Squeeze."

    did you have to change your code when you went to the sheevaplug or is it still a type of Optware package? if both your monitor and web display were running from the NSLU2 then it seems it should be relatively easy to run from DD-WRT or OpenWRT as they can run Optware packages also.

    next obstacle is that I assume your wepageexample wont fully work on the SunSaveDuo because it has double the data excepting the array voltage but that can be most likely be adjusted. not sure I can do it but with some pointers Im fairly confident I could learn how to or if you are interested I could lend you my BackUp SSD if you would like to delve into that?
  • notsobright
    notsobright Solar Expert Posts: 247 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    did you have to change your code when you went to the sheevaplug or is it still a type of Optware package? if both your monitor and web display were running from the NSLU2 then it seems it should be relatively easy to run from DD-WRT or OpenWRT as they can run Optware packages also.

    found sheevaplug listed here: http://www.nslu2-linux.org/wiki/Optware/HomePage as a supported "plug device" so should be good to go there.

    I havnt yet learned how to run optware from DDWRT so I will start with one of the more basic (simple) ones and if/when I figure that out I will try this one but this comment I read also on your wordpress site:

    " I can PMail you my software that makes my web pages, but you need to be able to program in C to modify it to your needs."

    I realize that this is even more complicated, I can work with HTML OK but I have no experience with C so this will not be easy for me at all. hopefully it is similar to straight line (machine) code since my first computer was a sinclair I do have a basic understanding of that.

    most of my confusion now is how this webpage works.. like how does a webpage that is coded with C get from there (C) to HTML so that a browser can read it?

    what Im trying to accomplish is having all this done on the router and then having the "webpage" available to any clients with proper credentials access this page via wifi. I know DDWRT has a "MyPage" option for custom webpages within DDWRT so in theory at least that should work for this but the C programming of this webpage has me very confused. I thought this was linux?


    sheesh..
  • okiejim
    okiejim Registered Users Posts: 16 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    westyd1982,
    Well I finally tried your code out on my tristar ts-45. Worked like a champ. You rock. I have just now started adding my data. Got up to the temps and did a convertion to F. It worked. Thank you so much for your work. I will keep going further with it to see if I can get it all captured.
  • okiejim
    okiejim Registered Users Posts: 16 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    Well, I was going great until I got to the bit fields. Not being the best at C I have tried struct the data and using unsigned int and I still don't get what I am expecting from the dip switches. Has anyone got this part to work yet and give a hint on what to do? I working on the tristarpwmtest.c sample. I am getting all of the data I am just not able to decode it properly. I'm expecting 1's on 0's to indicate whether or not a switch is on or off. Thanks for your help.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    Download at: http://rosebud.homedns.org/solar/tristar.tar.gz

    I don't have a TriStar to test this on, but it should test the dip switch bits properly. This is how I do it on the SunSaver MPPT.
  • okiejim
    okiejim Registered Users Posts: 16 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT
    westyd1982 wrote: »
    Download at: http://rosebud.homedns.org/solar/tristar.tar.gz

    I don't have a TriStar to test this on, but it should test the dip switch bits properly. This is how I do it on the SunSaver MPPT.

    I was looking for a hint. Shoot you did the whole thing. I will try this after work tonight and report back to you. Thank you again for your work.
    I saw some of this in a book on C but was not sure if it was the way to do it. I was trying to struct the data but could not get it to read the
    individual bits properly. This does look like it will work. Again thank you for your time. Once I get this to work I plan on tying in my Trimetric 2025RV data
    so I can see the entire system working I will share this work with you when done. My goal is to be able to see both the battery condition and the
    solar arrays condition in oneview on my linux laptop. Currently working with Fedora 19. I also added to the tristarpwmtest.c a timestamp that works
    I will show you that when done.
  • okiejim
    okiejim Registered Users Posts: 16 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    westyd1982,
    Geez the whole thing. It worked just fine first time out. I am running Fedora 19 on a tristar 45 pwm and a usb to serial adapter. Thank you so much for all you work and helping to teach programming in C with your examples. I am now going to work on communicating with my trimetric battery monitor. I will keep you informed on my progress. Having both on a laptop should give me a good look at my power generation and battery conditions. Thank you again.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    Thanks for the feedback. I'm glad it works.

    Sometime ago I started working on the web page example for the TriStar PWM. I think I now may have a working version, but don't have a TriStar to test it on. I added a new post at http://westyd1982.wordpress.com/ that includes a link to this software.
  • notsobright
    notsobright Solar Expert Posts: 247 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    westyd1982, Ive finally acquired enough skills to fully utilize the WRTs usage of Optware (.ipkg)

    now I am working on learning how to compile into .ipkg format but Im not sure that is necessary because as I mentioned previously, you mention ""I also replaced my Linksys NSLU2 with a much faster Sheevaplug"

    from my reading the Linksys NSLU2 is where "Optware" started so maybe you have this in .ipkg format already?

    if not, can you please have a look at this tutorial for this purpose and tell me if you think it might work to compile your program? http://gargoyle-router.com/old-openwrt-coding.html

    thanks
  • notsobright
    notsobright Solar Expert Posts: 247 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    more info: compiling .ipk for DDWRT http://basmaf.com/howto/create-ipk-package-for-dd-wrt/#more-312

    OpenWRT & DDWRT IPKGs are interchangeable so this should be useful.

    if anyone here can help with this, Im all ears! westyd seems a bit non-responsive towards my inquires about this but I certainly appreciate what he has shared here. this is taking a lot of effort for me to get it working this way but nothing is impossible and I really look forward to actually running it someday. (as long as the sun is still shinning LOL)
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    I haven't had time to work on this stuff for a little while, but I have been putting together software with web page examples and a full set of command line tools to read the RAM, EEPROM, and logs (where available) for a number of the Morningstar units including the SunSaver Duo, SunSaver MPPT, TriStar PWM, and the SureSine-300. I have most of these done. Hopefully I can make them available in the next few weeks.

    notsobright - I don't have any experience compiling ipkgs. On my NSLU2 I always ran the full Debian linux on an attached thumb drive. I'll try to find some time to look through the links you posted and see if I think they might work.
  • notsobright
    notsobright Solar Expert Posts: 247 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT
    westyd1982 wrote: »
    I haven't had time to work on this stuff for a little while, but I have been putting together software with web page examples and a full set of command line tools to read the RAM, EEPROM, and logs (where available) for a number of the Morningstar units including the SunSaver Duo, SunSaver MPPT, TriStar PWM, and the SureSine-300. I have most of these done. Hopefully I can make them available in the next few weeks.

    its good to see you havnt lost interest and Im excited to see what you have in store.

    westyd1982 wrote: »
    notsobright - I don't have any experience compiling ipkgs. On my NSLU2 I always ran the full Debian linux on an attached thumb drive. I'll try to find some time to look through the links you posted and see if I think they might work.

    that would be great! Ive wanted to learn more about this for a while but its been a slow process so no rush. have a good ways to go before I can even attempt this. working on it as quickly as possible though and making considerable progress using other apps that have already been done but helping me build up some experience.

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

    Tonight, I posted updated web page examples and command line tools for the SunSaver MPPT (well tested) and the TriStar PWM (untested - I don't have one). If anyone tries the TriStar PWM software, please let me know if it works. You can get either of these at: http://westyd1982.wordpress.com/

    My system has two SunSaver MPPTs and a SureSine-300, and I finally wrapped all the changes and improvements from the SunSaver MPPT web example into my own system. I will post it in a few days to show an example of how to combine monitoring of a number of devices into one web page.

    I'm also part way through writing the web page example and command line tool software for the SunSaver Duo and the SureSine-300. After those are done, I'm thinking I will look into doing the same for the TriStar MPPT units, since it might be useful for TS MPPT 30 and TS MPPT 45 owners or anyone who might want one web page combining the information from multiple TriStar MPPTs (30, 45, or 60s).
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    I posted web page example software and command line tools for the SunSaver Duo (untested - I don't have one). If anyone tries the SunSaver Duo software, please let me know if it works. You can get it at: http://westyd1982.wordpress.com/
  • okiejim
    okiejim Registered Users Posts: 16 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    I have finally had a chance to try the newer software with webpages. I am having some problems with all three executables. The first is with the powersystemstatus file. I keep getting an error
    Can't create log file:. My dir are intact any ideas what is wrong? The next issue is dailygraphs gives a segmentation fault; and dailylog gives modbus_read_registers: Illegal data address. I have this
    compiled on my raspberry pi and trying to talk to my ts-45. If I run the original tristarpwmtest code I get all of the data? I have looked at powersystemstaus and see where the message is coming from in the
    code but I don't understand why since the directory of 2014 is there and emply now files in it, do I need to create a dummy file first?
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    Thanks for trying it. Question: did you edit powersystem.h to match your system? Particularly the file paths and the serial port. In the log directory, type pwd at the command line to get the path. Also try running the command line tool tristarRAM. It prints out all the RAM registers and doesn't write any files.
  • okiejim
    okiejim Registered Users Posts: 16 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    Yep I have alot to still learn. PWD was the key I had editied it with what I thought was the path but pwd show /home/pi/powersystem I did not have the complete path on the raspberry. Powersystemstatus ran now to check the rest of it out and make sure the data is correct. Thank you again you have created a very useful system for me. I will have this installed in my ToyHauler for boondocking in the desert. I will let you know when I get the rest tested. Thank you agian
  • okiejim
    okiejim Registered Users Posts: 16 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    Well I edited cron last night and let it go. Your code is up and running fine on the raspberry pi with raspbian wheezy OS. The web page has some minor spacing issues on the pi browser but that is minor. I only have a small battery minder type panel up for testing. I have not put my two 100watt panels on the roof yet, still contemplating where I want them and how to be able to tilt them when I need to. I am unable to test all of the data with this setup but it does seem to be correct. Further testing will tell. I might just stick one panel up today to see if I can get out of night mode, and get some amperage readings. Thank you again for you hard work.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    I'm glad it works. Thanks for the feedback!
  • okiejim
    okiejim Registered Users Posts: 16 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    Merry Cristmas everyone.
    6 months now of using this code on the raspberry pi and it has not gone down yet. You did a fantastic job. I did change the code to read farenheight instead of celsius. It failed to read properly when it got below freezing last week. Not sure what I did wrong but will get another chance to test this coming week brrrrrrrrr!!
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Re: Linux (and Mac OS X) MODBUS Software for SunSaver MPPT

    Thanks again for the feedback! Did you get your temperature calculations fixed? It should be Ftemp=Ctemp*9.0/5.0 + 32.0. Also see:

    https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature
  • swerty24
    swerty24 Registered Users Posts: 3
    This thread has been very helpful. A huge thank you to westyd1985 (vanagon owner perhaps?) for the code and help to others. I had similar issues as User: Muskoka. I had the compile errors with the modbus.h include statement. I was eventually able to resolve this by slowly building up a hello world c code example, and adding a modbus function with the include statement and trying to get it to compile with each addition. After a few hours and much googling to solve each of the issues that came up, and to understand different suggestions, the thing that worked for me was adding -lmodbus on the compile line. So to compile I used the following:

    $gcc sunsaverduotest.c -o sunsaverduotest.o -lmodbus

    This got the code to compile and then I used ./sunsaverduotest.o to see the voltage on the battery through the sun saver duo charge controller on Serial port ttyS0, through RS-232 connection (not USB). Tom, I am using a Sun saver duo and the test works fine, but am unable to get a connection when I compile the powersystemstatus.c code. "Connection timed out" is the error. Not sure what the issue is there, but I will continue to investigate.

    I promised myself to contribute back to this forum once I had a solution, so hopefully this can help others who may run into the same problem. I used Debian since it was what others were using.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    swerty24 wrote: »
    vanagon owner perhaps?

    Yes, 1982 diesel Vanagon westy, although it is time to find it a new home. I don't use it anymore.

    On your compilation issues, where are you getting libmodbus from? Are you installing it from the source or are you installing it as a package from apt-get (or other package manager)?

    It is good to see that the sunsaverduotest is working. Are you trying to build powersystemstatus.c with the Makefile? If so, you need to edit the Makefile to use -lmodbus instead of
    `pkg-config --cflags --libs libmodbus`. You also need to make sure you install all the other libraries like gd2, etc... as described in the README file.
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    I've been thinking about the error:
    swerty24 wrote: »
    "Connection timed out" is the error.

    I looked at the code, and one thing to try is increasing the time between reads of the SunSaver Duo by adjusting this line in the code.
    [COLOR=#000000][FONT=Menlo][SIZE=11px]usleep([/SIZE][/FONT][/COLOR][COLOR=#272AD8][FONT=Menlo][SIZE=11px]2500[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Menlo][SIZE=11px]);        [/SIZE][/FONT][/COLOR][COLOR=#008400][FONT=Menlo][SIZE=11px]// Give the charge controller time before requesting next set of registers[/SIZE][/FONT][/COLOR]
    

    First do a test by putting:
    printf("Read first set of registers\n");
    
    on the line before to see if this is where it is timing out. If it prints out, then it goes this far before the time out.

    Then try changing the usleep time to 5000 and recompile and run it again.


    Do either sunsaverEEPROM.c or sunsaverRAM.c work?
  • swerty24
    swerty24 Registered Users Posts: 3
    I knew you had a westy! I have an old 1980 (gasoline) one myself, so glad to hear you got some good use out of your 82 Diesel!
    westyd1982 wrote: »
    On your compilation issues, where are you getting libmodbus from? Are you installing it from the source or are you installing it as a package from apt-get (or other package manager)?

    I can't remember how I installed it, but -lmodbus works just fine for now, I assume.


    westyd1982 wrote: »
    Are you trying to build powersystemstatus.c with the Makefile?

    Yep, I got that. The make file is edited to the changes.
    westyd1982 wrote: »
    You also need to make sure you install all the other libraries like gd2, etc... as described in the README file.

    Ok, I installed it.

    Do either sunsaverEEPROM.c or sunsaverRAM.c work?

    Both of these work as expected. It's Great to see all the variables as shown here.



    Currently I am getting a "Segmentation Fault" error when I run powersystemstatus.c. I was able to get it all to work by commenting out the majority of the Webpage and graph code, allowing me to log the voltage,current,etc into a textfile each minute with the cron.d file. I checked and double checked my 'pwd' directories. I added the print line statement where you suggested and it prints the line, and that shows up, then I get the segmentation fault error.

    For my current purposes the code works great. I can easily log my solar panel data collection project and battery state in to the text file for me to analyze later.

    Tom thanks again for your awesome code, and all the help on this forum!


  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    Thanks for testing all of this. Since I don't have a SunSaver Duo, I had to guess on what would work. It is good to know that the tools are working. That means that the base code is correct.

    Did you change the usleep time to 5000 to make the "Connection timed out" go away? If not, the print command might have done this also. Try removing the print command and run it to see if the "Connection timed out" is solved. If it works with 5000, please let me know and I will update the code to include this.

    The "Segmentation Fault" is probably an issue where the software
    can't find the directory where it needs to read and write files. Make sure the date on your computer is set correctly (you can check by typing: date) Also make sure you have a 2015 directory in each of the log and www directories. You also need a panelmeters directory in the www directory. They should all have been there in the code I posted. The other thing to check is that you have the directories set appropriately in powersystem.h. These need to be edited to match where the log and www directories are:
      [COLOR=#008400][FONT=Menlo][SIZE=11px][COLOR=#78492a]#define LOGFILEPATH        [/COLOR][COLOR=#d12f1b]"/home/tom/powersystem/log"[/COLOR]/* Path to directory to store log files - you need to create this directory[/SIZE][/FONT][/COLOR]
      [COLOR=#008400][FONT=Menlo][SIZE=11px]                                                                    You also need to create subdirectories with the year number (e.g, 2014, 2015, 2016, ...),[/SIZE][/FONT][/COLOR]
      [COLOR=#008400][FONT=Menlo][SIZE=11px]                                                                    since the log files are stored here. */[/SIZE][/FONT][/COLOR]
      
      [COLOR=#008400][FONT=Menlo][SIZE=11px][COLOR=#78492a]#define WEBPAGEFILEPATH    [/COLOR][COLOR=#d12f1b]"/home/tom/powersystem/www"[/COLOR]/* Path to directory to store web page files - you need to create this [/SIZE][/FONT][/COLOR]
      [COLOR=#008400][FONT=Menlo][SIZE=11px]                                                                    directory and configure the web server to serve this directory.[/SIZE][/FONT][/COLOR]
      [COLOR=#008400][FONT=Menlo][SIZE=11px]                                                                    You also need to create subdirectories with the year number (e.g, 2014, 2015, 2016, ...),[/SIZE][/FONT][/COLOR]
      [COLOR=#008400][FONT=Menlo][SIZE=11px]                                                                    since the daily graphs and daily log files are stored here. */[/SIZE][/FONT][/COLOR]
      
    

    Thanks again!

    - Tom
  • swerty24
    swerty24 Registered Users Posts: 3
    Wow Tom it worked! Thanks again for another successful install of your code working!!! The "Segmentation Fault" error was due to the www directory not having a panelmeters directory. Otherwise everything was good to go! Thanks again, it's been fun debugging this with the forum here!
  • n_den
    n_den Registered Users Posts: 1
    thx westyd1982! works perfect. i edited powersystemstatus.c like so:

    fprintf(htmlfile,"<html>\n<head>\n<title>Power System Status</title>\n");fprintf(htmlfile,"<meta http-equiv=\"refresh\" content=\"300\">\n");fprintf(htmlfile,"</head>\n");

    add i just leave the page on in Opera. thanks again. n_den.
    200W South@21.79&deg , SS-MPPT-15L, 12vdc 300Ah FLA, 1000W inverter, eu2000i
    21.45&deg N, 158.00&deg W
  • westyd1982
    westyd1982 Solar Expert Posts: 85 ✭✭
    n_den said:
    thx westyd1982! works perfect. i edited powersystemstatus.c like so:

    fprintf(htmlfile,"<html>\n<head>\n<title>Power System Status</title>\n");
    fprintf(htmlfile,"<meta http-equiv=\"refresh\" content=\"300\">\n");
    fprintf(htmlfile,"</head>\n");

    add i just leave the page on in Opera. thanks again. n_den.
    Thanks.  That is a good addition.