HomeAssistantAddons
HomeAssistantAddons copied to clipboard
GoSungrow mqtt run generates "panic: runtime error: invalid memory address or nil pointer dereference"
Hi Mick,
GoSungrow looks awesome.
I have the same problem that you had - I am trying to get my Sungrow SH5K-20 inverter integrated in Home Assistant.
I managed to get GoSungrow to connect to the iSolarCloud API and report data back using standalone GoSungrow.
When I tried though to get it working in HomeAssistant, it fails at the GoSungrow mqtt run
stage with the error stack below, which I got by running manually the docker entrypoint script inside the docker container.
The MQTT integration works fine with the same parameters (host, user, pass) that are used by the GoSungrow add-on.
I have no experience with golang, so it's a bit tricky to even attempt to debug the panic error below - it sounds like it's a variable that's supposed to have a non-nil value and it's nil, but I'm not quite sure which one is that. The panic seems to be triggered by a call to the GetValue function defined here: (https://github.com/MickMake/GoSungrow/blob/master/iSolarCloud/api/GoStruct/struct_reflect.go#L984) called from somewhere around here: (https://github.com/MickMake/GoSungrow/blob/master/iSolarCloud/AppService/queryDeviceList/data.go#L427) but the line in data.go is not the one that's in the error stack, since there is no GetValue call on line 434 in the current commit of the repo. This raises the question of which exactly is the commit of GoSungrow that is used to generate the docker image that is deployed by the add-on and I don't know the answer to that question either. This also means that even if I can add some code to avoid processing nil pointers, I don't know how to generate a new docker image with that code.
Since you mention in the README that the API changes occasionally, it could be a result of such a change. It could also be a result of a badly configured or defective inverter, which doesn't report properly certain values. I noticed that even in iSolarCloud, the "load" values are sometimes absent, sometimes they show up for a while, so the report is very confusing, which is one of the reasons I want to get away from it. Unfortunately, GoSungrow still relies on the data that is reported by the iSolarCloud API, so the GIGO principle will make this data useless.
Can you have a look and see if there's any obvious culprit, so I can at least get some data in HomeAssistant, even if it's missing some values (e.g. the load)? Thanks, Razvan
bash-5.1# /usr/local/bin/run.sh
[07:50:03] INFO: Setting up GoSungrow config ...
[07:50:08] INFO: Writing GoSungrow config ...
Using config file '/data/.GoSungrow/config.json'
New config:
+-----------------+------------+-------------------------+--------------------------------+-----------------------------------+
| FLAG | SHORT FLAG | ENVIRONMENT | DESCRIPTION | VALUE (* = DEFAULT) |
+-----------------+------------+-------------------------+--------------------------------+-----------------------------------+
| --config | | GOSUNGROW_CONFIG | GoSungrow: config file. | /data/.GoSungrow/config.json |
| --debug | | GOSUNGROW_DEBUG | GoSungrow: Debug mode. | false * |
| --quiet | | GOSUNGROW_QUIET | GoSungrow: Silence all | false * |
| | | | messages. | |
| --timeout | | GOSUNGROW_TIMEOUT | Web timeout. | 1m0s |
| --user | -u | GOSUNGROW_USER | SunGrow: api username. | [email protected] |
| --password | -p | GOSUNGROW_PASSWORD | SunGrow: api password. | my_password |
| --appkey | | GOSUNGROW_APPKEY | SunGrow: api application key. | 93D72E60331ABDCDC7B39ADC2D1F32B3 |
| | | | | * |
| --host | | GOSUNGROW_HOST | SunGrow: Provider API URL. | https://augateway.isolarcloud.com |
| | | | | * |
| --token-expiry | | GOSUNGROW_TOKEN_EXPIRY | SunGrow: last login. | 2023-05-24T15:46:39 |
| --save | -s | GOSUNGROW_SAVE | Save output as a file. | false * |
| --mqtt-user | | GOSUNGROW_MQTT_USER | HASSIO: mqtt username. | mqtt_user |
| --mqtt-password | | GOSUNGROW_MQTT_PASSWORD | HASSIO: mqtt password. | mqtt_pass |
| --mqtt-host | | GOSUNGROW_MQTT_HOST | HASSIO: mqtt host. | my_mqtt_host_ip |
| --mqtt-port | | GOSUNGROW_MQTT_PORT | HASSIO: mqtt port. | 1883 |
+-----------------+------------+-------------------------+--------------------------------+-----------------------------------+
[07:50:08] INFO: Login to iSolarCloud using gateway https://augateway.isolarcloud.com ...
Email: [email protected]
Create Date: Sat Jun 18 15:10:39 CST 2022
Login Last Date: 2023-05-24 15:50:08
Login Last IP:
Login State: 1
User Account: xxxxxxxxxxx
User Id: xxxxxxx
User Name: xxxxxxx
Is Online: false
Token: xxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Token File: /data/.GoSungrow/AppService_login.json
[07:50:08] INFO: Syncing data from gateway https://augateway.isolarcloud.com ...
2023/05/24 07:50:09 INFO: Connecting to MQTT HASSIO Service...
2023/05/24 07:50:09 INFO: Connecting to SunGrow...
2023/05/24 07:50:09 INFO: Found SunGrow 1 devices
2023/05/24 07:50:09 INFO: Caching Sungrow metadata...
2023/05/24 07:50:09 INFO: Cached 227 Sungrow data points...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6d2c9f]
goroutine 1 [running]:
GoSungrow/iSolarCloud/api/GoStruct.(*Reflect).GetValueFloat(0x0)
/Users/mick/Documents/GoLang/Solar/GoSungrow/iSolarCloud/api/GoStruct/struct_reflect.go:984 +0x7f
GoSungrow/iSolarCloud/AppService/queryDeviceList.(*EndPoint).SetPvPoints(_, {{_, _, _}}, {0xc0006dfc80, {0xc0006ddd57, 0x7}, {0xc1138e4c42b2d296, 0x2ee5af8, 0x48d4da0}, ...})
/Users/mick/Documents/GoLang/Solar/GoSungrow/iSolarCloud/AppService/queryDeviceList/data.go:434 +0xcaf
GoSungrow/iSolarCloud/AppService/queryDeviceList.(*EndPoint).GetEnergyStorageSystem(_, {0xc0006dfc80, {0xc0006ddd57, 0x7}, {0xc1138e4c42b2d296, 0x2ee5af8, 0x48d4da0}, {{0xc0006cc100, 0x2, 0x2}}, ...})
/Users/mick/Documents/GoLang/Solar/GoSungrow/iSolarCloud/AppService/queryDeviceList/data.go:299 +0x3b5
GoSungrow/iSolarCloud/AppService/queryDeviceList.(*EndPoint).GetData(_)
/Users/mick/Documents/GoLang/Solar/GoSungrow/iSolarCloud/AppService/queryDeviceList/data.go:259 +0xb8
GoSungrow/iSolarCloud/AppService/queryDeviceList.EndPoint.GetEndPointData(...)
/Users/mick/Documents/GoLang/Solar/GoSungrow/iSolarCloud/AppService/queryDeviceList/struct.go:367
GoSungrow/iSolarCloud.(*SunGrowData).CallEndpoint(_, {_, _}, {{0xc0006de9f0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...}, ...})
/Users/mick/Documents/GoLang/Solar/GoSungrow/iSolarCloud/data.go:161 +0x433
GoSungrow/iSolarCloud.(*SunGrowData).getDataSinglePsIdRequired(0xc000b8f488, {0x2f0ebd0, 0xc00036d500})
/Users/mick/Documents/GoLang/Solar/GoSungrow/iSolarCloud/data.go:281 +0x325
GoSungrow/iSolarCloud.(*SunGrowData).GetDataSingle(0xc000b8f488, {0xc000427150, 0xf})
/Users/mick/Documents/GoLang/Solar/GoSungrow/iSolarCloud/data.go:236 +0x14f
GoSungrow/iSolarCloud.(*SunGrowData).GetData(0xc000b8f488)
/Users/mick/Documents/GoLang/Solar/GoSungrow/iSolarCloud/data.go:207 +0x125
GoSungrow/cmd.(*CmdMqtt).Cron(0xc0000b0750)
/Users/mick/Documents/GoLang/Solar/GoSungrow/cmd/cmd_mqtt.go:368 +0x2b7
GoSungrow/cmd.(*CmdMqtt).CmdMqttRun(0xc0000b0750, 0x0?, {0x0?, 0x0?, 0x0?})
/Users/mick/Documents/GoLang/Solar/GoSungrow/cmd/cmd_mqtt.go:266 +0x85
github.com/spf13/cobra.(*Command).execute(0xc0002d8900, {0xc00018e170, 0x0, 0x0})
/Users/mick/go/pkg/mod/github.com/spf13/[email protected]/command.go:916 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc000118000)
/Users/mick/go/pkg/mod/github.com/spf13/[email protected]/command.go:1044 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
/Users/mick/go/pkg/mod/github.com/spf13/[email protected]/command.go:968
github.com/MickMake/GoUnify/Unify.(*Commands).Execute(...)
/Users/mick/go/pkg/mod/github.com/!mick!make/!go!unify/[email protected]/struct.go:258
github.com/MickMake/GoUnify/Unify.(*Unify).Execute(0xc0000bcb40)
/Users/mick/go/pkg/mod/github.com/!mick!make/!go!unify/[email protected]/struct.go:201 +0x385
GoSungrow/cmd.Execute(...)
/Users/mick/Documents/GoLang/Solar/GoSungrow/cmd/commands.go:90
main.main()
/Users/mick/Documents/GoLang/Solar/GoSungrow/main.go:11 +0x6f