Using the MQTT API
Atmosphere currently supports v3.1.1 of the MQTT protocol which will allow you to send device events to Atmosphere IoT managed devices and also recieve cloud events as well.
Connecting to MQTT Server
You can simply connect with any supported MQTT client to the hostname “mqtt.atmosphereiot.com” to subscribe to and publish on MQTT topics.
Authentication will be required by passing your device’s ID as the username and the device’s token as the password to connect.
Sending Device Events
A device can send device events from your device my publishing data on the following topic.
atmosphere/events/<YOUR DEVICE ID>/device/<DEVICE EVENT ELEMENT NAME>
You can send an event along with data to all of the Device Event elements in your project by simply dropping the element name in the MQTT topic path like so
atmosphere/events/<YOUR DEVICE ID>/device
All data published to this topic will then be processed by your device’s cloud plane by triggering the “Event Recieved” on your specified Device Event Element with the data sent to this topic.
Example with mosquitto_pub
To use this example you will need to download and install the mosquitto clients from mosquitto.org
mosquitto_pub -h mqtt.atmosphereiot.com -u <DEVICE ID> -P <DEVICE TOKEN> -t atmosphere/events/<YOUR DEVICE ID>/device/<DEVICE EVENT ELEMENT NAME> -m "Data" -p 8883 --capath /etc/ssl/certs
Recieving Cloud Events
Just as before but instead of publishing to the device topic we subscribe to the cloud topic using the following topic
atmosphere/events/<YOUR DEVICE ID>/cloud/<CLOUD EVENT ELEMENT NAME>
Just like the Device Events you can remove the Cloud Event name from the path and get cloud events from all Cloud Event elements in your project like the following,
atmosphere/events/<YOUR DEVICE ID>/cloud
Example with mosquitto_sub
mosquitto_sub -h mqtt.atmosphereiot.com -u <DEVICE ID> -P <DEVICE TOKEN> -t atmosphere/events/<YOUR DEVICE ID>/cloud/<CLOUD EVENT ELEMENT NAME> -p 8883 --capath /etc/ssl/certs