Connection and authentication
Please use the following information to connect to our Cloud MQTT broker:
- Host : iot.nao-cloud.com
- Port : 8883
- Protocol: MQTTS (TLS v1.2)
- Client ID: can be empty or random string
- Amazon Root CA: https://www.amazontrust.com/repository/
- Keep alive: 60s or lower
- Certificate file and private X.509 file: contact us for the certificates or generate them yourself if you have access. Usually, one certificate is used to access the API for one site. Every information about the tags and infrastructure of the site can be retrieved with that certificate. The certificate contains the following files:
- root-ca.pem,
- certificate-<API_Key>.pem (the certificate itself)
- private-<API_Key>.pem (the private key)
- The API Key can be found and managed in NAO Cloud in the following page: Left menu of your site > Developers > API Keys
Sample code for connection in Python:
2 | import paho.mqtt.client as paho |
5 | mqttc.tls_set( None , certfile = CERTIFICATE_PATH, keyfile = PRIVATE_KEY_PATH, |
6 | cert_reqs = ssl.CERT_REQUIRED, tls_version = ssl.PROTOCOL_TLSv1_2, ciphers = None ) |
7 | mqttc.on_connect = on_connect |
8 | mqttc.on_disconnect = on_disconnect |
9 | mqttc.connect(MQTT_ENDPOINT, MQTT_PORT, keepalive = 60 ) |
If the authentication fails, the on_disconnect callback will be called with a return code (1). Once connected, you can subscribe to topics in order to receive MQTT messages.
If you need to use the REST API, refer to the Authentication article for REST API.
For NAO Server integrations, implementation can be the same, with the following differences:
- Host: TRACKING_MQTT_EXTERNAL_ENDPOINT value from .env file
- Keep alive: 30s or lower
- Authentication: username/password
- Username: TRACKING_MQTT_EXTERNAL_USERNAME value from .env file
- Password: TRACKING_MQTT_EXTERNAL_PASSWORD value from .env file
MQTT QoS
MQTT provides three levels of QoS but we only support QoS 1 and 2:
- At most once (QoS 0)
- At least once (QoS 1)
- Exactly once (QoS 2) NOT SUPPORTED
Use QoS 0 when:
- You have a completely or mostly stable connection between sender and receiver. A classic use case for QoS 0 is connecting a test client or a front end application to an MQTT broker over a wired connection.
- You don’t mind if a few messages are lost occasionally. The loss of some messages can be acceptable if the data is not that important or when data is sent at short intervals
Use QoS 1 when:
- You need to get every message and your use case can handle duplicates. QoS level 1 is the most frequently used service level because it guarantees the message arrives at least once but allows for multiple deliveries. Of course, your application must tolerate duplicates and be able to process them accordingly.
Related Articles
2. Authentication
NAO Cloud API supports three types of authentication: API key, JWT and Oauth2. For API requests from frontend applications that run in the web browsers, JWT is the recommended authentication method and API key was the preferred authentication method ...
Oauth2 authentication
NAO Cloud can act as an Oauth2 resource and authorization server. Overview The benefits of Oauth2 authentication is two-fold: Users log in once on NAO Cloud, and automatically get logged-in to your site Your site gets an access token to authenticate ...
Location API
Overview Location API can be used to receive location information about all tags of a given site. Once subscribed to a topic, your application will receive MQTT messages. Each message contains a topic and a payload. Refer ot the “Connection and ...
Sample code
We supply a .zip file with the X509 certificate for authentication, alongside a sample Python script (referenced below) that illustrates how to connect to the API and obtain information. Please modify it as necessary (such as changing the certificate ...
Overview
We supply a .zip file with the X509 certificate for authentication, alongside a sample Python script (referenced below) that illustrates how to connect to the API and obtain information. Please modify it as necessary (such as changing the certificate ...