Skip to content

Commit

Permalink
dont assume scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveicedgreentea committed Jun 6, 2024
1 parent cabf4b1 commit 86d46b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions internal/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ var log = logger.GetLogger()

func connect(clientID string) (mqtt.Client, error) {
broker := config.GetString("mqtt.url")
opts := mqtt.NewClientOptions().AddBroker(fmt.Sprintf("tcp://%s", broker))
opts := mqtt.NewClientOptions().AddBroker(fmt.Sprintf("%s", broker))
opts.SetClientID(clientID)
opts.SetUsername(config.GetString("mqtt.username"))
opts.SetPassword(config.GetString("mqtt.password"))

c := mqtt.NewClient(opts)
token := c.Connect()
if !token.WaitTimeout(5*time.Second) {
if !token.WaitTimeout(5 * time.Second) {
return nil, fmt.Errorf("timeout when connecting to mqtt broker")
}

if token.Error() != nil {
return nil, token.Error()
}
Expand All @@ -38,7 +38,7 @@ func PublishWrapper(topic string, msg string) error {

// creates a connection to broker and sends the payload
func Publish(payload []byte, topic string) error {
if ! config.GetBool("mqtt.enabled") {
if !config.GetBool("mqtt.enabled") {
log.Debugf("MQTT is disabled, skipping publish to topic %v", topic)
return nil
}
Expand Down Expand Up @@ -70,8 +70,8 @@ func Publish(payload []byte, topic string) error {
// if this doesnt return true, it timed out
if !token.WaitTimeout(10 * time.Second) {
timeoutErr := fmt.Errorf("timeout when waiting for mqtt token")
log.Warning(timeoutErr.Error())
lastErr = timeoutErr
log.Warning(timeoutErr.Error())
lastErr = timeoutErr
continue
}

Expand Down
4 changes: 2 additions & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ <h2>MQTT</h2>
<div>
<label for="mqtt-url">MQTT URL with port
<span class="description">
URL - "tcp://x.x.x.x:1883" <- Must have tcp:// or equivalent schema </span>
URL - "tcp://x.x.x.x:1883" <- Must have tcp:// or equivalent scheme </span>
</label>

<input type="text" id="mqtt-url" name="mqtt.url" placeholder="http://x.x.x.x:1883">
<input type="text" id="mqtt-url" name="mqtt.url" placeholder="tcp://x.x.x.x:1883">
</div>
<div>
<label for="mqtt-username">Username
Expand Down

0 comments on commit 86d46b0

Please sign in to comment.