This guide will demonstrate the basic use of the API Application and how one can interact with it through the mosquitto command line tool and MQTT.
This can be utilized to integrate your own finished embedded devices into Atmosphere IoT without having to use the generated firmware from Atmosphere IoT Studio. You could also use this to create your own Edge Gateway to Atmosphere IoT solution. For example, having a gateway read data from fleet of BLE devices to then register and forward data to Atmosphere IoT.
If you wish to read more about the MQTT API that is available for Atmosphere IoT, look here.
Prerequisite: You should already have an Atmosphere account.
– A computer with mosquitto installed
The first step for this guide is to create a new Atmosphere IoT Studio application of the type API Application. This API Application will give you the ability to define the behavior of the Application view as well as the Cloud without needing a specific embedded device to load firmware onto.
1. Navigate to the “Applications” section of Atmosphere IoT using the right side navigation menu
2. Click on the “New Application” icon
3. From the “Create New Application” modal, find and select the API application type, set a name for the new project. and click “Create”
You will now find your self in a new application that includes the tabs for the “Application” and the “Cloud” but does not include any embedded plane.
For this step we will begin by creating a Device Event and then storage the data that comes to the cloud as that event into a Cloud Storage. Device Events are values that are sent by a device to the cloud that can then be processed by the logic that has been defined in your Atmosphere Application.
1. Navigate in your application to the “Cloud” tab
2. From the “Element Toolbox” click on the “Device Event” element to add it to the designer area
3. From the “Element Toolbox” click on the “Cloud Storage” element to add it to the designer area
4. Drag a connector from the newly added “DeviceEvent” to the newly created “CloudStorage”
5. Save your application by pressing the save button in the top right
Your project is now ready to receive data from a Device Event and storage that data within a Cloud Storage.
Now that we have create an application, we will now want to register a device against the application you just created.
1. Navigate to devices in the left hand navigation menu.
2. At the top of the devices table you will click the add button.
3. You will need to enter a new name for the device and then select the application we created in “Step 1” and press “Create”.
4. Now copy and save the device ID and token displayed on the screen for the next step.
We will now send a device event through the Device Event Element we created in the Cloud plane of our application called “DeviceEvent” using a simple curl command.
mqtt.atmosphereiot.com -u -P -t atmosphere/events//device/DeviceEvent -m '142' -p 8883 --capath /etc/ssl/certs
The data we are sending up is the value 142 which is being encoded as JSON with the
-d option in the curl command. We can now see this data in our devices storage are and also by using dashboard widgets to display the information as well.