1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Python

Discussion in 'Software' started by 5aboy, 1 Nov 2022.

  1. 5aboy

    5aboy Minimodder

    Joined:
    5 Oct 2004
    Posts:
    642
    Likes Received:
    36
    Hi

    I am desperately trying to get something running on a dietpi virtual machine through windows.

    The module is called pysolarmanv5
    I am able to use commands to download it and python onto my virtual machine.
    No idea how to actually 'run' it...

    Help.!
     
  2. Gareth Halfacree

    Gareth Halfacree WIIGII! Lover of bit-tech Administrator Super Moderator Moderator

    Joined:
    4 Dec 2007
    Posts:
    17,133
    Likes Received:
    6,728
    If it's a module, it's not a program - it's something you use in a program. You'll need to write a program that uses the module (or find one someone else has written.)

    You can confirm it's installed properly by loading Python and trying to import it:

    Code:
    blacklaw@shodan:/media/RAM Disk$ python
    Python 2.7.18 (default, Jul  1 2022, 12:27:04)
    [GCC 9.4.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pysolarmanv5
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named pysolarmanv5
    >>>
    
    So there I've loaded Python (just typing "python" and Enter at the terminal), and then imported the module (typed "import pysolarmanv5".) You'll notice I got an error: I don't have it installed. If all goes well, you do have it installed and you won't see an error.

    Oh, and to come out of Python just hit Ctrl-D. Yes, D, not C.
     
    5aboy likes this.
  3. 5aboy

    5aboy Minimodder

    Joined:
    5 Oct 2004
    Posts:
    642
    Likes Received:
    36
    thats brilliant - i get it now.
    so if i have downloaded it, then it is sitting there waiting for another .py file to use?

    i was going mad with it - thanks for the rapid reply

    any idea where i, a mere mortal, can learn how this all works? (or is it a pain in the butt)
     
  4. Gareth Halfacree

    Gareth Halfacree WIIGII! Lover of bit-tech Administrator Super Moderator Moderator

    Joined:
    4 Dec 2007
    Posts:
    17,133
    Likes Received:
    6,728
    I'd suggest starting with reading the fine manual - or just jumping straight to the samples, if you'd prefer.

    If you've never written a Python program before, though, be prepared for a learning curve!
     
    5aboy likes this.
  5. 5aboy

    5aboy Minimodder

    Joined:
    5 Oct 2004
    Posts:
    642
    Likes Received:
    36
    im not really that interested in writing a python script - some really clever ppl have already done that bit - its just about getting the damned thing working.
    its to gather data directly from a solar inverter and possibly control it using mqtt and they do this via this method - but dont really tell you how to make it work.
     
  6. Gareth Halfacree

    Gareth Halfacree WIIGII! Lover of bit-tech Administrator Super Moderator Moderator

    Joined:
    4 Dec 2007
    Posts:
    17,133
    Likes Received:
    6,728
    So what error do you get when you try to run the Python script they've written?
     
    5aboy likes this.
  7. 5aboy

    5aboy Minimodder

    Joined:
    5 Oct 2004
    Posts:
    642
    Likes Received:
    36
    So I have done the script bit that let me load the module into python and when I ran that script you have it seems to not give an error.

    The next step is to somehow get the following thing running...problem is it doesn't tell me how to put it into python.


    https://github.com/NosIreland/solismod


    Once I've done this with the edited config.py I'm hoping it'll start to work..the instructions are for docker and I tried it but got nowhere.
    Also it's not clear if I can run both of these on same VM running dietpi or if I need to do it on seperate VMS.

    Thanks for your help and not making me feel like a complete idiot...folk on the videos say 'just do it, it's easy' without telling you how.
     
  8. Gareth Halfacree

    Gareth Halfacree WIIGII! Lover of bit-tech Administrator Super Moderator Moderator

    Joined:
    4 Dec 2007
    Posts:
    17,133
    Likes Received:
    6,728
    Right, so, Python is what's called an "interpreted language" - which means that, unlike something like C/C++ or, I dunno, Pascal, you don't compile it. There's no distinction between "Python script" and "Python program" - they're one and the same, a text file with a bunch of instructions in that Python runs through.

    First thing you need to do is to get all those files. Assuming you've got Git installed - and if you haven't, "sudo apt install git" - then you need to:

    Code:
    $ git clone https://github.com/NosIreland/solismod.git
    $ cd solismod
    
    Once you're in there, edit config.py using the text editor of your choice - I use Vim, but if you don't want to get stuck trying to figure out how to save and quit just use nano:

    Code:
    $ nano config/config.py
    [DO EDITY STUFF HERE]
    [THEN CTRL-O TO SAVE AND CTRL-X TO QUIT]
    
    And then you just do exactly what it says in the README.md file: "run main.py."

    Now, if whoever wrote main.py had put a shebang line at the top you'd simply do "./main.py" to do that... but they didn't, so you can't run the file directly. What you can do is...

    Code:
    $ python main.py
    
    That's it, it's as simple as that. Tell Python you want it to load and run main.py. You're done.

    I mean, I have no idea where you go from there 'cos I have no idea what the software does or how you know it's working... but that's what the instructions tell you to do.

    If you find it gives you an error about other missing modules, then you need to install them. Good news, the author's given you a requirements.txt file:

    Code:
    $ pip install -r requirements.txt
    
    (You may need to prefix that with "sudo," I have no idea if the modules can be installed on a per-user basis.)

    Then just rerun main.py and see if it works.
     
    5aboy likes this.
  9. 5aboy

    5aboy Minimodder

    Joined:
    5 Oct 2004
    Posts:
    642
    Likes Received:
    36
    you are a legend! thanks for putting the time into this. it is beginning to make a lot more sense.

    I think one of the modules uses umodbus to allow you to read/write via mqtt to the solar inverter, and the other allows you to read it.
     
    Gareth Halfacree likes this.

Share This Page