Datacake
Last updated
Last updated
To record the measurements to a specific Database Field of a Device, we will update the MQTT publish topics as follows: This section covers how to create your first device on Datacake and connect the Conexio Stratus running ZephyrRTOS to the Datacake platform via MQTT broker. MQTT is a lightweight publish/subscribe messaging protocol designed for low-bandwidth IoT devices.
Furthermore, the sample application used for this tutorial also demonstrates how to fetch the important Conexio Stratus device vitals such as the battery voltage, LTE signal strength, firmware version, device IMEI, and environmental data.
This tutorial assumes that one has already installed and set up the nRF Connect SDK, the main toolchain required for building and compiling applications for the Stratus device. If not, please refer to this section. So let’s dive in.
Register and create a user account on the Datacake platform here. Your first two devices are free.
Before any measurement readings can be stored via MQTT, we will need to set up a device on the Datacake platform. After registration and account activation, head over to the fleet view of your Datacake workspace.
Click Add Device in the upper right corner which will bring up the following pop-up window.
In STEP 1, select the device type as “API”, and under Datacake Product choose New Product. Then assign a name to your device under “Product Name”. For this tutorial, we named our product to be “Conexio Stratus”.
In STEP 2, you can add one or more API devices. Next, assign the device name and hit Next.
Finally, in STEP 3, choose the Datacake plan. To create a device it is necessary to choose a payment plan. Since Datacake allows you to create up to two devices for free, you can choose the “Free” plan and click “Add 1 device”.
Hooray! Your device has now been registered to the Datacake platform and should appear under devices in the “Fleet” view. Click on your registered device and it will take you to its workspace.
All right. At this point, we need to define fields in the database of the device, which will host the measured values that are sent from the Stratus device via MQTT. You can read more about the Datacake fields and types here.
In the Datacake, navigate to the “Configuration” tab and scroll down to the Fields section and click the “Add Field” button.
This will open a modal with a variety of data types. For this tutorial, we will add multiple fields starting with the temperature of type “Float”. The Datacake will automatically fill in the “identifier” field. See the snippet below for details.
Once the field details are complete, click “Add Field” and you’re done with this field. Below you will see all the different fields we have added for this sample application. These fields include:
RSRP: the LTE signal strength value
Battery: for recording the voltage of the connected LiPo battery
IMEI: the Conexio Stratus International Mobile Equipment Identity (IMEI) number
Version: Firmware version running on the device
Temperature: environmental temperature readings from the SHT40 sensor
Humidity: relative humidity readings from the SHT40 sensor
Next, just below the Fields section, you will find the Integrations section. For forwarding data from your devices via MQTT, a connection to Datacake must be established. Click Configure and the MQTT Integration information window will pop up.
The Datacake platform offers an MQTT broker with TLS encryption, which allows both subscription and recording of data. With the help of this broker, you can:
Forward incoming device data to external services via MQTT
Store data via MQTT into the Datacake Cloud
For recording measurements into the Datacake Cloud, we will publish the data to the respective topic structure as shown in the MQTT Integration window.
Copy the above broker name and the topic which we will use later in our firmware configuration.
The MQTT topic prefix for Datacake follows the following structure:
dtck-pub/<product_slug>/<device_id>/<field_name>
Head over to Datacake’s MQTT documentation to read more about this structure. The last element in the topic structure is the field name of the measured value, as it appears in the database field that we created earlier above. The field (identifier) is where we will publish different measurements from the Stratus device.
To view your access token, click “Show”. Now copy this access token in a safe place as we will need it later.
At this point, we have all the required details to connect and publish data from our Conexio Stratus device to the Datacake. Let’s now head over to the device firmware side.
We have extended the sample MQTT application provided in the nRF Connect SDK to easily connect the Stratus kit to the MQTT broker, send, and receive data from the Datacake platform.
The extended sample application connects to the Datacake and publishes the data to the configured publish topic. On a button press event, the application publishes the device vitals to the Datacake and periodically publishes the environmental data such as temperature and humidity.
The full application can be found in the conexio-stratus-firmware repo on GitHub.
First, we will have to add the Datacake access token to the application code. You will need to edit conexio_stratus_firmware/samples/datacake/prj.conf
with your Datacake access token. Update the following parameters.
The username and password are the same.
Next, we need to configure the MQTT broker hostname and the port. Update the Datacake broker configuration with the following:
We will be using Port 8883 which uses a CA-signed server certificate.
To record the measurements to a specific Database Field of a Device, we will update the MQTT publish topics as follows:
For instance, with the Product-Slug my-product, the Device-ID 6b98a3bb-9ae1-418f-9375-f23091a849cd, and the Field-Identifier TEMPERATURE
, will publish a message to:
dtck-pub/my-product/6b98a3bb-9ae1-418f-9375-f23091a849cd/TEMPERATURE
The payload will hold the value which you want to be recorded into that specific database-Field.
publish("dtck-pub/my-product/6b98a3bb-9ae1-418f-9375-f23091a849cd/TEMPERATURE", 25.00)
Now we are all set in terms of the MQTT parameter configurations.
To compile the application, open a terminal window in the application directory and issue the following west
command
Once the application is compiled successfully, connect the Stratus device and put it into the DFU mode.
Flash the compiled firmware using newtmgr:
Open up a serial console and reset the Stratus device. The following serial UART output will be displayed in the terminal. If you are connecting your Stratus device for the first time, give it a few minutes to register to the network and establish the LTE connection with the tower. No extra SIM activations are required as the Stratus device comes preconfigured for automatically connecting to the LTE network.
Once the LTE connection is established, you will notice that the Stratus connects to the Datacake MQTT broker after which it publishes the sensor data to the configured topics. Your Stratus device is now ALIVE and communicating to the Datacake cloud 🎉.
Head back to the Datacake dashboard and add graphical widgets to your workspace.
You will now see the device data flowing into the Datacake and beautiful graphs being populated. Below is the sample dashboard that we have created. Fast and Simple!