Losant broker over MQTTs

@Michael_Papageorge,

Connections are unable to be made with SSL via an IP Address as the host name will not match the certificate.

You can connect to the Losant Broker via the domain broker.losant.com.

Here’s some code that I was using to test the Paho MQTT Client in Python. With this code, I am able to connect to the Losant MQTT broker via TLS.

import paho.mqtt.client as mqtt
import ssl

losant_client_id = ""
losant_username = ""
losant_password = ""
host = "broker.losant.com"

# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe("losant/" + losant_client_id + "/commands")

# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))

client = mqtt.Client(client_id=losant_client_id)
client.on_connect = on_connect
client.on_message = on_message


#set username and password
client.username_pw_set(username=losant_username, password=losant_password)

#set tls
client.tls_set(ca_certs=None, certfile=None, keyfile=None, cert_reqs=ssl.CERT_REQUIRED,
    tls_version=ssl.PROTOCOL_TLS, ciphers=None)

#connect to losant broker
client.connect(host, 8883, 60)

client.loop_forever()

Let me know if this works for you or if you have any other questions.

Thank you,
Heath