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

Small programmatic example #14

Open jpillora opened 1 year ago

jpillora commented 1 year ago

From an existing Go program, I'd like to get my current Sungrow inverter's current kw/hr output. I could use the binary and run a shell script, though it'd be awesome if I could call a function in my Go program. Is there a small example of this?

This is what I've tried, but it crashes

package main

import (
    "GoSungrow/iSolarCloud"
    "GoSungrow/iSolarCloud/AppService/login"
    "log"
)

func main() {
    sg := iSolarCloud.NewSunGro("https://augateway.isolarcloud.com", "/tmp/")
    if err := sg.Login(login.SunGrowAuth{
        UserAccount:  "MY_EMAIL",
        UserPassword: "MY_PASSWORD",
    }); err != nil {
        log.Fatal(err)
    }
    ep := sg.GetEndpoint("queryDeviceList")
    rargs := ep.GetRequestArgNames()
    log.Printf("args:%s\n", rargs)
    // var request iSolarCloud.SunGrowDataRequest
}
MickMake commented 1 year ago

I'm in the middle of doing a major rewrite - adding that feature wouldn't be too hard. So I'll tack it on to the end of release 2.0.0.

But if you're impatient - you'll need to follow:

Note, you'll need to Assert the endpoint to be able to see the locally scoped data within the endpoint interface.

data := queryMutiPointDataList.Assert(ep)
data.GetData()
table := data.GetPointDataTable(pointNames)

But, once again... major rewrite happening which will be completed in the next couple of days. So some things may have broken.

MickMake commented 1 year ago

BTW... I recently found a new endpoint which returns static data on what data points are supported for your device.

GoSungrow data table WebIscmAppService.modelPointsPage DeviceModelId:714 DeviceType:14