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.
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.
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.
git
is installed.wget
is installed.
-
Create the "go" sub-directory in your home directory:
$ mkdir -p ~/go
-
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 likedos2unix
to post-process the file.
- If you copy/paste into a Windows text editor, make sure your editor saves with Unix (
-
Open your browser at the Go downloads page.
-
Choose an appropriate image. Example:
$ URL=https://go.dev/dl/go1.21.6.linux-arm64.tar.gz $ TARGZ=$(basename $URL)
-
Also make a note of the SHA256 checksum and assign it to a variable. Example:
$ HASH=e2e8aa88e1b5170a0d495d7d9c766af2b2b6c6925a8f8956d834ad6b4cacbd9a
-
Download the image:
$ wget $URL
-
Verify the checksum:
$ shasum -a 256 -c <<< "$HASH *$TARGZ" go1.21.6.linux-arm64.tar.gz: OK
-
Install the compiler (replacing any older version):
$ sudo rm -rf /usr/local/go $ sudo tar -C /usr/local -xzf $TARGZ
- Open your browser at the Go download and install page.
- Click the "Download" button.
- 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.
See download and install page.
-
Logout and login again so the new login script commands run.
-
Confirm that GOPATH returns a sensible result:
$ echo $GOPATH /home/pi/go
-
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
-
-
Construct the following directory structure:
$ mkdir -p ~/go-projects/MickMake
-
Clone the GoUnify repository:
$ cd ~/go-projects $ git clone https://github.com/MickMake/GoUnify.git
-
Clone the GoSungrow repository:
$ cd MickMake $ git clone https://github.com/MickMake/GoSungrow.git
-
Move into the GoSungrow directory:
$ cd GoSungrow
-
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:
-
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:
-
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
-
-
Compile GoSungrow for your native architecture
$ go mod tidy $ go build
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.
$ ./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.
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.
Follow the instructions to set your iSolarCloud gateway configuration.
You can confirm everything is working by running:
$ ./GoSungrow api login
Email: [email protected]
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
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:
-
Cross-compile for 64-bit Raspberry Pi OS:
$ GOOS=linux GOARCH=arm64 go build -o GoSungrow_linux_arm64
-
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
-
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
-
Comparison with "native" compile on macOS:
$ file GoSungrow GoSungrow: Mach-O 64-bit executable x86_64
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 chipsGoSungrow-darwin-arm64
for macOS on Apple siliconGoSungrow-linux-amd64
for Linux on Intel chipsGoSungrow-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
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
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:
-
The "Advanced SSH & Web Terminal" add-on must be installed:
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.
- you need to set a username and password. This example uses "hassio" as the username. It turns up in the
-
"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".
-
-
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 [email protected]
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. -
-
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
-
-
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 fromdocker images
has turned up in the firstecho
command, and that the first part of the image name (ieba22da74
) has been replaced withtriamazikamno
in the secondecho
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.
- If you don't get sensible responses to the
-
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.
-
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.
-
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.
-
Go back to the Home Assistant GUI:
- Follow the steps to set your iSolarCloud gateway configuration.
- Follow the steps to set your APPKey configuration.
- Switch to the "Info" tab and click "START" or "RESTART" as seems appropriate.
-
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.
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:
-
Use your browser to open the following URL:
-
Scroll down to "Assets" and expand the disclosure triangle if necessary.
-
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
- macOS on Intel =
-
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. -
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. -
-
Complete the following steps from Part 1:
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.
-
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
-
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 }
-
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.
-
Save the edited JSON to the path:
$HOME/GoSungrow/options.json
-
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 -
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»
-
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 theoptions.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.
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:
- Open the Home Assistant GUI.
- Click "Settings".
- Click "Add-ons".
- Click "GoSungrow".
- Click the "Configuration" tab.
- Enter the Host URL from the table into the
sungrow_host
field. - 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", }
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:
- Open the Home Assistant GUI.
- Click "Settings".
- Click "Add-ons".
- Click "GoSungrow".
- Click the "Configuration" tab.
- Enter the APPKey from the table into the
sungrow_appkey
field. - 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", }
-
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
beforego build
.
- Move
-
2024-01-14
- Emphasise need to use
./
prefix when testing the recompiled binary. - Add short section on using GoSungrow from
~/.local/bin
.
- Emphasise need to use
-
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:- Additional step during compilation
- Update the APPKey
-
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.
After clean all IMAGE ID with GoSungrow and only install its my size 118MB.
Thanks M.
Sorry for my english