Remove unused code

This commit is contained in:
2020-01-01 21:05:49 +01:00
parent 0a3e47f001
commit 016be33296
7 changed files with 21 additions and 449 deletions

View File

@ -2,7 +2,7 @@ package cli
import (
"flag"
"github.com/cyrilix/robocar-base/mqttdevice"
"fmt"
"github.com/cyrilix/robocar-base/service"
MQTT "github.com/eclipse/paho.mqtt.golang"
"log"
@ -92,5 +92,24 @@ func InitFloat64Flag(key string, defValue float64) float64 {
}
func Connect(uri, username, password, clientId string) (MQTT.Client, error) {
return mqttdevice.Connect(uri, username, password, clientId)
//create a ClientOptions struct setting the broker address, clientid, turn
//off trace output and set the default message handler
opts := MQTT.NewClientOptions().AddBroker(uri)
opts.SetUsername(username)
opts.SetPassword(password)
opts.SetClientID(clientId)
opts.SetAutoReconnect(true)
opts.SetDefaultPublishHandler(
//define a function for the default message handler
func(client MQTT.Client, msg MQTT.Message) {
fmt.Printf("TOPIC: %s\n", msg.Topic())
fmt.Printf("MSG: %s\n", msg.Payload())
})
//create and start a client using the above ClientOptions
client := MQTT.NewClient(opts)
if token := client.Connect(); token.Wait() && token.Error() != nil {
return nil, fmt.Errorf("unable to connect to mqtt bus: %v", token.Error())
}
return client, nil
}