Skip to content

Instantly share code, notes, and snippets.

@Paraphraser
Last active June 4, 2024 12:38
Show Gist options
  • Save Paraphraser/cad3b0aa6428c58ee87bc835ac12ed37 to your computer and use it in GitHub Desktop.
Save Paraphraser/cad3b0aa6428c58ee87bc835ac12ed37 to your computer and use it in GitHub Desktop.
Compiling GoSungrow

Updating GoSungrow

This gist is intended to help you deal with the following error messages:

  • Error: appkey is incorrect 'er_invalid_appkey
  • Error: unknown error 'Request is not encrypted'

This gist has four parts. The instructions you should follow depend on what you want to do:

Part Explains how to
Part 1 recompile GoSungrow from its source code. This includes the patches that solve both errors.
Part 2 install a patched version of GoSungrow in Home Assistant.
Part 3 use a pre-compiled patched binary outside of Home Assistant. This lets you run GoSungrow from your Terminal command line.
Part 4 use a pre-built Docker image outside of Home Assistant.

The four parts are independent. In other words, you do not need to follow the steps in Part 1 and recompile GoSungrow yourself before you can use the patched version in Parts 2, 3 or 4.

about this gist

The reason this gist has a multi-part structure is historical.

The first version of this gist answered the question, "how do I recompile GoSungrow from its source code?" That material became Part 1.

Part 2 went through several revisions including using a Dockerfile plus the results of recompiling as per Part 1 to produce a new local image for Home Assistant. When triamazikamno provided patched Docker images, Part 2 was replaced with simpler (!) instructions.

Part 3 was added following a suggestion by xpufx which further leverages the work done by triamazikamno and avoids the need for recompiling GoSungrow from its source code.

Part 4 was added following a comment by Lmecano which identified a use-case for deploying the Docker images outside of the confines of Home Assistant.

Part 1 — Compiling GoSungrow

These instructions have been tested on macOS (Darwin) and Raspberry Pi OS (Debian). The Go compiler can be installed on Windows but I don't have any way of testing that.

Assumptions

  • git is installed.
  • wget is installed.

Prepare your system (Linux+macOS)

  1. Create the "go" sub-directory in your home directory:

    $ mkdir -p ~/go
  2. Add the following lines to your ~/.bashrc or ~/.profile as is your preference:

    #=======================================================================
    # Senses if the go compiler is installed
    #=======================================================================
    
    GO_BIN=/usr/local/go/bin
    if [ -x "$GO_BIN/go" ] ; then
       export GOPATH="$HOME/go"
       export PATH="$PATH:$GO_BIN:$GOPATH/bin"
    fi
    unset GO_BIN

    Tip:

    • If you copy/paste into a Windows text editor, make sure your editor saves with Unix ( : 0x0A) line endings, rather than Windows (␍␊ 0x0D 0x0A). Alternatively, use a tool like dos2unix to post-process the file.

Install/Update Go compiler

Linux (Raspberry Pi OS)

  1. Open your browser at the Go downloads page.

  2. Choose an appropriate image. Example:

    $ URL=https://go.dev/dl/go1.21.6.linux-arm64.tar.gz
    $ TARGZ=$(basename $URL)
  3. Also make a note of the SHA256 checksum and assign it to a variable. Example:

    $ HASH=e2e8aa88e1b5170a0d495d7d9c766af2b2b6c6925a8f8956d834ad6b4cacbd9a
  4. Download the image:

    $ wget $URL
  5. Verify the checksum:

    $ shasum -a 256 -c <<< "$HASH *$TARGZ"
    go1.21.6.linux-arm64.tar.gz: OK
  6. Install the compiler (replacing any older version):

    $ sudo rm -rf /usr/local/go
    $ sudo tar -C /usr/local -xzf $TARGZ

macOS

  1. Open your browser at the Go download and install page.
  2. Click the "Download" button.
  3. Run the installer package. This installs/updates as appropriate.

Tip:

  • If you have an older version of Go installed via HomeBrew, you can remove it with:

     $ brew uninstall go

    HomeBrew does not install the Go compiler in /usr/local/go/bin. You will need to adapt the login script commands if you want to use HomeBrew to install/update Go.

Windows

See download and install page.

Confirm compiler installation (Linux+macOS)

  1. Logout and login again so the new login script commands run.

  2. Confirm that GOPATH returns a sensible result:

    $ echo $GOPATH
    /home/pi/go
  3. Confirm that the compiler is present:

    • Linux (Raspberry Pi OS):

       $ go version
       go version go1.21.6 linux/arm64
    • macOS:

       $ go version
       go version go1.20.1 darwin/amd64

Compile GoSungrow

  1. Construct the following directory structure:

    $ mkdir -p ~/go-projects/MickMake
  2. Clone the GoUnify repository:

    $ cd ~/go-projects
    $ git clone https://github.com/MickMake/GoUnify.git
  3. Clone the GoSungrow repository:

    $ cd MickMake
    $ git clone https://github.com/MickMake/GoSungrow.git
  4. Move into the GoSungrow directory:

    $ cd GoSungrow
  5. Apply the patch to fix the er_invalid_appkey problem:

    $ git remote add -t encryption triamazikamno https://github.com/triamazikamno/GoSungrow.git
    $ git pull triamazikamno encryption
    $ git switch encryption

    Notes:

    1. You also need to update the APPKey and, optionally, make sure you are using the correct gateway host for your inverter. These steps are explained later at:

    2. When (if) MickMake/GoSungrow is updated to deal with this problem, you will want to undo the effect of this change and recompile from the master branch:

      $ git switch master
  6. Compile GoSungrow for your native architecture

    $ go mod tidy
    $ go build

Check your work

The next three steps tell you to run GoSungrow like this:

./GoSungrow

The ./ prefix means "run the just-recompiled binary from the working directory". Please do not make the mistake of omitting the ./ prefix because that risks executing an older version of GoSungrow that does not have any of the patches.

1. Confirm GoSungrow compiled

$ ./GoSungrow version
GoSungrow v3.0.7
Self-manage this executable.

Usage:
  GoSungrow version
  GoSungrow version [command]

Examples:
	GoSungrow version  


Available Commands:
  check                   Version	- Check and show any version updates.
  list                    Version	- List available versions.
  info                    Version	- Info on current version.
  latest                  Version	- Info on latest version.
  update                  Version	- Update version of this executable.

Flags: Use "GoSungrow help flags" for more info.

Additional help topics:

Use "GoSungrow version help [command]" for more information about a command.

2. Update the APPKey

If you followed the optional step to apply the patch to fix the er_invalid_appkey problem, you will also need to update the APPKey on any system where you intend to run GoSungrow. See APPKey configuration.

3. Set your gateway (optional)

Follow the instructions to set your iSolarCloud gateway configuration.

4. Confirm success

You can confirm everything is working by running:

$ ./GoSungrow api login
Email:	you@yourdomain.com
Create Date:	Thu Feb 09 13:14:55 CST 2023
Login Last Date:	2023-12-07 12:42:57
Login Last IP:
Login State:	1
User Account:	something
User Id:	999999
User Name:	someone
Is Online:	false
Token:	999999_99999999999999999999999999999999
Token File:	/home/pi/.GoSungrow/AppService_login.json

Cross-compiling

This section is optional. If you don't need to cross-compile, skip down to using the recompiled binary.

I want to run GoSungrow on a Raspberry Pi. Although I can install the Go compiler (as above) and compile GoSungrow on the Pi, it is much faster to do the work on macOS. All these commands are run on macOS:

  1. Cross-compile for 64-bit Raspberry Pi OS:

    $ GOOS=linux GOARCH=arm64 go build -o GoSungrow_linux_arm64
  2. Copy compiled binary to target Raspberry Pi system ("iot-hub"):

    $ scp GoSungrow_linux_arm64 iot-hub:./GoSungrow
    GoSungrow_linux_arm64    100%   90MB  90.0MB/s   00:01    
  3. Check result:

    $ ssh iot-hub file GoSungrow
    GoSungrow: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, Go BuildID=T7VxiW_Bb7zpmTzK5Gjk/ek581bp4wUYxRJpI4LW7/67TEDExnbLJooHJ3cURP/8Pi_onP5w88QBDpLdkcP, with debug_info, not stripped
  4. Comparison with "native" compile on macOS:

    $ file GoSungrow
    GoSungrow: Mach-O 64-bit executable x86_64

Cross-compiling helper script

Copy the script below and paste into a file named build-all.sh:

#!/usr/bin/env bash

compile_for() {

   echo "Compiling for $1/$2"
   GOOS=$1 GOARCH=$2 go build -o GoSungrow-${1}-${2}

}

go clean

compile_for darwin amd64
compile_for darwin arm64
compile_for linux amd64
compile_for linux arm64

if [ -n "$(which lipo)" ] ; then
   echo "Constructing universal binary for macOS"
   lipo -create -output GoSungrow-mac GoSungrow-darwin-amd64 GoSungrow-darwin-arm64
fi

The build-all.sh script should be at the path:

~/go-projects/MickMake/GoSungrow/build-all.sh

Give the file execute permission and run it:

$ cd ~/go-projects/MickMake/GoSungrow
$ chmod +x build-all.sh
$ ./build-all.sh

The result of running the script is four binaries:

  • GoSungrow-darwin-amd64 for macOS on Intel chips
  • GoSungrow-darwin-arm64 for macOS on Apple silicon
  • GoSungrow-linux-amd64 for Linux on Intel chips
  • GoSungrow-linux-arm64 for Raspberry Pi

If the lipo tool is available, the script also assembles the first two binaries into:

  • GoSungrow-mac macOS "universal" binary

Using the recompiled binary

There are many ways to use the recompiled binary. About the simplest is to include it in a directory that is in your Unix PATH. The most common pattern for home directories is:

$ mkdir -p ~/.local/bin
$ cp ./GoSungrow ~/.local/bin/.

If the ~/.local/bin directory did not already exist, you may need to logout and login to give your .profile or .bashrc a chance to discover it and add it to your PATH.

Once the binary is in a directory that is in your PATH, you can execute it just by typing the command name (ie without the ./ prefix). For example:

$ GoSungrow api login

Part 2 — Using patched images in HomeAssistant

This is based on material I added to MickMake/GoSungrow Issue 101.

Note:

  • There seems to be a common misconception that Supervised Home Assistant does not use Docker images. You may not be aware of it but that doesn't mean Home Assistant isn't using Docker.

