MickMake / GoSungrow

GoLang implementation to access the iSolarCloud API updated by SunGrow inverters.
https://mickmake.com/
GNU General Public License v2.0
149 stars 43 forks source link

Error 'er_invalid_appkey' / 'Request is not encrypted' #101

Open rob3r7 opened 7 months ago

rob3r7 commented 7 months ago

Since tonight I get with https://gateway.isolarcloud.eu in HA the following error:

ERROR: appkey is incorrect 'er_invalid_appkey

Checking with https://portaleu.isolarcloud.com/ I realized that the appkey could have changed to B0455FBE7AA0328DB57B59AA729F05D8 (at least I find this key when searching for the term appkey) .

When doing a direct request at /v1/userService/login at least I don't get any more an invalid_appkey error but now an Request is not encrypted error.

When looking at the source of https://portaleu.isolarcloud.com/#/dashboard there is the following function:

e.data.set("appkey", a.a.encryptHex(e.data.get("appkey"), h))

Did Sungrow changed the API access? How to deal with this change?

jangoetz commented 7 months ago

@triamazikamno Thanks a lot for your work. Everythings works perfect now. THANK YOU!

lupus78 commented 7 months ago

@triamazikamno you are a genius, thank you very much.

franpe1984 commented 7 months ago

Thank you @triamazikamno @Paraphraser from Spain. Now it works for me too.

arekmic commented 7 months ago

works for me as well. Thanks you @triamazikamno for instruction. Question is what will happen when @MickMake comes with update GoSungrow? What will be the easy way to get it: just update or uninstall & install again?

triamazikamno commented 7 months ago

works for me as well. Thanks you @triamazikamno for instruction. Question is what will happen when @MickMake comes with update GoSungrow? What will be the easy way to get it: just update or uninstall & install again?

I believe that it will just be an update as usual. The only quirk is that it will leave the old docker images dangling, which you will need to remove manually with the docker rmi command. That is if you want to save space, they don't do anything otherwise.

chris3081 commented 7 months ago

What this highlights is there is probably a need for more than one person to have admin control against this project, assuming @MickMake is happy to do that. This would share the burden of managing the project and allow people to progress the project.

DL4DP commented 7 months ago

Hello everyone, I have read the instructions, but I don't understand some of them properly because I unfortunately lack the specialist knowledge. Can someone perhaps create a simple step-by-step guide with a screen?

I think that the path is difficult to understand if you have little knowledge like me.

Above all, almost all users around the world will face the same problem.

I find it amazing how much knowledge comes together in such a group and even finds a solution in the end, great!

Unfortunately, not all Home Assistant users are trained programmers.

Unfortunately, I don't see myself in a position to create this correctly at the moment.

If no expert can be found, I will try.

My solar system is now receiving data again, what luck!

Thanks to everyone who helped on the long road to a solution!

Thank you Dirk

loucksg commented 7 months ago

Ok, I think the code-snipped is for inside the Docker, I am trying to work out whether the Docker bits are / where they are on the GIT, will take a look and see if there is a way to script a little fix, splitting time with my MOD-RTU as I need the data for my automation and the RTU was to be secondary, however will see about split time on this weekend. Guy

gads83 commented 7 months ago

Thank you all. A little bit of head scratching but I eventually got there.

ccrrtti commented 7 months ago

Thanks a lot for the fix. It works well for me too!

AZKhalil commented 7 months ago

In the meantime, I've added my hack to the same gist in case the same approach is useful for anyone else.

Thank you @Paraphraser for that helpful gist! I have no experience with HomeAssistant, but I've managed to build, push and test docker images for the addon on all platforms, here is a simplified way to do a hack now:

  1. connect to the HA instance over ssh
  2. run:
old_image=`docker image list --format 'table {{.Repository}}:{{.Tag}}' | grep gosungrow | grep -vE 'triamazikamno|backup' | head -1`;
new_image=`echo $old_image | awk -F/ '{print"triamazikamno/"$2}'`;
docker tag $old_image ${old_image}-backup;
docker pull $new_image;
docker tag $new_image $old_image;
  1. go to the HomeAssistant GUI, Settings, Add-ons, GoSungrow, Configuration tab and change sungrow_appkey to B0455FBE7AA0328DB57B59AA729F05D8

Restart GoSungrow when it prompts.

Thanks, this worked for me too.

SCoe2k commented 7 months ago

Thanks to all contributed. Worked for me also. Hope that it will become part of 3.0.8

QUOTE:

  1. connect to the HA instance over ssh

  2. run: old_image=docker image list --format 'table {{.Repository}}:{{.Tag}}' | grep gosungrow | grep -vE 'triamazikamno|backup' | head -1; new_image=echo $old_image | awk -F/ '{print"triamazikamno/"$2}'; docker tag $old_image ${old_image}-backup; docker pull $new_image; docker tag $new_image $old_image;

  3. go to the HomeAssistant GUI, Settings, Add-ons, GoSungrow, Configuration tab and change sungrow_appkey to B0455FBE7AA0328DB57B59AA729F05D8

