Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
leroxyl committed Oct 23, 2019
1 parent a28cb8d commit 26b7c20
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions c8y/c8y_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package c8y
import (
"bytes"
"encoding/json"
"github.com/eclipse/paho.mqtt.golang"
"io/ioutil"
"log"
"net/http"
"os"
"time"
)
import MQTT "github.com/eclipse/paho.mqtt.golang"

func BootstrapHTTP(uuid string, tenant string, password string) map[string]string {
log.Println("Bootstrapping")
Expand Down Expand Up @@ -62,7 +62,7 @@ func BootstrapHTTP(uuid string, tenant string, password string) map[string]strin
}
}

func GetClient(uuid string, tenant string, bootstrapPW string) (MQTT.Client, error) {
func GetClient(uuid string, tenant string, bootstrapPW string) (mqtt.Client, error) {
var deviceCredentials map[string]string
// check for device credentials file
credentialsFilename := uuid + ".ini"
Expand Down Expand Up @@ -99,7 +99,7 @@ func GetClient(uuid string, tenant string, bootstrapPW string) (MQTT.Client, err

// initialize MQTT client
address := "tcps://" + tenant + ".cumulocity.com:8883/"
opts := MQTT.NewClientOptions().AddBroker(address)
opts := mqtt.NewClientOptions().AddBroker(address)
opts.SetClientID(uuid)
opts.SetUsername(tenant + "/" + deviceCredentials["username"])
opts.SetPassword(deviceCredentials["password"])
Expand All @@ -108,13 +108,13 @@ func GetClient(uuid string, tenant string, bootstrapPW string) (MQTT.Client, err
c8yReady := make(chan bool)

// callback for error messages
receive := func(client MQTT.Client, msg MQTT.Message) {
receive := func(client mqtt.Client, msg mqtt.Message) {
answer := string(msg.Payload())
log.Println("received error message: " + answer)
}

// configure OnConnect callback: subscribe to error messages when connected
opts.OnConnect = func(c MQTT.Client) {
opts.OnConnect = func(c mqtt.Client) {
log.Println("MQTT client connected.")

// subscribe to error messages
Expand All @@ -132,7 +132,7 @@ func GetClient(uuid string, tenant string, bootstrapPW string) (MQTT.Client, err
}

// create client and connect
client := MQTT.NewClient(opts)
client := mqtt.NewClient(opts)
if token := client.Connect(); token.Wait() && token.Error() != nil {
return nil, token.Error()
}
Expand All @@ -146,7 +146,7 @@ func GetClient(uuid string, tenant string, bootstrapPW string) (MQTT.Client, err
}
}

func Send(c MQTT.Client, valueToSend bool) error {
func Send(c mqtt.Client, valueToSend bool) error {
log.Println("sending...")
var message string
if valueToSend {
Expand Down

0 comments on commit 26b7c20

Please sign in to comment.