triamazikamno has provided patched images for GoSungrow on DockerHub. To use the correct image for your instance of Home Assistant, proceed as follows:

  1. The "Advanced SSH & Web Terminal" add-on must be installed:

    Must Be Advanced add-on

    Go to Settings » Add-ons » Advanced SSH & Web Terminal. In the:

    • "Configuration" tab:

      • you need to set a username and password. This example uses "hassio" as the username. It turns up in the ssh command below.
    • "Info" tab:

      • "Show in sidebar" should be turned ON.
      • "Protection mode" needs to be turned OFF.
      • if you changed any settings in either tab, click "RESTART". If you don't see "RESTART" then click "START".
  2. Do one of the following:

    • Either – from your support host (Linux, macOS, Windows), replace hassio with the username you set in the "Configuration" tab above and connect to your HA instance:

       $ ssh hassio@homeassistant.local

      The prompt you get is:

       ~ #
      

      The # indicates you are running as root and the ~ indicates that your working directory is root's home directory.

    • Or – from the HomeAssistant web GUI, click "Terminal". A terminal window opens and the prompt you get is:

       ~ $
      

      Although the Unix convention is that a $ prompt means "running unprivileged" while # means "running as root", the HA Terminal window is in fact running as root and the working directory is root's home directory.

    In what follows below, wherever you see a line starting with "#", it means "copy/paste everything except the # and press return". Any line that does not start with "#" indicates the expected response from the preceding command.

  3. You should be able to see the existing (broken) image:

    # docker images | grep -e REPOSITORY -e gosungrow
    REPOSITORY                                        TAG         IMAGE ID       CREATED        SIZE
    ba22da74/amd64-addon-gosungrow                    3.0.7       2f8714749ba2   3 months ago   161MB

    Your output may be slightly different but you should at least be able to identify a line with "gosungrow" and version 3.0.7.

    Note:

    • If you can't find at least one GoSungrow image then it means something else is wrong with your system. You won't be able to complete these instructions. I recommend deleting and reinstalling the GoSungrow add-on. That will install the broken version but, once that is in place, you should be able to complete these instructions. You may also find it helpful to run the following command:

       # docker system prune -f
  4. Construct the required variables:

    # old_image=$(docker images | grep gosungrow | awk '{print $1 ":" $2}')
    # echo $old_image
    ba22da74/amd64-addon-gosungrow:3.0.7
    
    # new_image=$(echo $old_image | awk -F/ '{print"triamazikamno/"$2}')
    # echo $new_image
    triamazikamno/amd64-addon-gosungrow:3.0.7

    You should get sensible responses to the echo commands. Your exact output may differ but you should be able to see that the earlier output from docker images has turned up in the first echo command, and that the first part of the image name (ie ba22da74) has been replaced with triamazikamno in the second echo command.

    Note:

    • If you don't get sensible responses to the echo commands then it means something is wrong. Go back and re-check your work.
  5. Retag the old image. This prevents it from being removed:

    # docker tag $old_image ${old_image}-backup

    Confirm that that has worked by re-running the images command:

    # docker images | grep -e REPOSITORY -e gosungrow
    REPOSITORY                                        TAG            IMAGE ID       CREATED        SIZE
    ba22da74/amd64-addon-gosungrow                    3.0.7          2f8714749ba2   3 months ago   161MB
    ba22da74/amd64-addon-gosungrow                    3.0.7-backup   2f8714749ba2   3 months ago   161MB

    You can see both repository+tag combinations point to the same ImageID.

    Note:

    • An ImageID is a hash of the image file so two repository+tag combinations pointing to the same ImageID means they are both pointing to the same image file on disk.
  6. Pull the replacement image from DockerHub:

    # docker pull $new_image
    3.0.7: Pulling from triamazikamno/amd64-addon-gosungrow
    659d66d51139: Already exists 
    7c0ba91aad39: Pull complete 
    fb2a01b55562: Pull complete 
    4425acca1925: Pull complete 
    d50c5eb93aa0: Pull complete 
    adde5526d152: Pull complete 
    Digest: sha256:216c20966785878ccae85b48e45f31fc5e38295f04589d0b2377a7c8b564c867
    Status: Downloaded newer image for triamazikamno/amd64-addon-gosungrow:3.0.7
    docker.io/triamazikamno/amd64-addon-gosungrow:3.0.7

    Again, the actual details may vary but images will confirm the result:

    # docker images | grep -e REPOSITORY -e gosungrow
    REPOSITORY                                        TAG            IMAGE ID       CREATED        SIZE
    triamazikamno/amd64-addon-gosungrow               3.0.7          f2cbc9418287   11 hours ago   161MB
    ba22da74/amd64-addon-gosungrow                    3.0.7          2f8714749ba2   3 months ago   161MB
    ba22da74/amd64-addon-gosungrow                    3.0.7-backup   2f8714749ba2   3 months ago   161MB

    Three repository+tag combinations but now we have two distinct images.

  7. Now we change the middle tag to point to the new image:

    # docker tag $new_image $old_image

    And confirm that again with images:

    # docker images | grep -e REPOSITORY -e gosungrow
    REPOSITORY                                        TAG            IMAGE ID       CREATED        SIZE
    ba22da74/amd64-addon-gosungrow                    3.0.7          f2cbc9418287   11 hours ago   161MB
    triamazikamno/amd64-addon-gosungrow               3.0.7          f2cbc9418287   11 hours ago   161MB
    ba22da74/amd64-addon-gosungrow                    3.0.7-backup   2f8714749ba2   3 months ago   161MB

    Note:

    • This step of using the old repository+tag combination to point to the new ImageID is what causes Home Assistant to load the new patched image rather than the old broken image.
  8. Go back to the Home Assistant GUI:

  9. If HA seems to freeze, try quitting your browser and reconnecting to the GUI. Worst case you may need to restart HA, and then start GoSungrow again.

Part 3 — Using a patched binary

triamazikamno has provided patched versions of GoSungrow on GitHub. If you want to obtain a patched version of GoSungrow for use outside of Home Assistant but you do not want to recompile GoSungrow yourself, proceed as follows:

  1. Use your browser to open the following URL:

  2. Scroll down to "Assets" and expand the disclosure triangle if necessary.

  3. Identify the asset which is appropriate to your platform. Examples:

    • macOS on Intel = GoSungrow-darwin_amd64.tar.gz
    • macOS on Apple silicon = GoSungrow-darwin_arm64.tar.gz
    • Linux on Intel = GoSungrow-linux_amd64.tar.gz
    • Linux on 64-bit Raspberry Pi = GoSungrow-linux_arm64.tar.gz
  4. Download the asset to your system. You can either do that from within your browser or you can copy the asset URL to your clipboard, then paste it into a wget command. Something like this would get the job done:

    $ mkdir ~/GoSungrow-patched
    $ cd ~/GoSungrow-patched
    $ wget https://github.com/triamazikamno/GoSungrow/releases/download/v3.0.7/GoSungrow-linux_arm64.tar.gz

    Just make sure you use the correct asset URL in the wget command.

  5. Unpack the .tar.gz (a tape archive – sometimes called a "tarball" – with gzip compression):

    • On macOS (assuming you asked your browser to do the download), the asset will be in your Downloads folder. Double-clicking the downloaded asset creates a folder of the same base name as the asset and extracts the asset's contents into that folder.

    • On Linux (assuming you have just done the wget as above and your working directory is still ~/GoSungrow-patched), you can extract the asset's contents into the working directory like this:

       $ tar -xzf *.tar.gz

    Either way, you wind up with a folder containing the GoSungrow binary plus some other odds and ends which you can ignore.

  6. Complete the following steps from Part 1:

Part 4 — Using a patched Docker image

triamazikamno has provided patched images for GoSungrow on DockerHub. Although the images were intended for use with Home Assistant, they are just Docker images and can also be used outside of Home Assistant.

Initial setup

  1. Create a directory to hold the GoSungrow configuration and its runtime artifacts. These instructions assume the following but the actual directory can have any name and be located be anywhere:

    $ mkdir -p $HOME/GoSungrow
  2. Use the following JSON as a template:

    {
      "sungrow_host": "«Host URL»",
      "sungrow_user": "«USERNAME»",
      "sungrow_password": "«PASSWORD»",
      "sungrow_appkey": "«APPKEY»",
      "mqtt_host": "localhost",
      "mqtt_port": "1883",
      "mqtt_user": "",
      "mqtt_password": "",
      "debug": false,
      "sungrow_timeout": 60
    }
  3. Edit the JSON:

    • "sungrow_host": see iSolarCloud gateway configuration and replace «Host URL» with the appropriate Host URL.
    • "sungrow_user" and "sungrow_password": replace both «USERNAME» and «PASSWORD» with your iSolarCloud credentials.
    • "sungrow_appkey": see APPKey configuration and replace «APPKEY» with the appropriate key.
    • "mqtt_host": the default value of "localhost" assumes the broker is running on the same host as the GoSungrow container but this field can contain a hostname, domain name or IP address.
    • "mqtt_port": the default port for MQTT is 1883 so only change this if you know your broker is running on a non-standard port.
    • "mqtt_user" and "mqtt_password": default to null strings, which assumes your broker does not check credentials. Set appropriate values if your broker authenticates messages.
    • "debug" and "sungrow_timeout": should be left as is.
  4. Save the edited JSON to the path:

    $HOME/GoSungrow/options.json
    

Running the container

  1. From the following list, choose the image which is appropriate for your host's architecture:

    Image Typical Platform
    triamazikamno/armhf-addon-gosungrow:3.0.7 Raspberry Pi 3
    triamazikamno/armv7-addon-gosungrow:3.0.7 Raspberry Pi 4 in 32-bit user mode (kernel mode is irrelevant)
    triamazikamno/aarch64-addon-gosungrow:3.0.7 Raspberry Pi 4/5 in full 64-bit mode
    triamazikamno/amd64-addon-gosungrow:3.0.7 Debian guest on Proxmox-VE running on Intel
  2. In the following command, replace «IMAGE» with the image you chose in the previous step:

    $ docker run -d --name gosungrow --net=host \
       -v "/etc/ssl/certs:/etc/ssl/certs:ro" \
       -v "$HOME/GoSungrow:/data" \
       «IMAGE»
  3. Execute the command. For example, on a Raspberry Pi 4 running full 64-bit Bullseye or Bookworm, the command would be:

    $ docker run -d --name gosungrow --net=host \
       -v "/etc/ssl/certs:/etc/ssl/certs:ro" \
       -v "$HOME/GoSungrow:/data" \
       triamazikamno/aarch64-addon-gosungrow:3.0.7

Notes:

  • --net=host is only needed to facilitate the use of "mqtt_host": "localhost" in the options.json file. If you run the GoSungrow container as part of a stack in which Mosquitto is also running, you can employ non-host mode and change "localhost" to "mosquitto".

  • The first -v maps the host's SSL certificates into the container. The container will inherit any changes made by routine updates to your operating system.

  • When you execute the docker run command on a non-Intel platform, you may see the following message:

     WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
    

    You can ignore that message. See GoSungrow Issue 32 for more information.

Configuration

iSolarCloud gateway configuration

Sungrow appears to operate the iSolarCloud servers shown in the table below. There may be more. If you discover another server then please add a comment to this gist and I will update the list.

Clicking a link in the "Web URL" column will take you to a web portal where you can login. The "Host URL" column is the URL you need to use for GoSungrow.

URLs marked with "†" are guesses based on the .eu pattern. Each domain name resolves in the Domain Name System but I have no way of testing whether any gateway other than the Australian host works in practice. If you use one of these servers and are able to confirm the Host URL is correct, please let me know in the comments below.

"Server" Web URL Host URL
Chinese www.isolarcloud.com.cn https://gateway.isolarcloud.com.cn 
European www.isolarcloud.eu https://gateway.isolarcloud.eu
International www.isolarcloud.com.hk https://gateway.isolarcloud.com.hk 
Australian au.isolarcloud.com https://augateway.isolarcloud.com

To apply a "Host URL":

  • If you are using the GoSungrow add-on in Home Assistant:

    1. Open the Home Assistant GUI.
    2. Click "Settings".
    3. Click "Add-ons".
    4. Click "GoSungrow".
    5. Click the "Configuration" tab.
    6. Enter the Host URL from the table into the sungrow_host field.
    7. Click "Save" then follow your nose.
  • If you are using the GoSungrow binary, run:

     $ ./GoSungrow config write --host "«Host URL»"
    

    Example:

     $ ./GoSungrow config write --host "https://augateway.isolarcloud.com"
    
  • If you are editing a JSON configuration file, replace the «Host URL» field with the value from the table:

     {
       "sungrow_host": "«Host URL»",
     }

    Example:

     {
       "sungrow_host": "https://augateway.isolarcloud.com",
     }

APPKey configuration

