Skip to content

Commit

Permalink
Different clienids for subPower and readPrices
Browse files Browse the repository at this point in the history
  • Loading branch information
joehil committed Feb 28, 2024
1 parent 3314c8d commit 3c0ba04
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions tibber2mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,28 @@ func main() {
opts.SetDefaultPublishHandler(messagePubHandler)
opts.OnConnect = connectHandler
opts.OnConnectionLost = connectLostHandler
mclient = mqtt.NewClient(opts)
if token := mclient.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
// mclient = mqtt.NewClient(opts)
// if token := mclient.Connect(); token.Wait() && token.Error() != nil {
// panic(token.Error())
// }

// Get commandline args
if len(os.Args) > 1 {
a1 := os.Args[1]
if a1 == "readPrices" {
opts.SetClientID("tibber2mqttsingle")
mclient = mqtt.NewClient(opts)
if token := mclient.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
getTibberPrices()
os.Exit(0)
}
if a1 == "subPower" {
mclient = mqtt.NewClient(opts)
if token := mclient.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
getTibberSubUrl()
getTibberHomeId()
subTibberPower()
Expand Down Expand Up @@ -142,10 +151,10 @@ var connectLostHandler mqtt.ConnectionLostHandler = func(client mqtt.Client, err
func myUsage() {
fmt.Printf("Usage: %s argument\n", os.Args[0])
fmt.Println("Arguments:")
fmt.Println("readPrices Read prices for today and tomorrow (only available after 1pm)")
fmt.Println("subPower Subscribe to webservice to get current power consumption")
fmt.Println("readPrices Read prices for today and tomorrow (only available after 1pm)")
fmt.Println("subPower Subscribe to webservice to get current power consumption")
fmt.Println("getSubUrl Get Url to use for subscriptions")
fmt.Println("getHomeId Get ID of active home")
fmt.Println("getHomeId Get ID of active home")
}

func SortASC(a []float64) []float64 {
Expand Down

0 comments on commit 3c0ba04

Please sign in to comment.