MQTT

MQTT #

Broker specification:

  • MQTT v3.1.1
  • QoS 0 and 1

Connection details:

  • Host: api.nr.iotready.no
  • Uses TLS with CA-signed certificate
  • TLS secured Port: 8883
  • Username: X-API-Key
  • Password: your api key
  • Topic prefix required: v1

Topics:

  • v1/upstream: Messages

Example:

mosquitto_sub -v \
    -L "mqtts://X-API-Key:<api key>@api.nr.iotready.no/v1/upstream/#"
import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
    client.subscribe("v1/upstream/#")

def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))

client = mqtt.Client()
client.username_pw_set("X-API-Key", "<api key>")
client.on_connect = on_connect
client.on_message = on_message
client.tls_set()
client.connect("api.nr.iotready.no", 8883)
client.loop_forever()
package main

import (
	"fmt"

	mqtt "github.com/eclipse/paho.mqtt.golang"
)

func main() {
	opts := mqtt.NewClientOptions().
		AddBroker("tls://api.nr.iotready.no:8883").
		SetUsername("X-API-Key").
		SetPassword("<api key>")
	client := mqtt.NewClient(opts)
	if t := client.Connect(); t.Wait() && t.Error() != nil {
		panic(t.Error())
	}
	client.Subscribe("v1/upstream/#", 1, func(_ mqtt.Client, msg mqtt.Message) {
		fmt.Println(msg.Topic(), string(msg.Payload()))
	})
	select {}
}

Note: mosquitto_sub might need the –capath option for reliable operation Especially on reconnect this might cause reconnect problems: Typical linux use: --capath /etc/ssl/certs