The situation with APPKeys is confusing. Some people report success with one key, other people another key. Below is a list of known keys. Try them in order until you find one that works:

  • B0455FBE7AA0328DB57B59AA729F05D8
  • ANDROIDE13EC118BD7892FE7AB5A3F20

If you discover new APPKeys, please let me know and I'll add them to this list.

To apply an "APPKey":

  • If you are using the GoSungrow add-on in Home Assistant:

    1. Open the Home Assistant GUI.
    2. Click "Settings".
    3. Click "Add-ons".
    4. Click "GoSungrow".
    5. Click the "Configuration" tab.
    6. Enter the APPKey from the table into the sungrow_appkey field.
    7. Click "Save" then follow your nose.
  • If you are using the GoSungrow binary, run:

     $ ./GoSungrow config write --appkey «APPKey»
    

    Example:

     $ ./GoSungrow config write --appkey B0455FBE7AA0328DB57B59AA729F05D8
    
  • If you are editing a JSON configuration file, replace the «APPKEY» field with the value from the table:

     {
       "sungrow_appkey": "«APPKEY»",
     }

    Example:

     {
       "sungrow_appkey": "B0455FBE7AA0328DB57B59AA729F05D8",
     }

Change History

  • 2024-05-02

    • Evidence now suggests there is no correlation between iSolarCloud servers and AppKeys. Text adjusted.
  • 2024-05-01

    • Consolidate all information about iSolarCloud gateways and APPKeys into a new section and cross-reference existing sections to the consolidated material.
  • 2024-03-15

    • Adds Part 4 to leverage existing updated DockerHub images for anyone who wants to run GoSungrow in a Docker container outside of Home Assistant.
  • 2024-03-13

    • Adds Part 3 to leverage existing recompiled binaries (which are inputs to the updated DockerHub images) for anyone who simply wants to obtain a patched version of GoSungrow without having to recompile it themselves.
  • 2024-02-28

    • Includes reminder to click SAVE when changing settings.
  • 2024-01-30

    • Adds reminder to set cloud gateway for non-AU systems.
  • 2024-01-22

    • Move go mod tidy before go build.
  • 2024-01-14

    • Emphasise need to use ./ prefix when testing the recompiled binary.
    • Add short section on using GoSungrow from ~/.local/bin.
  • 2023-12-24 - restructure to make clear the distinction between recompiling and using replacement images in Home Assistant.

  • 2023-12-06 - revise "hack" to clarify that the hack can be applied without opening a connection via SSH.

  • 2023-12-09 - revise "hack" to use images provided by triamazikamno on DockerHub.

  • 2023-12-07 - add steps to recompile from triamazikamno fork to resolve er_invalid_appkey problem:

  • 2023-11-29 - re-tested using go 1.21.4 on:

    • M2 MacBook Pro running macOS Ventura 13.6.2
    • Intel Mac Mini running Debian Bookworm guest on Proxmox VE
    • Raspberry Pi 4B running Raspberry Pi OS Bullseye
    • Raspberry Pi 4B running Raspberry Pi OS Bookworm
  • 2023-09-18 - satisfy GoUnify dependency.

@Paraphraser
Copy link
Author

@Lmecano If this gist has given you the impression that I have any deep knowledge about anything to do with Sungrow infrastructure then I'm sorry but that's not the case. Such "knowledge" as I have comes from starting with the README on the GoSungrow repo, exploration, frustration and guesswork. Even then I only ever went as far as I needed to go to get the data I wanted.

I don't use the Home Assistant version. I use the compiled binary in a script which runs once a day to collect "yesterday's" data. My goal was to replicate a time-series that began when I got my first solar system, which had a SolaX inverter. My script fetches a grand total of 12 metrics from iSolarCloud. That's all I need to do all the calculations I want. I really only look at it once a day to see how yesterday went, and then once a week to do an expected bill calculation. Sure, early on I'd use the iPad app to watch the thing in real time but that got real old, real fast. In reality my main objective is just to avoid ever being in the situation where the inverter stopped working, I didn't realise, and then I got a surprise bill. Nothing more than that. An eyeball once a day is sufficient.

If my script ever broke with a message like you are seeing then I would have no idea what to do next.

But.

My understanding is that, in this context, "API" (Application Programming Interface) refers to the communications protocol and the syntax of the request/response messages transported between client (your device) and server (iSolarCloud), while "endpoint" refers to a specific data element which usually looks something like this:

1234567_1_1_1.p1

I believe (I do not know) that that decomposes as follows:

  • 1234567 is the "psid" (maybe "personal site identifier" or some such);

  • 1_1_1 seems to be a "device ID". It means my Sungrow SG5.0RS inverter, as distinct from, say, 7_1_1 which seems to mean the inline meter; and

  • .p1 appears to be the data store for Daily Yield.

Thus:

$ GoSungrow-mac show point data 202403130000 202403132359 5 1234567_1_1_1.p1 >results.txt

In words, "fetch Daily Yield at 5-minute intervals for yesterday's date". There are 288 5-minute periods in 24 hours so I expect the output file to contain at least that many lines:

$ wc -l results.txt 
     294 results.txt

The other 294-288=6 lines are header/trailer. The observation for the 5-minute period beginning midday yesterday:

$ grep "12:00:00" results.txt 
┃ 2024-03-13 12:00:00    ┃ 1234567_1_1_1    ┃ 9800                ┃

or 9.8kWh to that point.

So, to the extent that my earlier definition of the "Sungrow API" holds, I can communicate with the (Australian) server and retrieve expected end-points, so I don't think anything is "broken", at least not in any systematic sense.

But that still doesn't explain why you are getting that message.

I wondered if the explanation might be as simple as using the wrong server. However, when I try switching to the EU server, I get different error messages:

$ GoSungrow-mac api login
Error: cannot login

$ GoSungrow-mac show point data 202403130000 202403132359 5 1234567_1_1_1.p1
Error: Account does not exist '账号不存在'

Logically, if you aren't seeing those messages, the EU server must be correct for you. What happens when you run:

$ GoSungrow show ps list

I get my expected three devices:

┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ Ps Key           ┃ Ps Id   ┃ Device Type ┃ Device Code ┃ Channel Id ┃ Serial #    ┃ Factory Name ┃ Device Model   ┃
┣━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┫
┃ 1234567_1_1_1    │ 1234567 │ 1           │ 1           │ 1          │ B2222334445 │ SUNGROW      │ SG5.0RS        ┃
┃ 1234567_22_247_1 │ 1234567 │ 22          │ 247         │ 1          │ B2222334445 │ SUNGROW      │ WiNet-S        ┃
┃ 1234567_7_1_1    │ 1234567 │ 7           │ 1           │ 1          │ B2222334445 │ SUNGROW      │ SG Smart Meter ┃
┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛

If you can get that far then my guess is that the error message means what I would interpret it as saying were I to receive it myself, which is that, given a request for:

psid_deviceid.pnnnn

the pnnnn data store (aka bucket aka metric) doesn't exist for your inverter.

As to why? Beats me. Sorry.

@Lmecano
Copy link

Lmecano commented Mar 14, 2024

Thanks for the feedback, you are still more knowledgeable than I do :)
I have succeeded to run a bash of the image with
docker run -it <image-id> /bin/bash

And modified manually all the config file and tried to manual login with
GoSungrow api login
But I just got an "Error : empty file"

I'm wondering if I should not compile everything as you did in Part 1, because when I run the docker image, I got the following warning :
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

@Paraphraser
Copy link
Author

@Lmecano I have extended the gist to include a new Part 4 which explains how to take one of the Docker images built as Home Assistant add-ons and repurpose it as a local container using docker run.

The new material also explains why the "WARNING" message can be ignored.

Something I suspect you might not be fully aware of is what happens when you run a container like this:

$ docker run -it <image-id> /bin/bash

That tells Docker to:

  1. Pull the image (if it is not already downloaded);
  2. Instantiate the image as a running container; and
  3. Override the container's normal startup sequence by telling it to execute /bin/bash.

All you really get from doing that is the base operating system (Alpine Linux).

In the case of the GoSungrow container, the normal startup sequence runs a script called run.sh (it's inside the container). That script takes the options.json file and uses it to create a config.json (the thing you see when you run GoSungrow config read), and then launches GoSungrow with the arguments mqtt run.

Overriding that means options.json is never read and config.json is never created. That's why GoSungrow api login moans about an empty file.

If you want to open a shell into the GoSungrow container, the correct way is to get it going as is explained in Part 4 then, once it is running, you can interact with it via:

$ docker exec -it gosungrow bash

That opens a shell into the initialised container. Then you can run GoSungrow commands alongside the mqtt run command and it will all just work.

There's really no way around this because the setup work done by run.sh is the foundation for everything else. Plus, the only reason docker exec is able to open a shell is because the mqtt run is in an infinite loop keeping the container running.

If you simply want to experiment with GoSungrow where you have full control over what it does and when it does it, you have to install the binary locally. That's what Part 3 is for.

I hope I've covered-off everything you raised in your post.

@Lmecano
Copy link

Lmecano commented Mar 15, 2024

Hello, thanks again !
I have followed some docker tutorial to be more familiar with the vocabulary, and with your explanations, I'm starting to got it !
I have prepared the container to run as you describe, but when time has come, I got the following permission error :
d50c6b123e2ab99216b5d785095cbff30d8c2a16ed06394c472893b12403d870 docker: Error response from daemon: error while creating mount source path '/root/GoSungrow': mkdir /root/GoSungrow: read-only file system.
The container doesn't appear in the list of running container with docker ps

Even a chmod -R 777 $HOME/GoSungrow doesn't help.
From what I have found on internet, could be an issue with the docker version (I'm using an RPI 3, may be that's why....)

I have installed Docker Desktop on my window, I will try all of that on another HomeAutomation build
EDIT : I have installed Debian on a VM and compiled the soft. The connection to API is fine and it looks like I can see my Sungrow system \o/
The question would be now.... why the homeassistant version doesn't catch the API endpoint

@Paraphraser
Copy link
Author

@Lmecano

Error response from daemon: error while creating mount source path '/root/GoSungrow': mkdir /root/GoSungrow: read-only file system

That error makes absolutely no sense to me.

Let's go back a few hundred steps.

If you start with a blank SD card, use Raspberry Pi Imager to transfer Raspberry Pi OS onto that media, insert that media into your Pi (3, 4, 5, Zero2W, whatever) and apply power, you get a privileged initial user account and the root account is disabled.

Historically, that initial user account is called "pi" but you can now set it to be any name (although I still recommend going with "pi" and it's what I'm going to assume in this discussion).

What I mean by "privileged" is that "pi" has the ability to run sudo. On Raspberry Pi OS, "pi" also has the ability to run sudo without being prompted to enter a password.

Other OS install procedures have different approaches. For example, if you install Debian either natively or as a Proxmox guest, the installer prompts you to enter a root password. If you supply a password, the root account is enabled and the initial user account isn't privileged. However, if you leave the root password blank then the initial account is privileged (but a password is needed to run sudo).

The take home message from all of this is that there are so many variations on the theme that, without knowing exactly how you set up your Pi, I can really only discuss this in general terms.

In Part 4 of this gist, the instruction is that you should create the GoSungrow folder before executing the docker run command.

Assuming you did that, if you are logged-in as root then running:

# docker run … -v "$HOME/GoSungrow:/data"

should see $HOME expand to /root and it should not be necessary for docker to attempt to create /root/GoSungrow because it should already exist.

However, if you did not create /root/GoSungrow before running the docker command then it is still running as root and should have no trouble creating /root/GoSungrow itself.

Conversely, if you are logged in as "pi" then running:

$ docker run … -v "$HOME/GoSungrow:/data"

should see $HOME expand to /home/pi and it should not be necessary for docker to attempt to create /home/pi/GoSungrow because it should already exist.

However, if you did not create /home/pi/GoSungrow before running the docker command then it is still running as "pi" and should have no trouble creating /home/pi/GoSungrow itself, and should not be trying to create /root/GoSungrow in the first place.

Even if you are logged in as "pi" but run:

$ sudo docker run … -v "$HOME/GoSungrow:/data"

the expansion of $HOME occurs before the sudo so the command that is actually passed to sudo is:

docker run … -v "/home/pi/GoSungrow:/data"

and, again, /home/pi/GoSungrow should exist already so there's no reason for docker to try to create it.

The only thing that seems to make sense is this kind of pattern:

$ mkdir -p $HOME/GoSungrow
$ sudo -s
# docker run … -v "$HOME/GoSungrow:/data" 

In that situation, $HOME expands to /home/pi for the mkdir command, but expands to /root within the sudo shell context.

If that (or something like it) is what you have been doing then I further surmise that you feel the need to use sudo to run docker commands, likely because they don't seem to work without sudo.

Am I anywhere close to guessing correctly about this?

If I am then the basic problem might be that you have missed a step somewhere along the way when installing Docker, which is to give yourself membership of the "docker" group. Do this test (while logged-in as "pi" and not while inside a sudo shell):

$ groups

Do you see "docker" in the list? If not, that's a problem. You can fix it by doing:

$ sudo /usr/sbin/usermod -G docker -a $USER

and then you must logout and login again. After that, "docker" should be in the groups list and you shouldn't have to use sudo to run docker commands.

Perhaps also read what-is-sudo for more hints on when sudo is or isn't appropriate.

The real problem with over-use of sudo is that it can easily do an awful lot of damage to your system which is hard to discover and fix. The damage lurks under the hood causing permission errors, which lead you to using sudo and causing further damage. It's a vicious cycle.

From what I have found on internet, could be an issue with the docker version (I'm using an RPI 3, may be that's why....)

This is a definitely possibility. I keep running across tutorials and YouTube videos which boil down to using apt to install docker and docker-compose. That's a recipe for a mess. What usually happens is you get an obsolete docker-compose with dependencies which force the downgrade of docker, and then both become pinned and can never be upgraded.

Look, if you're up for it, perhaps take a look at PiBuilder.

What PiBuilder is designed to do is construct a rock solid server-class platform for IOTstack.

IOTstack is not a "system". It's a set of conventions for allowing arbitrary collections of Docker containers to be run together as a "stack". The classical form of that stack is MING (Mosquitto, InfluxDB, Node-RED and Grafana). Although GoSungrow is not included as one of IOTstack's templates, it's easy enough to add if that is what you wanted to do (I've done it). Plus, the problem of setting up Mosquitto is solved because that is part of IOTstack.