Restart GoSungrow when it prompts.

HACSsolaris commented 6 months ago

I wanted to rebuild GoSungrow and I also get the error: [19:20:30] INFO: Login to iSolarCloud using gateway https://gateway.isolarcloud.eu ... Error: appkey is incorrect 'er_invalid_appkey' Unfortunately I don't understand the entries with Docker. I'm hoping for a simple solution.

marioalfaro75 commented 6 months ago

In the meantime, I've added my hack to the same gist in case the same approach is useful for anyone else.

Thank you @Paraphraser for that helpful gist! I have no experience with HomeAssistant, but I've managed to build, push and test docker images for the addon on all platforms, here is a simplified way to do a hack now:

  1. connect to the HA instance over ssh
  2. run:
old_image=`docker image list --format 'table {{.Repository}}:{{.Tag}}' | grep gosungrow | grep -vE 'triamazikamno|backup' | head -1`;
new_image=`echo $old_image | awk -F/ '{print"triamazikamno/"$2}'`;
docker tag $old_image ${old_image}-backup;
docker pull $new_image;
docker tag $new_image $old_image;
  1. go to the HomeAssistant GUI, Settings, Add-ons, GoSungrow, Configuration tab and change sungrow_appkey to B0455FBE7AA0328DB57B59AA729F05D8

Restart GoSungrow when it prompts.

Thanks, this worked for me too.

Just a newbie question. Commands mentioned dont work when you go to the Terminal icon in the left menu on HA dashboard. Do you have to SSH from another machine to be able to run these commands?

AZKhalil commented 6 months ago

Yes, also you have to turn off the protected mode

Sent from Outlook for iOShttps://aka.ms/o0ukef

Ahmad Khalil IT Coordinator Email: @.*** Switchboard: Direct line: +32 2 224 06 11 +32 2 224 06 58 Fax:+32 2 224 06 06 15 Boulevard Bischoffsheim | 1000 Brussels | www.ei-ie.org Twitter: @eduint | Facebook: @educationinternational | YouTube| SoundCloud

​This message may contain privileged and confidential information intended only for the addressee(s) named above. If you are not the addressee(s) named above, you are hereby notified that any use, dissemination, distribution or reproduction of this message is prohibited. If you have received this message in error, please notify immediately. Any views expressed in this message are those of the individual sender and may not necessarily reflect the views of Education International.