The material point, though, is that IOTstack needs Docker so PiBuilder installs Docker properly, which includes using the official "convenience script" and setting up the group membership as above. So, even if IOTstack doesn't sound like something you want or need, using PiBuilder ensures the Docker side of things will have been done right.

Also, if you would prefer to do the same thing on a VM, you might get some useful hints from running-on-proxmox-debian.

The container doesn't appear in the list of running container with docker ps

No. A container has to at least start before it appears in the process list. Not being able to create the folder prevents the container from starting.

The question would be now.... why the homeassistant version doesn't catch the API endpoint

I don't understand your question. Do you mean:

  1. The HA version does report "EndPoint not yet implemented" but the VM version doesn't get that error; or
  2. The HA version doesn't report "EndPoint not yet implemented" but the VM version does get that error?

Either way, my answer is the same. I don't know. I don't have any deep understanding about how Sungrow inverters log metrics, nor how the iSolarCloud API works, nor how GoSungrow works. All I have to go on is my own standalone use of GoSungrow and I don't see any errors like this in what I'm using it for.

@Lmecano
Copy link

Lmecano commented Mar 20, 2024

It makes no sense to me either :D
For some context, I have installed HomeAssistant through RPImager on a RPI3 model B.
Some information :

  • Before running the "run" command, the folder $HOME/GoSungrow was created.
  • The whoiam command identify me as root.
  • I have never needed to use the sudo command in HA
  • Even sudo docker run .... leads to the same error message
  • Even creating the folder in /home/pi/GoSungrow leads to the same error message
  • I did not installed docker, it's included in HA

In parallel, on my personal computer, I have installed a VirtualMachine of Debian to compile the code (Part1 of your tutorial)
=> Doing this way work ! I can see my Sungrow material and some information.

In summary : I can't make this addon work with HA. But it works installed directly on Debian.
May be I could compile the addon in HA, as it is a Debian-based OS.... but it looses all the advantages to have a simple embedded addon, I think.

I think I will forget about getting the data from the Sungrow API (doesn't look reliable) and just do my own electronic board to measure the information I need.

Thank you for the support <3

@Paraphraser
Copy link
Author

@Lmecano - well that makes things a lot clearer. If you'd given me that context at the start, I wouldn't have guessed (incorrectly; several times) about what you were trying to do.

If you're running Home Assistant, regardless of platform, the only part of this gist you need to concern yourself with is Part 2.

You don't need the $HOME/GoSungrow folder - at all - irrespective of whether $HOME expands to /root or /home/«someUserNameOfYourChoiceHere».

You don't need to be using sudo - for anything.

You don't need to be doing docker run - with or without sudo.

Yes, the whoami command will return root because that's what you get when you use the Advanced SSH and Web Terminal. Even if you SSH (rather than run Terminal from the sidebar), whatever user you define (the default is hassio) still becomes root on login.

And, yes, you don't need to be installing Docker because HA comes with Docker because Docker is how HA works.

For the record, I have been running HA as a Proxmox-VE guest on an old Intel MacMini. That's mainly because I don't actually use HA for anything productive so I don't want to dedicate a Pi to HA.

But, today, I worked through the same install process as you, albeit on a Pi 4B rather than a Pi 3B, because I no longer have a 3B (mine died about a year ago). I used Raspberry Pi Imager to download the HA image and burn it to SD. I booted the Pi 4, installed Advanced SSH and Web Terminal, Mosquitto broker and GoSungrow. I configured all three from scratch. I went through the steps in Part 2. And GoSungrow just worked. The last part of the log:

Is Online:	false
Token:	374058_053ea977157c4d0ba2afa14b170aa5eb
Token File:	/data/.GoSungrow/AppService_login.json
[09:58:32] INFO: Syncing data from gateway https://augateway.isolarcloud.com ...
2024/03/21 09:58:32 INFO: Connecting to MQTT HASSIO Service...
2024/03/21 09:58:32 INFO: Connecting to SunGrow...
2024/03/21 09:58:32 INFO: Found SunGrow 3 devices
2024/03/21 09:58:32 INFO: Caching Sungrow metadata...
2024/03/21 09:58:33 INFO: Cached 963 Sungrow data points...
2024/03/21 09:58:33 INFO: Syncing 148 entries with HASSIO from getPsList.
CUCU?CU?CUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCU?CUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCU?CUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCUCU?CUCUCUCUCUCUCUCUCUCUCUCUCUCUCU?CUCUCUCUCUCUCUCUCUCUCUCU?CUCUCUCUCUCUCUCUCU
2024/03/21 09:58:34 INFO: Syncing 205 entries with HASSIO from getPsDetail.
????CUCUCUCU?CUCUCUCU?CUCUCU?CU?CUCUCUCUCU??CU?CUCUCUCUCUCUCUCUCUCU?CUCUCUCUCU?CU?CUCUCUCU?CU???CU?CUCUCUCU?CUCU?CUCUCUCUCU??CUCUCUCU?CU?CUCUCUCU?CUCU?CU?CU?CU?CUCUCUCUCU?CUCU???CUCUCUCUCUCUCUCU?CUCUCUCUCUCUCUCUCUCUCU?CU?CUCUCUCUCUCUCUCUCU?CUCU?CUCU???CUCU?CUCUCUCUCUCUCU?CU?CUCUCUCU??CU?CUCUCUCUCUCU?CUCUCUCUCU?CUCUCU?CUCU?CUCU?CUCUCUCUCUCU??CUCUCUCUCUCU
2024/03/21 09:58:34 INFO: Syncing 461 entries with HASSIO from queryDeviceList.
CU-CUCUCUCU--CU-CU--CU-CUCU---CUCU-CU--CU-CU-CU-CU-CUCUCUCUCU
2024/03/21 09:58:34 INFO: Starting ticker...
2024/03/21 09:58:34 INFO: Fetch Schedule: 5m
2024/03/21 09:58:34 INFO: Sleep Delay:    40s
2024/03/21 10:04:34 INFO: Syncing 461 entries with HASSIO from queryDeviceList.
-UU----U-UU-U--UU--UUU--UU-UUUU--UU-CUUU
2024/03/21 10:04:35 INFO: Syncing 148 entries with HASSIO from getPsList.
UUUUUUCUUUUU?UUUUUUUUUUUUUUUUUU?UUUUUUUUUCUUUUUUUU?UUUUUUU??UUUUUUUUUUUUUU?UUUUUUUUUUUUUUUUUUUUUUUUUCUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUCUUUUUUUUUUUU?UUCUU
2024/03/21 10:04:35 INFO: Syncing 205 entries with HASSIO from getPsDetail.
U?UU?U?UUU???U?U?UU?UU??UU??UUU??UUUCUUUU?U?UUCUUCUUUUU?U?UUCUUU?UU?UUUU?UUUUU?UUUUUUUUU?U?U?UU?U??UUUU??UUUUUU?UUUUUUU?CUCUU?UUU?U?UUUUU?U?UUU?U??UU?U??UUUU?UUUUUUU?UUUU?UUUUCUUCUUU?U??U?UUUUUUUUUUUUUUUU??UUUUU??
2024/03/21 10:10:24 INFO: Syncing 148 entries with HASSIO from getPsList.
UU?UCUUCUUU?UUUUUUUUUUUUUUUUCUUUUUUUUUUUUCUUUUUUUUUUU?UUUUUUUUUUUUUUUU??UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU?UUUUUUUUUUUUUU?UUUUUUUUUCUUUUUUUUUUUUUUUUUUUUUU
2024/03/21 10:10:24 INFO: Syncing 205 entries with HASSIO from getPsDetail.
UUUU?UUUUUUUU?UUU?U?UU??UUUUUUUUUUU??UUUUUUCU?U??CU?UUUUUUUUUU?UU?U?UUUUUU??U?UUUUCUUU??UUCUUU??CUUCUU?UUU?UU?UCU?U?UUUUUCU??UUUCUU??UU??UUUUUU?UU?CU?UUU?????CU??U?U?UU?UCU?UCU?UUCUUU?UUCUU?UUUUUUUUUUU?UUCUUUUU?UU?UUU?UU?
2024/03/21 10:10:24 INFO: Syncing 461 entries with HASSIO from queryDeviceList.
-UUU--UU---UUU--UUUU---UCUCU--U-UUU-U-UU-

Now, if I want to use the already-running GoSungrow container (the actual running add-on) to experiment with other GoSungrow commands, I do this:

  1. Click Terminal in the side-bar.

  2. Type the command:

    docker ps
    
  3. One of the entries in the response is:

    CONTAINER ID   IMAGE                                  COMMAND                  CREATED          STATUS          PORTS                                                                                                                          NAMES
    04e0c040d4ab   3fa94738/aarch64-addon-gosungrow:3.0.7 "/init /usr/local/bi…"   16 minutes ago   Up 16 minutes                                                                                                                                  addon_3fa94738_gosungrow
    
  4. I can use either the CONTAINER ID of 04e0c040d4ab or the NAME addon_3fa94738_gosungrow in the next command. I'm going to use the ID because it's shorter:

    docker exec -it 04e0c040d4ab bash
    
  5. The prompt changes to bash-5.1# to indicate I'm running a shell inside the container. Now I can run other GoSungrow commands:

    GoSungrow --config /data/.GoSungrow/config.json show ps list
    

    and the response is:

    ┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
    ┃ Ps Key           ┃ Ps Id   ┃ Device Type ┃ Device Code ┃ Channel Id ┃ Serial #    ┃ Factory Name ┃ Device Model   ┃
    ┣━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┫
    ┃ 9999999_1_1_1    │ 9999999 │ 1           │ 1           │ 1          │ B2272674442 │ SUNGROW      │ SG5.0RS        ┃
    ┃ 9999999_22_247_1 │ 9999999 │ 22          │ 247         │ 1          │ B2272674442 │ SUNGROW      │ WiNet-S        ┃
    ┃ 9999999_7_1_1    │ 9999999 │ 7           │ 1           │ 1          │ B2272674442 │ SUNGROW      │ SG Smart Meter ┃
    ┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛
    

Meanwhile, the command run by the container (GoSungrow mqtt run) when it starts continues to run in parallel with all this activity.

When I'm done, a couple of Control-D to exit.

@Lmecano
Copy link

Lmecano commented Mar 22, 2024

Hello Paraphraser,

Good to know, may be it's because it's a RPI 3, I don't know

Thank you for the test :)

@guyserotonin
Copy link

Thank you so much @Paraphraser !
Part 2 worked a treat mate.

@igoratencompass
Copy link

@duncanjmck I'm getting the same error ERROR: unknown error 'Repeated request' both in HA and when running GoSungrow binary. Did you get to the bottom of it?

@Paraphraser
Copy link
Author

Long discussion at MickMake issue 111. No actual resolution as yet. But the more people who read/contribute, the greater the chance we will have a collective "ahah" moment.

I have never seen this issue so it's hard for me to throw my usual tools at the problem (eg tcpdump; modified image with additional instrumentation, etc).

@msmitka
Copy link

msmitka commented May 24, 2024

Hello, after reinstalling the image I log in according to the log, it also identifies the plant, the number of devices, but then it displays an error:
[09:58:32] INFO: Syncing data from gateway https://gateway.isolarcloud.eu ...
2024/05/24 09:58:32 INFO: Connecting to MQTT HASSIO Service...
2024/05/24 09:58:32 INFO: Connecting to SunGrow...
2024/05/24 09:58:32 INFO: Found SunGrow 8 devices
2024/05/24 09:58:32 INFO: Caching Sungrow metadata...
2024/05/24 09:58:34 INFO: Cached 1171 Sungrow data points...
PsId: required
JSON request: {"ps_id":5490784}
2024/05/24 09:58:35 ERROR: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax
Error: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax

Usage:
GoSungrow mqtt run [flags]

Aliases:
run,

Examples:
GoSungrow mqtt run

Flags: Use "GoSungrow help flags" for more info.

Additional help topics:

ERROR: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Thank you Michal

@Paraphraser
Copy link
Author

@msmitka I assume you mean you have reinstalled the image in Home Assistant.

If yes then please go into the Advanced SSH & Web Terminal window, run the command below, and include the output in your reply:

docker images

Ideally, whenever you include system output in anything on GitHub you put it inside "code fences" which are lines containing triple back-ticks, like this:

```
your lines of output go here
```

That makes it much easier to read.

@msmitka
Copy link

msmitka commented May 27, 2024

➜  ~ docker images
REPOSITORY                                        TAG            IMAGE ID       CREATED         SIZE
ghcr.io/home-assistant/qemux86-64-homeassistant   2024.5.5       9c8682203c2a   2 days ago      1.57GB
ghcr.io/hassio-addons/ssh/amd64                   18.0.0         e5e71eb39301   2 days ago      314MB
ba22da74/amd64-addon-gosungrow                    3.0.7-backup   c2674b5a35fc   2 days ago      118MB
homeassistant/amd64-addon-ssh                     9.14.0         5ad3fc53c047   2 weeks ago     121MB
homeassistant/amd64-hassio-supervisor             2024.05.1      d39d4f158c09   2 weeks ago     343MB
homeassistant/amd64-hassio-supervisor             latest         d39d4f158c09   2 weeks ago     343MB
ghcr.io/home-assistant/amd64-hassio-supervisor    2024.05.1      d39d4f158c09   2 weeks ago     343MB
ghcr.io/home-assistant/amd64-hassio-supervisor    latest         d39d4f158c09   2 weeks ago     343MB
ghcr.io/home-assistant/amd64-hassio-cli           2024.05.0      3e25d7e4c08d   2 weeks ago     52.5MB
ghcr.io/home-assistant/amd64-hassio-dns           2024.04.0      5c3e729cba11   7 weeks ago     58.7MB
ghcr.io/home-assistant/amd64-base                 3.16           3d5bcac5f23e   2 months ago    37.8MB
ghcr.io/home-assistant/amd64-hassio-multicast     2024.03.0      73c70d06ef84   2 months ago    42.4MB
homeassistant/amd64-addon-configurator            5.8.0          5b6b5dab6789   3 months ago    117MB
ghcr.io/hassio-addons/log-viewer/amd64            0.17.0         fd282649a2d4   4 months ago    162MB
ghcr.io/home-assistant/amd64-hassio-audio         2023.12.0      0446586f35b1   5 months ago    71.4MB
ba22da74/amd64-addon-gosungrow                    3.0.7          f2cbc9418287   5 months ago    161MB
triamazikamno/amd64-addon-gosungrow               3.0.7          f2cbc9418287   5 months ago    161MB
homeassistant/amd64-addon-mosquitto               6.4.0          e65d4ff7d911   6 months ago    209MB
ghcr.io/home-assistant/amd64-hassio-observer      2023.06.0      5a1f2299c4fa   11 months ago   7.76MB
local/amd64-addon-openvpn-client                  0.2.9          5314fb8870cc   23 months ago   411MB
ghcr.io/home-assistant/amd64-base                 latest         c350be7f2f9f   23 months ago   81.5MB

Thank you M.

@Paraphraser
Copy link
Author

Well,here's mine (pruned a bit with grep):

~ # docker images | grep -e REPOSITORY -e gosungrow
REPOSITORY                                        TAG            IMAGE ID       CREATED         SIZE
triamazikamno/amd64-addon-gosungrow               3.0.7          f2cbc9418287   5 months ago    161MB
ba22da74/amd64-addon-gosungrow                    3.0.7          f2cbc9418287   5 months ago    161MB
ba22da74/amd64-addon-gosungrow                    3.0.7-backup   2f8714749ba2   8 months ago    161MB
~ #

I'm not saying this is the explanation but I find myself wondering why the three images are more or less the same size in my case, but different in your case. The date pattern also makes sense in my case (backup being the old malfunctioning image, triamazikamno the newer working image, with the re-tag in the middle being the same age). I have not done a reinstall recently so it's possible that I'm reading too much into your dates pattern.