From: MarsFromEarth @.> Sent: Friday, December 15, 2023 6:39:59 AM To: MickMake/GoSungrow @.> Cc: Ahmad Khalil @.>; Comment @.> Subject: Re: [MickMake/GoSungrow] Error 'er_invalid_appkey' / 'Request is not encrypted' (Issue #101)

In the meantime, I've added my hack to the same gist in case the same approach is useful for anyone else.

Thank you @Paraphraserhttps://github.com/Paraphraser for that helpful gist! I have no experience with HomeAssistant, but I've managed to build, push and test docker images for the addon on all platforms, here is a simplified way to do a hack now:

  1. connect to the HA instance over ssh
  2. run:

old_image=docker image list --format 'table {{.Repository}}:{{.Tag}}' | grep gosungrow | grep -vE 'triamazikamno|backup' | head -1; new_image=echo $old_image | awk -F/ '{print"triamazikamno/"$2}'; docker tag $old_image ${old_image}-backup; docker pull $new_image; docker tag $new_image $old_image;

  1. go to the HomeAssistant GUI, Settings, Add-ons, GoSungrow, Configuration tab and change sungrow_appkey to B0455FBE7AA0328DB57B59AA729F05D8

Restart GoSungrow when it prompts.

Thanks, this worked for me too.

Just a newbie question. Commands mentioned dont work when you go to the Terminal icon in the left menu on HA dashboard. Do you have to SSH from another machine to be able to run these commands?

— Reply to this email directly, view it on GitHubhttps://github.com/MickMake/GoSungrow/issues/101#issuecomment-1857309036, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKAOE4LOXNPT36ZYS4GWKU3YJPPC7AVCNFSM6AAAAABAAXZAJCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJXGMYDSMBTGY. You are receiving this because you commented.Message ID: @.***>

Paraphraser commented 6 months ago

@marioalfaro75

Just a newbie question. Commands mentioned dont work when you go to the Terminal icon in the left menu on HA dashboard. Do you have to SSH from another machine to be able to run these commands?

I'm a total newbie with HA too. Until this moment I wasn't aware that a "Terminal icon on the left menu" was even a possibility, and I still can't find anything that looks like that. I'd ask you for more details but that's off topic for this repo and this issue is cluttered enough already.

Bottom line, setting up the ssh add-on is the only way I've found to be able to do this kind of work.

danielsaraujo commented 6 months ago

Same error here

[13:51:50] INFO: Login to iSolarCloud using gateway https://gateway.isolarcloud.com.hk ... Error: unknown error 'Request is not encrypted' Usage: GoSungrow api login [flags] Examples: GoSungrow api login
Flags: Use "GoSungrow help flags" for more info. Additional help topics: ERROR: unknown error 'Request is not encrypted' 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

luongdaniel commented 6 months ago

Just a newbie question. Commands mentioned dont work when you go to the Terminal icon in the left menu on HA dashboard. Do you have to SSH from another machine to be able to run these commands?

I'm also having trouble with this. For some reason when I try to run those commands I'm getting an error saying "-bash: docker: command not found", and if I try to apt-get docker I get "-bash: apt-get command not found".

Fairly sure I'm completely missing something fundamental but I'm not able to get this workaround working.

Paraphraser commented 6 months ago

@luongdaniel Go here.

Step 1 tells you to install AND configure the Advanced SSH & Web Terminal.

Step 2 tells you to start from your support host (ie another computer) and SSH to your homeassistant instance.

It's the combination of those two steps that get you the privileges needed to do what has to be done.

Paraphraser commented 6 months ago

@luongdaniel

Update. I still don't know about "Terminal" in any general HA sense but if I:

  1. Install Advanced SSH & Web Terminal; and
  2. Go to Settings » Add-ons » Advanced SSH & Web Terminal » Info tab and enable "Show in sidebar",

then "Terminal" appears in the side-bar. If I click that then I get a Terminal window in the web browser. The prompt is $ (rather than #) but a whoami still says root.

If, in that Terminal window, I paste:

$ docker images | grep -e REPOSITORY -e gosungrow

I see:

Screenshot 2023-12-16 at 12 06 23

That indicates that I can run the necessary docker commands which, in turn, means I would be able to follow the rest of the steps in the gist.

I will update the gist so that this approach can be used as an alternative to using SSH from a support host.

One thing I did note is that, while I can paste into the HA Terminal window, I don't seem to be able to select snippets (strings, lines) for copying to the clipboard. I do seem to be able to do a select-all followed by a copy and then get the whole screen; just not parts of a screen. That's a bit weird.

luongdaniel commented 6 months ago
  1. Install Advanced SSH & Web Terminal; and

Thanks, that was the issue it looks like. I was using "Terminal & SSH" add on which I already had installed. The Advanced add on accepts the docker commands as expected and things are now working.

b1ackh34rt commented 6 months ago

I keep having the below issue? Network host, I left those fields blank

01:23:55] INFO: Login to iSolarCloud using gateway https://augateway.isolarcloud.com ... Email:
Create Date: Sat Aug 26 07:27:02 CST 2023 Login Last Date: 2023-12-18 09:23:56 Login Last IP:
Login State: 1 User Account:
User Id:
User Name:
Is Online: false Token: 428137_d154ee5e1c07475cad6182aaa56966a4 Token File: /data/.GoSungrow/AppService_login.json [01:23:56] INFO: Syncing data from gateway https://augateway.isolarcloud.com ... 2023/12/18 01:23:56 INFO: Connecting to MQTT HASSIO Service... 2023/12/18 01:23:56 INFO: Connecting to SunGrow... 2023/12/18 01:23:56 INFO: Found SunGrow 3 devices Error: network Error : dial tcp: lookup core-mosquitto on 127.0.0.11:53: no such host Usage: GoSungrow mqtt run [flags]

Aliases: run,

Examples: GoSungrow mqtt run

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

Additional help topics:

ERROR: network Error : dial tcp: lookup core-mosquitto on 127.0.0.11:53: no such host 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 commented 6 months ago

@b1ackh34rt it means what it says - the core-mosquitto container isn't available. Either it has never been installed or it has stopped running. The reference to 127.0.0.11:53 is the "special" IP address provided by Docker so a container (like GoSungrow) can lookup the IP address of another container running on the same host using its name (ie "core-mosquitto").

Hope this helps.

eikarramba commented 6 months ago

Hi, got the following problem

Token File: /data/.GoSungrow/AppService_login.json
[07:20:38] INFO: Syncing data from gateway https://gateway.isolarcloud.eu ...
Email:  
Create Date:    Thu Dec 14 22:27:19 CST 2023
Login Last Date:    2023-12-18 15:20:38
Login Last IP:  
2023/12/18 07:20:38 INFO: Connecting to MQTT HASSIO Service...
Error: parse "tcp://mqtt_user:mqtt_user": invalid port ":mqtt_user" after host
Login State:    1
[08:14:14] INFO: Starting mosquitto MQTT broker...
2023-12-18 08:14:14: mosquitto version 2.0.18 starting
2023-12-18 08:14:14: Config loaded from /etc/mosquitto/mosquitto.conf.
2023-12-18 08:14:14: Loading plugin: /usr/share/mosquitto/go-auth.so
2023-12-18 08:14:14: Warning: Mosquitto should not be run as root/administrator.
2023-12-18 08:14:14:  ├── Username/password checking enabled.
2023-12-18 08:14:14:  ├── TLS-PSK checking enabled.
2023-12-18 08:14:14:  └── Extended authentication not enabled.
2023-12-18 08:14:14: Opening ipv4 listen socket on port 1883.
Paraphraser commented 6 months ago

@eikarramba looks like the MQTT config in GoSungrow is wrong. Here's mine for reference.

IMG_2435

core-Mosquitto is the name of the Mosquitto add-on. 1883 is the default port that the broker (Mosquitto) listens on. The user and password fields should be whatever you set up in the config for the Mosquitto add-on.

eikarramba commented 6 months ago

i think config is ok. but it uses the name instead the port. image

eikarramba commented 6 months ago

@Paraphraser problem solved. there was a chracter (#) in the password that causes the problem.

https://github.com/MickMake/GoSungrow/issues/85

zrahash commented 6 months ago

@Paraphraser your a legend ! Thanks

b1ackh34rt commented 6 months ago

@b1ackh34rt it means what it says - the core-mosquitto container isn't available. Either it has never been installed or it has stopped running. The reference to 127.0.0.11:53 is the "special" IP address provided by Docker so a container (like GoSungrow) can lookup the IP address of another container running on the same host using its name (ie "core-mosquitto").

Hope this helps.

Hi @Paraphraser I'm not sure what that means? I'm new to HA so I'm trying to work it all out. I didn't see anything in the guide about needing this mosquitto, Is it because of the type of HA I am using? I have a Windows server running Hyper-V, HA was a VHDX image that I attached to a new VM. So I don't use containers or anything. So do I have to install mosquitto? Is that a HA add on? Thanks!

Paraphraser commented 6 months ago

@b1ackh34rt Short answer: yes!

Longer answer…

I'm also very new to HA. I have it running as a Proxmox guest but I don't use it for anything other than tinkering.

It's also well over a decade since I used Windows for anything and, even then, it was in a corporate environment where "problems" just became helpdesk tickets. Although I can surmise that "Windows server", "Hyper-V" and everything else in that sentence sounds like a Windows approximation of what I'm running with Proxmox, I can't be certain about any of it. Sorry.

Not that it makes any difference to what I'm about to say but my guess is that your HA system is indeed using Docker containers and you just haven't discovered that yet.

I agree that the installation instructions for GoSungrow rely a bit too much on "assumed knowledge".

A good example is this question of Mosquitto. I agree that is not really explained anywhere, either that you need a Mosquitto broker, or how to install one. It's simply implied.

How is it implied? It's implied anywhere you see a reference to MQTT and, in particular, under the heading of What does it do?, item 2 is "MQTT client to push to HomeAssistant".

My guess is that MickMake assumed that anyone with some Internet-of-Things background would be able to look at item 2 and reason like this:

  1. GoSungrow publishes metrics using MQTT". That, in turn, means,
  2. I will need need an MQTT broker somewhere. That, in turn, means,
  3. Home Assistant will need to subscribe to the same broker in order to receive the metrics from GoSungrow.

Of course, anyone who hasn't reached just the right point on the IoT learning-curve finds themselves up the proverbial creek.

An MQTT broker is just something which can receive and distribute messages using the MQTT protocol. The most commonly-used example of a broker is Mosquitto.

You can provide a Mosquitto broker service in a variety of ways:

  1. You can install it "natively" (ie as a system service rather than in a Docker container). I've done that on macOS and Linux. I assume it's possible for Windows.
  2. You can install it as a Docker container.
  3. You can do it as a Home Assistant "add-on".

There's no "correct" answer. There's also nothing stopping you from having multiple MQTT brokers running in your network.

However, if you're going to run GoSungrow as a Home Assistant add-on then you may as well also install Mosquitto as a Home Assistant add-on.

Hold that thought.

Think about how computers reach each other (eg a ping). You can use the IP address or a host-name or a domain name.

When two or more Docker containers run on the same host, Docker tells the containers to use 127.0.0.11 for DNS queries. Docker augments the normal recursive DNS query process so that each container is able to be reached via the container's hostname (this makes sense if you think of containers as small self-contained computers).

Although this is working backwards, if you install the Mosquitto add-on for Home Assistant and go to its "Info" tab, it will tell you its hostname is "core-mosquitto".

Which brings us to your error message:

ERROR: network Error : dial tcp: lookup core-mosquitto on 127.0.0.11:53: no such host

So, the GoSungrow add-on is trying to find the IP address of a host named core-mosquitto. Because GoSungrow is a container, the /etc/resolv.conf inside the container tells the container's resolver to send queries to port 53 on 127.0.0.11 which is the special Docker resolver that gets in between the Docker containers and the host system on which the containers are running.

The word "host" has to do a lot of work

The Mosquitto add-on container isn't running so the special Docker resolver can't answer. It forwards the query to the host system's resolver which, in turn, may forward the query elsewhere.

Ultimately, nothing can provide an answer to "what's the IP address of core-mosquitto" so the query fails and you get "no such host".

Does that make more sense?

In terms of trying to build a mental map of how it all hangs together, this diagram might help:

mqttbroker

The question that comes after this is, how do you go from HA receiving MQTT messages that are coming to it from GoSungrow via the Mosquitto broker, to the fancy charts shown in the GoSungrow doco?

🤷‍♂️

mercslkamg commented 6 months ago

Hi New to HA, but love it so far. I got a Sungrow inverter and want to add it to my Hassio

Got confused This GoLang package does several things:

  1. Provides ready access to all API calls via a simple get/put framework.
  2. MQTT client to push to [HomeAssistant

Is the MQTT client inkl or do I need to install a MQTT client ?

I am connecting to EU server is https://gateway.isolarcloud.eu/ the right link ?

Regards from a beginner happy to learn :)

mercslkamg commented 6 months ago

Same error here

[13:51:50] INFO: Login to iSolarCloud using gateway https://gateway.isolarcloud.com.hk/ ... Error: unknown error 'Request is not encrypted' Usage: GoSungrow api login [flags] Examples: GoSungrow api login Flags: Use "GoSungrow help flags" for more info. Additional help topics: ERROR: unknown error 'Request is not encrypted' 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

Key B0455FBE7AA0328DB57B59AA729F05D8

EU server

Paraphraser commented 6 months ago

@mercslkamg see this gist.

mercslkamg commented 6 months ago

Thanks Paraphraser It's a bit too advanced for me though, admittedly :) Do you think there will be an update so you can install according to previous instructions?

Regards from Sweden

Paraphraser commented 6 months ago

@mercslkamg I would like to think that one of the following will happen:

  1. MickMake will adopt the solution(s) that have been found by others (earlier posts in this issue) and publish updates. I think everyone here would agree that that would be the best outcome.
  2. Someone like triamazikamno (that's the person who has created the images that the gist relies on) will decide to take over and maintain the project. If that happens then I suspect we will be installing "GoSungrow2". triamazikamno has already said that's not a preferred solution. A lot will depend on both when and if MickMake is heard from again.

In the meantime, the only way GoSungrow can be made to work is by following the instructions in the gist.

The alternative is Modbus2MQTT. That's also mentioned in earlier comments in this issue.

As I understand it:

In both cases, Home Assistant subscribes to the MQTT topics and displays the data.

I haven't tried Modbus2MQTT but some of the earlier discussion implied it was more reliable with Ethernet-connected inverters than WiFi-connected, and I think I remember someone saying that multiple inverters were more problematic. But I may have misunderstood both sets of comments.

Either way, if you want to resume getting metrics from your Sungrow inverter, you either have to follow the gist, see if Modbus2MQTT works in your situation, or just wait and hope that another solution is found.

loucksg commented 6 months ago

Ok, given the error, and this may be further down the chain, if we add: pycryptodomex~=3.11.0 to the requirements.txt, I suspect that will load ahead of the other modules, and when testing occurs, it will go, hey I've a compatible module here... A little of kick the can down the road, but sometimes a blunt tool is appropriate, with a FBH anything can look like a nail ;-) Best

robeyl commented 6 months ago

@luongdaniel Go here.

Step 1 tells you to install AND configure the Advanced SSH & Web Terminal.

Step 2 tells you to start from your support host (ie another computer) and SSH to your homeassistant instance.

It's the combination of those two steps that get you the privileges needed to do what has to be done.

Ah!

This was my issue as well. I was using the existing Terminal & SSH addon I already had, instead of the Advanced version. I followed the rest of the guide and all is working for me again too!

mroxso commented 5 months ago

https://gist.github.com/Paraphraser/cad3b0aa6428c58ee87bc835ac12ed37#encryptionhack helped me a lot! thank you!

iuliusmaximilian commented 5 months ago

Did anyone get it fixed on a native Rasp installation (without Home Assist). I executed all patch steps but in the end I still have the error that the "Request is not encrypted" ?

Paraphraser commented 5 months ago

@iuliusmaximilian yes - in fact that's where part 1 of this gist came from. I assure you it works - I'm using it every day. All I can suggest is you retrace your steps.

iuliusmaximilian commented 5 months ago

@Paraphraser Did it once again, I executed Part 1 steps up to incl. "Update the API key", alle without any error, my result:

image
Paraphraser commented 5 months ago

@iuliusmaximilian I never know how much Unix knowledge anyone has so please forgive me if I tell you things you already know.

In your screen shot, you are:

  1. In the working directory:

    ~/go-projects/MickMake/GoSungrow
  2. Have launched GoSungrow with the command:

    $ GoSungrow

    rather than:

    $ ./GoSungrow

The gist actually has the second form. The second form (with the ./ prefix) will launch the just-compiled version from your working directory.

The first form (without the ./ prefix) will follow your search path and may easily find an old version.

Try running:

$ which -a GoSungrow
$ ls -l $(which -a GoSungrow)
$ echo $PATH

The objective is to figure out:

  1. How many instances of GoSungrow might be installed on your system;
  2. When they were compiled; and
  3. Which one is going to launch.

If #1 lists exactly one hit, and #2 doesn't have a date within the last 24 hours or so (ie when you compiled the program) then my guess is that you just didn't move the recompiled program into your search path.

If #1 has more than one hit then we need to also figure out which one is launching

Making the first form (without the ./ prefix) work involves you copying the just-recompiled binary to the "right place". It would depend on how your system is set up but, assuming your working directory is still as above and your user account is set up with the most common pattern, something like this would get the job done:

$ cp GoSungrow ~/.local/bin

If you get stuck, please show me the output from the which, ls and echo commands above and I'll try to help.


If you're wondering why the gist doesn't go into this, it's because the goal of the gist is to help you recompile a working binary. It's not to say what you should do with that binary. That's far too open-ended for me to be able to cover all the possibilities. You might be compiling on the target system. You might be cross-compiling for another system. Your intention might be to run GoSungrow from the command line. You might be building your own Docker container where the recompiled binary is one of the inputs. And so on.


Update. I changed the gist to emphasise the need for ./ and also added a short section on copying the binary into ~/.local/bin. Assuming I guessed correctly about what you were doing, I'm hoping the changes will help the next person avoid a similar trap.

iuliusmaximilian commented 5 months ago

@Paraphraser Many thanks for this comprehensive explanation, something the easy ones are the most challenging ones:

pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ which -a GoSungrow
/usr/bin/GoSungrow
/bin/GoSungrow

pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ ls -l $(which -a GoSungrow)
-rwxr-xr-x 1 10000 staff 71106560  4. Sep 06:46 /bin/GoSungrow
-rwxr-xr-x 1 10000 staff 71106560  4. Sep 06:46 /usr/bin/GoSungrow

pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin:/home/pi/go/bin:/usr/local/go/bin:/home/pi/go/bin
pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ /usr/bin/GoSungrow api login
Error: unknown error 'Request is not encrypted'
Usage:
  GoSungrow api login [flags]

Examples:
    GoSungrow api login  

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

Additional help topics:

ERROR: unknown error 'Request is not encrypted'
pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ /bin/GoSungrow api login
Error: unknown error 'Request is not encrypted'
Usage:
  GoSungrow api login [flags]

Examples:
    GoSungrow api login  

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

Additional help topics:

ERROR: unknown error 'Request is not encrypted'
iuliusmaximilian commented 5 months ago

@Paraphraser I removed everything and started from the scratch, however, after building I end up here:

pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ ls
bin           cmdHassio    defaults          DockerfileRemote.sh  EXAMPLES.md   go.sum       main.go      tablib
CHANGELOG.md  cmdModbus    Dockerfile        docs                 examples.txt  iSolarCloud  README.md    TODO.txt
cmd           config.json  DockerfileRemote  example              go.mod        LICENSE      servers.txt
pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ ./GoSungrow
-bash: ./GoSungrow: Datei oder Verzeichnis nicht gefunden
pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ 
pi@raspberrypi:~/go-projects/MickMake/GoSungrow $  which -a GoSungrow
pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ ls -l $(which -a GoSungrow)
insgesamt 256
drwxr-xr-x  2 pi pi  4096 14. Jan 08:32 bin
-rw-r--r--  1 pi pi  2020 14. Jan 08:32 CHANGELOG.md
drwxr-xr-x  2 pi pi  4096 14. Jan 08:32 cmd
drwxr-xr-x  2 pi pi  4096 14. Jan 08:32 cmdHassio
drwxr-xr-x  2 pi pi  4096 14. Jan 08:32 cmdModbus
-rw-r--r--  1 pi pi   224 14. Jan 08:32 config.json
drwxr-xr-x  2 pi pi  4096 14. Jan 08:32 defaults
-rw-r--r--  1 pi pi  1331 14. Jan 08:32 Dockerfile
-rw-r--r--  1 pi pi  1189 14. Jan 08:32 DockerfileRemote
-rwxr-xr-x  1 pi pi   869 14. Jan 08:32 DockerfileRemote.sh
drwxr-xr-x  5 pi pi  4096 14. Jan 08:32 docs
drwxr-xr-x  2 pi pi  4096 14. Jan 08:32 example
-rw-r--r--  1 pi pi 16747 14. Jan 08:32 EXAMPLES.md
-rw-r--r--  1 pi pi 19900 14. Jan 08:32 examples.txt
-rw-r--r--  1 pi pi  5188 14. Jan 08:32 go.mod
-rw-r--r--  1 pi pi 68772 14. Jan 08:32 go.sum
drwxr-xr-x 11 pi pi  4096 14. Jan 08:32 iSolarCloud
-rw-r--r--  1 pi pi 18092 14. Jan 08:32 LICENSE
-rw-r--r--  1 pi pi   200 14. Jan 08:32 main.go
-rw-r--r--  1 pi pi 45837 14. Jan 08:32 README.md
-rw-r--r--  1 pi pi   755 14. Jan 08:32 servers.txt
drwxr-xr-x  3 pi pi  4096 14. Jan 08:32 tablib
-rw-r--r--  1 pi pi  4689 14. Jan 08:32 TODO.txt
pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin:/home/pi/go/bin:/usr/local/go/bin:/home/pi/go/bin
pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ 
iuliusmaximilian commented 5 months ago

@Paraphraser I just see that the build had a "go: updates to go.mod needed; to update it: go mod tidy" - I did that and started the build once again but then I receive a error as mentioned below so in the end I think my issue is that the fixed build version is not build correctly:

pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ go build
go: downloading github.com/MickMake/GoUnify v1.0.3-0.20230904042338-0db745f1bada
go: downloading github.com/go-co-op/gocron v1.33.1
go: downloading github.com/eclipse/paho.mqtt.golang v1.4.3
go: downloading github.com/spf13/cobra v1.7.0
go: downloading github.com/spf13/viper v1.16.0
go: downloading github.com/simonvetter/modbus v1.6.0
go: downloading go.pennock.tech/tabular v1.1.3
go: downloading github.com/andreburgaud/crypt2go v1.4.0
go: downloading github.com/olekukonko/tablewriter v0.0.5
go: downloading github.com/wcharczuk/go-chart/v2 v2.1.1
go: downloading github.com/MichaelMure/go-term-markdown v0.1.4
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/ivanpirog/coloredcobra v1.0.1
go: downloading github.com/fsnotify/fsnotify v1.6.0
go: downloading github.com/mitchellh/mapstructure v1.5.0
go: downloading github.com/spf13/afero v1.9.5
go: downloading github.com/spf13/cast v1.5.1
go: downloading github.com/spf13/jwalterweatherman v1.1.0
go: downloading github.com/google/uuid v1.3.1
go: downloading github.com/robfig/cron/v3 v3.0.1
go: downloading go.uber.org/atomic v1.9.0
go: downloading github.com/gorilla/websocket v1.5.0
go: downloading golang.org/x/net v0.14.0
go: downloading golang.org/x/sync v0.1.0
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/agrison/mxj v0.0.0-20160310142625-1269f8afb3b4
go: downloading github.com/tealeg/xlsx v1.0.5
go: downloading github.com/goburrow/serial v0.1.0
go: downloading github.com/mattn/go-runewidth v0.0.15
go: downloading github.com/logrusorgru/aurora v2.0.3+incompatible
go: downloading github.com/sevlyar/go-daemon v0.1.6
go: downloading github.com/kardianos/service v1.2.2
go: downloading github.com/abiosoft/ishell/v2 v2.0.2
go: downloading github.com/briandowns/spinner v1.23.0
go: downloading github.com/blang/semver v3.5.1+incompatible
go: downloading github.com/google/go-github/v30 v30.1.0
go: downloading github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
go: downloading github.com/rhysd/go-github-selfupdate v1.2.3
go: downloading github.com/tcnksm/go-gitconfig v0.1.2
go: downloading golang.org/x/oauth2 v0.11.0
go: downloading github.com/fatih/color v1.13.0
go: downloading golang.org/x/sys v0.12.0
go: downloading golang.org/x/text v0.12.0
go: downloading github.com/MichaelMure/go-term-text v0.3.1
go: downloading github.com/alecthomas/chroma v0.7.1
go: downloading github.com/eliukblau/pixterm/pkg/ansimage v0.0.0-20191210081756-9fb6cf8c2f75
go: downloading github.com/gomarkdown/markdown v0.0.0-20191123064959-2c17d62f5098
go: downloading github.com/kyokomi/emoji/v2 v2.2.8
go: downloading github.com/subosito/gotenv v1.4.2
go: downloading github.com/hashicorp/hcl v1.0.0
go: downloading gopkg.in/ini.v1 v1.67.0
go: downloading github.com/magiconair/properties v1.8.7
go: downloading github.com/pelletier/go-toml/v2 v2.0.8
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
go: downloading golang.org/x/image v0.11.0
go: downloading github.com/rivo/uniseg v0.2.0
go: downloading github.com/fatih/structs v1.1.0
go: downloading github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db
go: downloading github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568
go: downloading github.com/mattn/go-isatty v0.0.16
go: downloading golang.org/x/term v0.11.0
go: downloading github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
go: downloading github.com/ulikunitz/xz v0.5.9
go: downloading github.com/mattn/go-colorable v0.1.13
go: downloading github.com/google/go-querystring v1.0.0
go: downloading golang.org/x/crypto v0.12.0
go: downloading github.com/dlclark/regexp2 v1.1.6
go: downloading github.com/disintegration/imaging v1.6.2
go: downloading github.com/lucasb-eyer/go-colorful v1.0.3
go: downloading github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964
**go: updates to go.mod needed; to update it:
    go mod tidy**
pi@raspberrypi:~/go-projects/MickMake/GoSungrow $ go build
# runtime/cgo
In file included from _cgo_export.c:4:
cgo-gcc-export-header-prolog:31:14: error: size of array ‘_check_for_64_bit_pointer_matching_GoInt’ is negative
Paraphraser commented 5 months ago

@iuliusmaximilian Well, as I'm sure you probably worked out from your first batch of commands, you had two copies of GoSungrow installed, both compiled on September 4 2023, neither of which was the up-to-date version. Because /usr/bin appears in your PATH before /bin, the file being executed is /usr/bin/GoSungrow.

Once you removed both of those, the $(which -a GoSungrow) inline command evaluated to a null string so that's why it showed you the entire working directory (ie ~/go-projects/MickMake/GoSungrow).


I decided to follow part 1 of the gist from scratch on a Pi4 running Bookworm. I took the opportunity to update to the latest Go compiler, and I brought all those details in the gist up-to-date as I went.

I hit the same "go mod tidy" as you did, but not the same error after that. I just got a successful compile.

I don't know enough about Go to explain why this "tidy" thing has appeared since the last time I tested the gist, nor what it means, nor why I was able to get past it and compile successfully when you could not.

What I have done is to put a log of everything I did on Pastebin. If you re-try and compare/contrast, you might be able to figure out what is going on.

Because I started on a clean(ish) system, you should probably replicate that by removing all the Go infrastructure:

$ sudo rm -rf ~/go ~/go-projects

I've noticed in the past that Go can be a bit sensitive to "old crud" so blowing everything away can often be helpful.

The key point, of course, is that I was able to compile successfully. That means it's possible. Just knowing that something is working for someone else is often half the battle.

Zesstra69 commented 5 months ago

All, this one https://gist.github.com/Paraphraser/cad3b0aa6428c58ee87bc835ac12ed37#usingNewBinary solved the initial problem of "ERROR: appkey is incorrect 'er_invalid_appkey" for me. The recompilation procedure worked also OK but no need to go there unless you are curious to understand the full story.

I'm just asking myself: if is there a way to fix the original MickMake github project so that others (less Unix / docker / Go, etc. skilled people, well, they exist right ?) falling there looking for an HA-Sungrow integration can benefit from a working solution? Well, I'm myself not that familiar with the "github way", you see ;-)

iuliusmaximilian commented 5 months ago

@Paraphraser Many thanks for the detailed feedback. I started from the scratch without success. I assume my issue has something todo with my RaspPi 4 and go 64 bit compiling as the OS is still 32 bit. I am using the go1.21.6.linux-arm64.tar.gz and my go variables are below I tried to switch to 'arm' instead but I don't get it this work. Any experience in this direction?

GO111MODULE=''
GOARCH='arm'
GOBIN=''
GOCACHE='/home/pi/.cache/go-build'
GOENV='/home/pi/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/pi/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/pi/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.21.6'
GCCGO='gccgo'
GOARM='7'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/home/pi/go-projects/MickMake/GoSungrow/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -marm -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build783683320=/tmp/go-build -gno-record-gcc-switches'
iuliusmaximilian commented 5 months ago

@Paraphraser For everyone who has the same compiling issue in Rasp. PI 4. According to https://go.dev/doc/install/source#gopath adding the lines below ~/.bashrc and ~/.profile solved the compiling issue for me, I had to run "go mod tidy" again before building and of course re-login when changing the params in the scripts.

export GOARCH=arm
export GOOS=linux
export GOHOSTARCH=arm
DanelRod commented 5 months ago

Same issue, any possible solution ?

Appkey: 3A51762ED80A39AD3DF3DB3CE6767884

https://gateway.isolarcloud.eu ... Error: unknown error 'Request is not encrypted' Usage: GoSungrow api login [flags]

Examples: GoSungrow api login

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

Additional help topics:

ERROR: unknown error 'Request is not encrypted'