Look, here's what I would do. I'd go into the HA GUI and turn off GoSungrow (assuming it hasn't stopped itself) and then uninstall it.

Next, I'd go into the SSH terminal session and run docker images | grep gosungrow to see if anything has been left behind. Although I haven't tested it, I expect that you'd see at least the -backup and triamazikamno images. Using the value in the "IMAGE ID" column, run docker rmi IMAGEIDHERE and keep repeating these basic "show me the images" and "delete by ID" until there are no GoSungrow images left. Finish off with a docker system prune -f which is a general junk cleaner.

Then, go back into the HA GUI and reinstall GoSungrow. That will get you the malfunctioning image, of course. And then follow part 2 of the gist again to download triamazikamno and make it active.

@msmitka
Copy link

msmitka commented May 27, 2024

After clean all IMAGE ID with GoSungrow and only install its my size 118MB.

ba22da74/amd64-addon-gosungrow                    3.0.7-backup   c2674b5a35fc   2 days ago      118MB
triamazikamno/amd64-addon-gosungrow               3.0.7          f2cbc9418287   5 months ago    161MB
➜  ~ docker rmi c2674b5a35fc docker system prune -f                              
Untagged: ba22da74/amd64-addon-gosungrow:3.0.7-backup
Deleted: sha256:c2674b5a35fcaadf0541e50e552082425473a076b149fbd61233248a2a44c099
Deleted: sha256:577addbab744f19072d64862fbe09edc0df468ab7c166cb2f9c69e952b46b981
Deleted: sha256:2f67220303d4f7922c1f3b52f98e6ba5bb3364dd3db4a7d8a9e4d40cc14b5f11
Deleted: sha256:7552e42edfb7e61029fba358cd22fd8a3aa3ef315ae463c2fb62b0011a1528b0
Deleted: sha256:60091038b777b1dbeed909ad44efea2a61465ad224c555741e5ea12f0848a4e5
Deleted: sha256:57277f2efcf30a90647b7ac9c77a7a108352eddf1bd7d5b9f4777f67b512d720
Deleted: sha256:74135c97c72e6e3d97065d11551da8fa32ea8db4e67999282bd7c13b70f6a237
Deleted: sha256:be09d9bf4e59a64642cce667dd7b8db0cd3b89c97bd1a21c10b0660d1d257b6d
Deleted: sha256:a502485a674522a2f16ae9ed4feff9d7c02c44258ed00de28e63e5c14086fe30
Deleted: sha256:a994a37542f7f4ea569a2ae68c2f5cc4706bdbcc81e80f6eb9cc5064a4044978
Deleted: sha256:87007da81326f184839ce945267e874102b68e1edc392900a36802f132e50364
Deleted: sha256:72e7b7ce108d35115319c4c4ede21907e6dda9c8c078ffee8e1ac793ab8d8525
Deleted: sha256:07426c704c3472885124286d2d500e90bc01f3a1ba80c63fa5495cc51be2fe2a
Deleted: sha256:573dd01dee404fb91ea3cd37247234b31579341b866321b6f1c7a77348d40fd0
Deleted: sha256:5e7fcbc193c50e6c5ec6812e63db43060faed084e257f4dacae8125596a720d7
Deleted: sha256:336d28ad5b7ec13a79e34fbb23cae441ea06b1739672006484994d8931c74d2e
Deleted: sha256:04fa521fc62da873207d5add37dc28565c95bdac347d83a5a16bb4a98bbb382a
Deleted: sha256:1209c402ef9a187e1e7c52f58cc75a584fea1c00f9ff48b075d1f66db392eb0f
Deleted: sha256:fbf652db8b1ca7e8d444c95bd3230897761fe7a975f362ab6d1393180492512c
Deleted: sha256:5602cff68ebdaccaaa14b60cbe087af4d58083fba824702545e4059355f779c5
Deleted: sha256:4e76a25575354dcf01c9127a918951d4563ff972310d88327464e9c99d7826d7
Deleted: sha256:336c7ee0753034e0412b48964b0276ecdf1348b8dc492c9204803d2abda4db19
Deleted: sha256:5dfb40a4fbf9a24555a05566ec0497e409c74b909993d7b2454bd088a08e6ffa
Deleted: sha256:ee1b979afebd4be8b8d21ca42c8fee6d5a4137fe6af7307a5848c28121aef66b
Deleted: sha256:87c96d7cdcf4620d1305973b0ced44f831577ee6b3b4bead979ca56f8fdbfb84
Deleted: sha256:0267596b61e90ba093e01c6686e4bc6ce7888c6c9218c62e27c87c20397957b1
Deleted: sha256:4488a3c235a170fa098c0a82b3d17b33057c00b0795b59cd9262d4424638a9a9
Deleted: sha256:0c5c0df98afcb5c665343f1da633bdb51fa4e2bb25bb885a572c43067f1808cc
Deleted: sha256:02f5527fd08fad7abb48fb6d87015596148806d12dadaf9eb8369fc0034f3adc
Deleted: sha256:f4985c7e2a15817c4cdcb9d891057c19a6b5f23fd089db2e2b58018d7c119a7b
Deleted: sha256:150eb2bfe3ca86a0c87e5b57d9242c3b80dc4b940edec4e23484b90c8d3a5453
Deleted: sha256:0312d0ece2a584cd21358c9be1d140e40e59d50bbfd34dc032dfbb54216d7d8a
Deleted: sha256:4993bae01045f0e8203995d89dae1a6e3f65d8b495bf13b0b2156d30b2c3ea9b
Deleted: sha256:d81c457477639755325eef207bb8232dde014926f323706abe2cecf53024346a
Deleted: sha256:4a286d553f7a72c74ad1ef073ec58456e338a54440b12338fefc02ca1e81dd2b
Deleted: sha256:66b5aceedb9a9f018e6b61a032d4e6b2d0c4fabd7ea707b222f498679770cea4
Error response from daemon: No such image: docker:latest
Error response from daemon: No such image: system:latest
Error response from daemon: No such image: prune:latest
➜  ~ docker images | grep gosungrow                
triamazikamno/amd64-addon-gosungrow               3.0.7       f2cbc9418287   5 months ago    161MB
➜  ~ docker rmi f2cbc9418287 docker system prune -f
Untagged: triamazikamno/amd64-addon-gosungrow:3.0.7
Untagged: triamazikamno/amd64-addon-gosungrow@sha256:216c20966785878ccae85b48e45f31fc5e38295f04589d0b2377a7c8b564c867
Deleted: sha256:f2cbc9418287863f7137e1c3523f505eab171e8605f69156c79a41f865e6c16e
Deleted: sha256:ee04fd92a820383680d5d372c38a7599a244eb9a78f0cdba6a6cb96d594adafe
Deleted: sha256:11e8d899e8ea3d313d51c8ed2c3ca7e6654e127fe4154d1350e91e815ef25f0f
Deleted: sha256:606a734c1e3cca4925e2a9cb2678aeb906e56db8b2886843e0bae53361815da1
Deleted: sha256:353db3bc1bde1e3bb88e11f072e9ce25f67c43ecbdf1232ff43684d6690edd8c
Deleted: sha256:9506016b5a3b87b38beda0792ad8ebe49a0d9246657f8e874f60941c7ff7b9f9
Deleted: sha256:0e182002b05f2ab123995821ef14f1cda765a0c31f7a6d260221558f6466535e
Error response from daemon: No such image: docker:latest
Error response from daemon: No such image: system:latest
Error response from daemon: No such image: prune:latest
➜  ~ docker images | grep gosungrow     

in this time install new GoSungrow
           
➜  ~ docker images | grep -e REPOSITORY -e gosungrow                                    
REPOSITORY                                        TAG         IMAGE ID       CREATED         SIZE
ba22da74/amd64-addon-gosungrow                    3.0.7       f4aec31ecb07   3 minutes ago   118MB
➜  ~ 
➜  ~ 

Thanks M.
Sorry for my english

@msmitka
Copy link

msmitka commented May 27, 2024

➜  ~ docker images | grep -e REPOSITORY -e gosungrow                                    
REPOSITORY                                        TAG         IMAGE ID       CREATED         SIZE
ba22da74/amd64-addon-gosungrow                    3.0.7       f4aec31ecb07   3 minutes ago   118MB
➜  ~ 
➜  ~                                                                   
➜  ~ old_image=$(docker images | grep gosungrow | awk '{print $1 ":" $2}')
➜  ~ echo $old_image
ba22da74/amd64-addon-gosungrow:3.0.7
➜  ~ new_image=$(echo $old_image | awk -F/ '{print"triamazikamno/"$2}')
➜  ~ echo $new_image
triamazikamno/amd64-addon-gosungrow:3.0.7
➜  ~ docker tag $old_image ${old_image}-backup
➜  ~ docker images | grep -e REPOSITORY -e gosungrow
REPOSITORY                                        TAG            IMAGE ID       CREATED          SIZE
ba22da74/amd64-addon-gosungrow                    3.0.7          f4aec31ecb07   16 minutes ago   118MB
ba22da74/amd64-addon-gosungrow                    3.0.7-backup   f4aec31ecb07   16 minutes ago   118MB
➜  ~ docker pull $new_image
3.0.7: Pulling from triamazikamno/amd64-addon-gosungrow
659d66d51139: Pull complete 
7c0ba91aad39: Pull complete 
fb2a01b55562: Pull complete 
4425acca1925: Pull complete 
d50c5eb93aa0: Pull complete 
adde5526d152: Pull complete 
Digest: sha256:216c20966785878ccae85b48e45f31fc5e38295f04589d0b2377a7c8b564c867
Status: Downloaded newer image for triamazikamno/amd64-addon-gosungrow:3.0.7
docker.io/triamazikamno/amd64-addon-gosungrow:3.0.7
➜  ~ docker images | grep -e REPOSITORY -e gosungrow
REPOSITORY                                        TAG            IMAGE ID       CREATED          SIZE
ba22da74/amd64-addon-gosungrow                    3.0.7          f4aec31ecb07   17 minutes ago   118MB
ba22da74/amd64-addon-gosungrow                    3.0.7-backup   f4aec31ecb07   17 minutes ago   118MB
triamazikamno/amd64-addon-gosungrow               3.0.7          f2cbc9418287   5 months ago     161MB
➜  ~ docker tag $new_image $old_image
➜  ~ docker images | grep -e REPOSITORY -e gosungrow
REPOSITORY                                        TAG            IMAGE ID       CREATED          SIZE
ba22da74/amd64-addon-gosungrow                    3.0.7-backup   f4aec31ecb07   17 minutes ago   118MB
ba22da74/amd64-addon-gosungrow                    3.0.7          f2cbc9418287   5 months ago     161MB
triamazikamno/amd64-addon-gosungrow               3.0.7          f2cbc9418287   5 months ago     161MB
➜  ~ 

After config and start:

[06:50:57] INFO: Syncing data from gateway https://gateway.isolarcloud.eu ...
2024/05/27 06:50:57 INFO: Connecting to MQTT HASSIO Service...
2024/05/27 06:50:57 INFO: Connecting to SunGrow...
2024/05/27 06:50:58 INFO: Found SunGrow 8 devices
2024/05/27 06:50:58 INFO: Caching Sungrow metadata...
2024/05/27 06:51:03 INFO: Cached 1171 Sungrow data points...
PsId: required
JSON request:	{"ps_id":5490784}

2024/05/27 06:51:04 ERROR: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax
Error: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax
Usage:
  GoSungrow mqtt run [flags]

Aliases:
  run, 

Examples:
	GoSungrow mqtt run  


Flags: Use "GoSungrow help flags" for more info.

Additional help topics:

ERROR: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

@Paraphraser
Copy link
Author

Sorry for my english

Well, seeing as I have made no effort to learn your language, I'm extremely grateful you've made the effort to learn mine.

As to the problem, I really do not know. I thought this Atoi issue had been fixed in the triamazikamno image. But, at its core, it means what it says. A string containing an underscore has been handed to a function which expects to receive a string containing digits (and, possibly a + or - sign). The question is why? It's unlikely to be in the config so that means it's in the data coming back from iSolarCloud. You might be able to get a handle on what's going on by running GoSungrow from the command line and exploring using some of the commands (eg show ps list) that are documented on the GoSungrow GitHub repo. Other than that ... no idea. Sorry.

@msmitka
Copy link

msmitka commented May 27, 2024

Can you please guide me how to run it from the command line? A container like tao will terminate immediately after starting. If I type docker ps it is not in the listing, if I type docker ps -a in the listing it is like Exited (1) 2 hours ago.
Thanks for the guidance and help.
M.

@Paraphraser
Copy link
Author

You can try to get rid of it using "stop" and "remove":

docker stop addon_ba22da74_gosungrow
docker rm -f addon_ba22da74_gosungrow

Then try starting it again in the HA GUI. That might get you a bit further.

@Paraphraser
Copy link
Author

Can you please guide me how to run it from the command line?

The basic problem is that when the GoSungrow container starts, it launches GoSungrow (the binary inside the container) like this:

GoSungrow mqtt sync

That mqtt mode is what's crashing and, although that would be easy to avoid in a normal Docker environment, I don't know of a way of avoiding it in the Home Assistant environment.

The Home Assistant environment is tightly locked down. Although the Advanced SSH and Terminal is quite powerful, it ultimately has to obey the constraints of the Home Assistant environment.

You really need to follow one of the other parts of this gist.

If you compile GoSungrow from its source code (Part 1) or use a pre-compiled patched binary (Part 3), you will be running GoSungrow "natively" and you won't have to worry about Docker, Home Assistant or anything else.

If you try to follow Part 4 and use a pre-built Docker image outside of Home Assistant then the container will still start in mqtt mode and, if it's crashing now in Home Assistant, it will probably continue to crash outside of Home Assistant too.

However, if you find that GoSungrow running natively on another machine doesn't crash when you try to run it in mqtt mode then (a) it tells you that it's probably something about your HA environment, and (b) you will have an immediate workaround because there is nothing stopping you from running GoSungrow separately from HA and just pointing it to the MQTT broker running inside HA.

Alternatively, if you see the same (crashing) behaviour from GoSungrow when it's running natively then it tells you it's something to do with the data about your Sungrow inverter being sent to you by iSolarCloud. That's not necessarily going to lead to a fix but, as I said before, running the various GoSungrow commands may get you closer to finding just what it is that is returning that string with an underscore where a string representation of an integer is expected.

It's a real pity that MickMake has gone quiet because he's the person who understands this stuff and could probably fix it. I have no means of contacting MickMake and the longer he remains quiet, the more I fear that something might have happened to him.

@msmitka
Copy link

msmitka commented May 28, 2024

So I installed Docker for Windows on another PC according to point 4 and it behaves the same. I just connected to another MQTT.

2024-05-28 14:33:40 [12:33:40] INFO: Setting up GoSungrow config ...
2024-05-28 14:33:45 [12:33:45] INFO: Writing GoSungrow config ...
2024-05-28 14:33:45 Using config file '/data/.GoSungrow/config.json'
2024-05-28 14:33:45 New config:
2024-05-28 14:33:45 +-------------------+------------+---------------------------+--------------------------------+----------------------------------+
2024-05-28 14:33:45 |       FLAG        | SHORT FLAG |        ENVIRONMENT        |          DESCRIPTION           |       VALUE (* = DEFAULT)        |
2024-05-28 14:33:45 +-------------------+------------+---------------------------+--------------------------------+----------------------------------+
2024-05-28 14:33:45 | --config          |            | GOSUNGROW_CONFIG          | GoSungrow: config file.        | /data/.GoSungrow/config.json     |
2024-05-28 14:33:45 | --debug           |            | GOSUNGROW_DEBUG           | GoSungrow: Debug mode.         | false *                          |
2024-05-28 14:33:45 | --quiet           |            | GOSUNGROW_QUIET           | GoSungrow: Silence all         | false *                          |
2024-05-28 14:33:45 |                   |            |                           | messages.                      |                                  |
2024-05-28 14:33:45 | --timeout         |            | GOSUNGROW_TIMEOUT         | Web timeout.                   | 1m0s                             |
2024-05-28 14:33:45 | --user            | -u         | GOSUNGROW_USER            | SunGrow: api username.         | xxx         |
2024-05-28 14:33:45 | --password        | -p         | GOSUNGROW_PASSWORD        | SunGrow: api password.         | xxx                         |
2024-05-28 14:33:45 | --appkey          |            | GOSUNGROW_APPKEY          | SunGrow: api application key.  | B0455FBE7AA0328DB57B59AA729F05D8 |
2024-05-28 14:33:45 | --host            |            | GOSUNGROW_HOST            | SunGrow: Provider API URL.     | https://gateway.isolarcloud.eu   |
2024-05-28 14:33:45 | --token-expiry    |            | GOSUNGROW_TOKEN_EXPIRY    | SunGrow: last login.           | 2024-05-28T20:30:26              |
2024-05-28 14:33:45 | --save            | -s         | GOSUNGROW_SAVE            | Save output as a file.         | false *                          |
2024-05-28 14:33:45 | --dir             |            | GOSUNGROW_DIR             | Save output base directory.    |  *                               |
2024-05-28 14:33:45 | --mqtt-user       |            | GOSUNGROW_MQTT_USER       | HASSIO: mqtt username.         | mqtt                             |
2024-05-28 14:33:45 | --mqtt-password   |            | GOSUNGROW_MQTT_PASSWORD   | HASSIO: mqtt password.         | mqtt                             |
2024-05-28 14:33:45 | --mqtt-host       |            | GOSUNGROW_MQTT_HOST       | HASSIO: mqtt host.             | 192.168.100.235                  |
2024-05-28 14:33:45 | --mqtt-port       |            | GOSUNGROW_MQTT_PORT       | HASSIO: mqtt port.             |                             1883 |
2024-05-28 14:33:45 | --modbus-user     |            | GOSUNGROW_MODBUS_USER     | Modbus username.               |  *                               |
2024-05-28 14:33:45 | --modbus-password |            | GOSUNGROW_MODBUS_PASSWORD | Modbus password.               |  *                               |
2024-05-28 14:33:45 | --modbus-host     |            | GOSUNGROW_MODBUS_HOST     | Modbus host.                   |  *                               |
2024-05-28 14:33:45 | --modbus-port     |            | GOSUNGROW_MODBUS_PORT     | Modbus port.                   | 502 *                            |
2024-05-28 14:33:45 +-------------------+------------+---------------------------+--------------------------------+----------------------------------+
2024-05-28 14:33:46 [12:33:46] INFO: Login to iSolarCloud using gateway https://gateway.isolarcloud.eu ...
2024-05-28 14:33:47 Email:     xxx
2024-05-28 14:33:47 Create Date:        Tue May 21 15:10:04 CST 2024
2024-05-28 14:33:47 Login Last Date:    2024-05-28 20:34:30
2024-05-28 14:33:47 Login Last IP:
2024-05-28 14:33:47 Login State:        1
2024-05-28 14:33:47 User Account:       xxx
2024-05-28 14:33:47 User Id:    xxx
2024-05-28 14:33:47 User Name:  xxx
2024-05-28 14:33:47 Is Online:  false
2024-05-28 14:33:47 Token:      47f57dd
2024-05-28 14:33:47 Token File: /data/.GoSungrow/AppService_login.json
2024-05-28 14:33:47 [12:33:47] INFO: Syncing data from gateway https://gateway.isolarcloud.eu ...
2024-05-28 14:33:47 2024/05/28 12:33:47 INFO: Connecting to MQTT HASSIO Service...
2024-05-28 14:33:47 2024/05/28 12:33:47 INFO: Connecting to SunGrow...
2024-05-28 14:33:47 2024/05/28 12:33:47 INFO: Found SunGrow 8 devices
2024-05-28 14:33:47 2024/05/28 12:33:47 INFO: Caching Sungrow metadata...
2024-05-28 14:33:48 2024/05/28 12:33:48 INFO: Cached 1171 Sungrow data points...
2024-05-28 14:33:49 PsId: required
2024-05-28 14:33:49 JSON request:       {"ps_id":5490784}
2024-05-28 14:33:49 
2024-05-28 14:33:49 2024/05/28 12:33:49 ERROR: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax
2024-05-28 14:33:49 Error: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax
2024-05-28 14:33:49 Usage:
2024-05-28 14:33:49   GoSungrow mqtt run [flags]
2024-05-28 14:33:49 
2024-05-28 14:33:49 Aliases:
2024-05-28 14:33:49   run, 
2024-05-28 14:33:49 
2024-05-28 14:33:49 Examples:
2024-05-28 14:33:49     GoSungrow mqtt run  
2024-05-28 14:33:49 
2024-05-28 14:33:49 
2024-05-28 14:33:49 Flags: Use "GoSungrow help flags" for more info.
2024-05-28 14:33:49 
2024-05-28 14:33:49 Additional help topics:
2024-05-28 14:33:49 
2024-05-28 14:33:49 ERROR: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax
2024-05-28 14:33:49 s6-rc: info: service legacy-services: stopping
2024-05-28 14:33:49 s6-rc: info: service legacy-services successfully stopped
2024-05-28 14:33:49 s6-rc: info: service legacy-cont-init: stopping
2024-05-28 14:33:49 s6-rc: info: service legacy-cont-init successfully stopped
2024-05-28 14:33:49 s6-rc: info: service fix-attrs: stopping
2024-05-28 14:33:49 s6-rc: info: service fix-attrs successfully stopped
2024-05-28 14:33:49 s6-rc: info: service s6rc-oneshot-runner: stopping
2024-05-28 14:33:49 s6-rc: info: service s6rc-oneshot-runner successfully stopped

image

@Paraphraser
Copy link
Author

Well, at least you're now at the point where you have a basis for some further experimentation.

At this point (based on Part 4 of the Gist), you've got the container running and, even though it is crashing, it will have initialised the $HOME/GoSungrow folder. You can check that by looking for a hidden folder:

$HOME/GoSungrow/.GoSungrow

which will contain a bunch of stuff including config.json which is populated from the options.json file, albeit with different keys on the left hand side.

I have no idea why GoSungrow uses such a convoluted approach but I assume it has something to do with how the Home Assistant environment gets set up.

Because the container crashed, it will be in a kind of limbo state so it's a good idea to clean that up:

$ docker stop gosungrow
$ docker rm gosungrow

If you get any complaints from Docker, try adding -f after the rm to force the issue.

Then, unless you're trying to run Windows on ARM I'm guessing an Intel chip, so the command you ran to start the container in the first place will have been this, right?

$ docker run -d --name gosungrow --net=host \
   -v "/etc/ssl/certs:/etc/ssl/certs:ro" \
   -v "$HOME/GoSungrow:/data" \
   triamazikamno/amd64-addon-gosungrow:3.0.7

what you need is a subtle variation on that:

$ docker run -d --name gosungrow --net=host \
   -v "/etc/ssl/certs:/etc/ssl/certs:ro" \
   -v "$HOME/GoSungrow:/data" \
   triamazikamno/amd64-addon-gosungrow:3.0.7 \
   sleep 3600

That launches the container but, instead of going into MQTT mode, the container just runs that sleep command. Because it's "running" a command (as opposed to crashing) you can get into it:

$ docker exec -it gosungrow bash

and the prompt you will see is something like:

bash-5.1# 

and from here I'm going to use # to mean the system prompt inside the container

Now you can start running commands. The only "trick" is to always pass the path to the config file that GoSungrow set up the first time you ran it and it crashed. Here's an example:

# GoSungrow --config /data/.GoSungrow/config.json api login

With any luck it will log you in successfully. Then you can try:

# GoSungrow --config /data/.GoSungrow/config.json show ps list

Once you get the hang of this, take yourself to Using GoSungeow and see what you can find. Keep an eye out for evidence of the string that is causing you trouble (4050146_4050147).

It's possible that if you can collect enough evidence you can open an issue on the GoSungrow repo and maybe (just maybe) someone will be able to figure out why it is happening, and maybe (just maybe) someone with the requisite skills (eg triamazikamno) will be able to provide a patch.

Once you've finished experimenting, exit the container and clobber it:

# exit
$ docker stop gosungrow
$ docker rm gosungrow

Some more thoughts:

  1. Does Issue 107 sound like it could be the same problem? If yes then perhaps add a comment to that issue addressed to @illuzn and @copetogo to see if they made progress and, if so, how.

  2. If you wade through this post then part way down you'll find (screenshot):

    Screenshot 2024-05-29 at 10 30 41

    Reading through those linked issues (which include 107 as above) might provoke an "ahah" moment.

@msmitka
Copy link

msmitka commented May 29, 2024

Hi, so the program ends at show device list:

bash-5.1# GoSungrow --config /data/.GoSungrow/config.json show ps list
┏━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Ps Key        ┃ Ps Id   ┃ Device Type ┃ Device Code ┃ Channel Id ┃ Serial #    ┃ Factory Name ┃ Device Model ┃
┣━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┫
┃ 5490784_1_1_1 │ 5490784 │ 1           │ 1           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_7_1 │ 5490784 │ 1           │ 7           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_9_1 │ 5490784 │ 1           │ 9           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_2_1 │ 5490784 │ 1           │ 2           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_8_1 │ 5490784 │ 1           │ 8           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_6_1 │ 5490784 │ 1           │ 6           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_4_1 │ 5490784 │ 1           │ 4           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_3_1 │ 5490784 │ 1           │ 3           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┗━━━━━━━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┛

bash-5.1# GoSungrow --config /data/.GoSungrow/config.json show device list
Error: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax
Usage:
  GoSungrow show device list [flags]

Aliases:
  list, ls

Examples:
        GoSungrow show device list


Flags: Use "GoSungrow help flags" for more info.

Additional help topics:

ERROR: SetResponse: strconv.Atoi: parsing "4050146_4050147": invalid syntax
bash-5.1#

@msmitka
Copy link

msmitka commented May 29, 2024

"device_area":"4050146_4050147" In file in dir cache devicelist is:

{
	"req_serial_num":"20240528ad904f788313996e5e5e4459",
	"result_code":"1",
	"result_msg":"success",
	"result_data":{
		"pageList":[
			{
				"uuid":4061968,
				"module_uuid":4050268,
				"connect_state":0,
				"ps_id":5490784,
				"device_area":"4050146_4050147",
				"device_type":1,
				"device_sub_type":null,
				"type_name":"Inverter",
				"device_id":14,
				"device_name":"Inverter_1",
				"device_sub_type_name":null,
				"device_code":1,
				"ps_key":"5490784_1_1_1",
				"chnnl_id":1,
				"rel_state":1,
				"device_pro_sn":"A2333002091",
				"device_model_id":346857,
				"device_model":"SG50CX-P2",
				"device_model_code":"SG50CX-P2",
				"is_third_party":0,
				"is_read_set":1,
				"is_country_check":0,
				"is_reset":0,
				"factory_name":"SUNGROW",
				"device_factory_date":null,
				"is_init":1,
				"is_second":0,
				"inverter_model_type":3,
				"command_status":0,
				"p24":"0.0",
				"dev_status":"1",
				"dev_fault_status":"3",
				"installer_dev_fault_status":"3",
				"owner_dev_fault_status":"3",
				"is_replacing":0,
				"device_state":"3",
				"attr_id":504767652,
				"posx":null,
				"posy":null,
				"is_has_function_enum":1,
				"is_has_the_ability":1,
				"sn":"B2353176487",
				"data_flag":2,
				"data_flag_detail":1808
			},
			{
				"uuid":4050274,
				"module_uuid":4050268,
				"connect_state":0,
				"ps_id":5490784,
				"device_area":"4050146_4050147",
				"device_type":1,
				"device_sub_type":null,
				"type_name":"Inverter",
				"device_id":11,
				"device_name":"Inverter_2",
				"device_sub_type_name":null,
				"device_code":7,
				"ps_key":"5490784_1_7_1",
				"chnnl_id":1,
				"rel_state":1,
				"device_pro_sn":"A2333002103",
				"device_model_id":346857,
				"device_model":"SG50CX-P2",
				"device_model_code":"SG50CX-P2",
				"is_third_party":0,
				"is_read_set":1,
				"is_country_check":0,
				"is_reset":0,
				"factory_name":"SUNGROW",
				"device_factory_date":null,
				"is_init":1,
				"is_second":0,
				"inverter_model_type":3,
				"command_status":0,
				"p24":"0.0",
				"dev_status":"1",
				"dev_fault_status":"3",
				"installer_dev_fault_status":"3",
				"owner_dev_fault_status":"3",
				"is_replacing":0,
				"device_state":"3",
				"attr_id":499138546,
				"posx":null,
				"posy":null,
				"is_has_function_enum":1,
				"is_has_the_ability":1,
				"sn":"B2353176487",
				"data_flag":2,
				"data_flag_detail":1808
			},
			{
				"uuid":4050263,
				"module_uuid":4050268,
				"connect_state":0,
				"ps_id":5490784,
				"device_area":"4050146_4050147",
				"device_type":1,
				"device_sub_type":null,
				"type_name":"Inverter",
				"device_id":4,
				"device_name":"Inverter_3",
				"device_sub_type_name":null,
				"device_code":9,
				"ps_key":"5490784_1_9_1",
				"chnnl_id":1,
				"rel_state":1,
				"device_pro_sn":"A2333002043",
				"device_model_id":346857,
				"device_model":"SG50CX-P2",
				"device_model_code":"SG50CX-P2",
				"is_third_party":0,
				"is_read_set":1,
				"is_country_check":0,
				"is_reset":0,
				"factory_name":"SUNGROW",
				"device_factory_date":null,
				"is_init":1,
				"is_second":0,
				"inverter_model_type":3,
				"command_status":0,
				"p24":"0.0",
				"dev_status":"1",
				"dev_fault_status":"3",
				"installer_dev_fault_status":"3",
				"owner_dev_fault_status":"3",
				"is_replacing":0,
				"device_state":"3",
				"attr_id":499137914,
				"posx":null,
				"posy":null,
				"is_has_function_enum":1,
				"is_has_the_ability":1,
				"sn":"B2353176487",
				"data_flag":2,
				"data_flag_detail":1808
			},
			{
				"uuid":4050269,
				"module_uuid":4050268,
				"connect_state":0,
				"ps_id":5490784,
				"device_area":"4050146_4050147",
				"device_type":1,
				"device_sub_type":null,
				"type_name":"Inverter",
				"device_id":6,
				"device_name":"Inverter_4",
				"device_sub_type_name":null,
				"device_code":2,
				"ps_key":"5490784_1_2_1",
				"chnnl_id":1,
				"rel_state":1,
				"device_pro_sn":"A2333006594",
				"device_model_id":346857,
				"device_model":"SG50CX-P2",
				"device_model_code":"SG50CX-P2",
				"is_third_party":0,
				"is_read_set":1,
				"is_country_check":0,
				"is_reset":0,
				"factory_name":"SUNGROW",
				"device_factory_date":null,
				"is_init":1,
				"is_second":0,
				"inverter_model_type":3,
				"command_status":0,
				"p24":"0.0",
				"dev_status":"1",
				"dev_fault_status":"3",
				"installer_dev_fault_status":"3",
				"owner_dev_fault_status":"3",
				"is_replacing":0,
				"device_state":"3",
				"attr_id":499138495,
				"posx":null,
				"posy":null,
				"is_has_function_enum":1,
				"is_has_the_ability":1,
				"sn":"B2353176487",
				"data_flag":2,
				"data_flag_detail":1808
			},
			{
				"uuid":4050262,
				"module_uuid":4050268,
				"connect_state":0,
				"ps_id":5490784,
				"device_area":"4050146_4050147",
				"device_type":1,
				"device_sub_type":null,
				"type_name":"Inverter",
				"device_id":3,
				"device_name":"Inverter_5",
				"device_sub_type_name":null,
				"device_code":8,
				"ps_key":"5490784_1_8_1",
				"chnnl_id":1,
				"rel_state":1,
				"device_pro_sn":"A2332802067",
				"device_model_id":346857,
				"device_model":"SG50CX-P2",
				"device_model_code":"SG50CX-P2",
				"is_third_party":0,
				"is_read_set":1,
				"is_country_check":0,
				"is_reset":0,
				"factory_name":"SUNGROW",
				"device_factory_date":null,
				"is_init":1,
				"is_second":0,
				"inverter_model_type":3,
				"command_status":0,
				"p24":"0.0",
				"dev_status":"1",
				"dev_fault_status":"3",
				"installer_dev_fault_status":"3",
				"owner_dev_fault_status":"3",
				"is_replacing":0,
				"device_state":"3",
				"attr_id":499137907,
				"posx":null,
				"posy":null,
				"is_has_function_enum":1,
				"is_has_the_ability":1,
				"sn":"B2353176487",
				"data_flag":2,
				"data_flag_detail":1808
			},
			{
				"uuid":4050273,
				"module_uuid":4050268,
				"connect_state":0,
				"ps_id":5490784,
				"device_area":"4050146_4050147",
				"device_type":1,
				"device_sub_type":null,
				"type_name":"Inverter",
				"device_id":10,
				"device_name":"Inverter_6",
				"device_sub_type_name":null,
				"device_code":6,
				"ps_key":"5490784_1_6_1",
				"chnnl_id":1,
				"rel_state":1,
				"device_pro_sn":"A2332802032",
				"device_model_id":346857,
				"device_model":"SG50CX-P2",
				"device_model_code":"SG50CX-P2",
				"is_third_party":0,
				"is_read_set":1,
				"is_country_check":0,
				"is_reset":0,
				"factory_name":"SUNGROW",
				"device_factory_date":null,
				"is_init":1,
				"is_second":0,
				"inverter_model_type":3,
				"command_status":0,
				"p24":"0.0",
				"dev_status":"1",
				"dev_fault_status":"3",
				"installer_dev_fault_status":"3",
				"owner_dev_fault_status":"3",
				"is_replacing":0,
				"device_state":"3",
				"attr_id":499138539,
				"posx":null,
				"posy":null,
				"is_has_function_enum":1,
				"is_has_the_ability":1,
				"sn":"B2353176487",
				"data_flag":2,
				"data_flag_detail":1808
			},
			{
				"uuid":4050271,
				"module_uuid":4050268,
				"connect_state":0,
				"ps_id":5490784,
				"device_area":"4050146_4050147",
				"device_type":1,
				"device_sub_type":null,
				"type_name":"Inverter",
				"device_id":8,
				"device_name":"Inverter_7",
				"device_sub_type_name":null,
				"device_code":4,
				"ps_key":"5490784_1_4_1",
				"chnnl_id":1,
				"rel_state":1,
				"device_pro_sn":"A2333006570",
				"device_model_id":346857,
				"device_model":"SG50CX-P2",
				"device_model_code":"SG50CX-P2",
				"is_third_party":0,
				"is_read_set":1,
				"is_country_check":0,
				"is_reset":0,
				"factory_name":"SUNGROW",
				"device_factory_date":null,
				"is_init":1,
				"is_second":0,
				"inverter_model_type":3,
				"command_status":0,
				"p24":"0.0",
				"dev_status":"1",
				"dev_fault_status":"3",
				"installer_dev_fault_status":"3",
				"owner_dev_fault_status":"3",
				"is_replacing":0,
				"device_state":"3",
				"attr_id":499138520,
				"posx":null,
				"posy":null,
				"is_has_function_enum":1,
				"is_has_the_ability":1,
				"sn":"B2353176487",
				"data_flag":2,
				"data_flag_detail":1808
			},
			{
				"uuid":4050270,
				"module_uuid":4050268,
				"connect_state":0,
				"ps_id":5490784,
				"device_area":"4050146_4050147",
				"device_type":1,
				"device_sub_type":null,
				"type_name":"Inverter",
				"device_id":7,
				"device_name":"Inverter_8",
				"device_sub_type_name":null,
				"device_code":3,
				"ps_key":"5490784_1_3_1",
				"chnnl_id":1,
				"rel_state":1,
				"device_pro_sn":"A2333006581",
				"device_model_id":346857,
				"device_model":"SG50CX-P2",
				"device_model_code":"SG50CX-P2",
				"is_third_party":0,
				"is_read_set":1,
				"is_country_check":0,
				"is_reset":0,
				"factory_name":"SUNGROW",
				"device_factory_date":null,
				"is_init":1,
				"is_second":0,
				"inverter_model_type":3,
				"command_status":0,
				"p24":"0.0",
				"dev_status":"1",
				"dev_fault_status":"3",
				"installer_dev_fault_status":"3",
				"owner_dev_fault_status":"3",
				"is_replacing":0,
				"device_state":"3",
				"attr_id":499138505,
				"posx":null,
				"posy":null,
				"is_has_function_enum":1,
				"is_has_the_ability":1,
				"sn":"B2353176487",
				"data_flag":2,
				"data_flag_detail":1808
			}
		],
		"rowCount":11
	}
}

@Paraphraser
Copy link
Author

Hmmm...

When I search my own cache I see:

$ grep '"device_area"' *
AppService_getDeviceList-42aa5791c953124dc8c0e4bf0fe43e79.json:                         "device_area":"1367847",
AppService_getDeviceList-42aa5791c953124dc8c0e4bf0fe43e79.json:                         "device_area":"1367847",
AppService_getDeviceList-42aa5791c953124dc8c0e4bf0fe43e79.json:                         "device_area":"1367850",
AppService_queryDeviceList-42aa5791c953124dc8c0e4bf0fe43e79.json:                               "device_area":"1367847",
AppService_queryDeviceList-42aa5791c953124dc8c0e4bf0fe43e79.json:                               "device_area":"1367847",
AppService_queryDeviceList-42aa5791c953124dc8c0e4bf0fe43e79.json:                               "device_area":"1367850",

So, in my case, the values are always string representations of integers. But, I only have three devices in my show ps list, the inverter, the WiFi adapter and the (so called) smart meter. You have more. I don't know if that is significant.

@msmitka
Copy link

msmitka commented May 29, 2024

bash-5.1# GoSungrow --config /data/.GoSungrow/config.json show ps list
┏━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Ps Key        ┃ Ps Id   ┃ Device Type ┃ Device Code ┃ Channel Id ┃ Serial #    ┃ Factory Name ┃ Device Model ┃
┣━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┫
┃ 5490784_1_1_1 │ 5490784 │ 1           │ 1           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_7_1 │ 5490784 │ 1           │ 7           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_9_1 │ 5490784 │ 1           │ 9           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_2_1 │ 5490784 │ 1           │ 2           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_8_1 │ 5490784 │ 1           │ 8           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_6_1 │ 5490784 │ 1           │ 6           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_4_1 │ 5490784 │ 1           │ 4           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┃ 5490784_1_3_1 │ 5490784 │ 1           │ 3           │ 1          │ B2353176487 │ SUNGROW      │ SG50CX-P2    ┃
┗━━━━━━━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┛

bash-5.1#

@msmitka
Copy link

msmitka commented May 29, 2024

image

@Paraphraser
Copy link
Author

?

@msmitka
Copy link

msmitka commented May 30, 2024

Sorry, I misunderstood, I thought I should have sent a show ps list.
I apologize for my English.
M.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment