Temperature reading in buildings can be a major issue for heating specialists, social landlords, or even for homeowners to ensure a constant and regularly controlled temperature in housing. A properly managed indoor climate can guarantee a pleasant environment for the user and help save energy.
This tutorial demonstrates how to
- create your own IoT-based weather data dashboard for free.
- create your first device on Datacake and connect the Conexio Stratus running ZephyrRTOS to the Datacake platform via MQTT broker.
- assemble the required hardware.
- fetch the important environmental data from the BME280 sensor using the Conexio Stratus device and other vitals such as the battery voltage, LTE signal strength, firmware version, and device IMEI and push it to the cloud.
- visualize and track your environment data from anywhere in the world.
Why Cellular And Why the Conexio Stratus kit?
Wi-Fi service might not be the most reliable and even not an option in some places for users. For instance, if you want to monitor and deploy a sensor device in the middle of the farm, where there is no WiFi, but you have good cellular coverage. This is where cellular connectivity comes in handy and which is why I decided to go with the cellular-based Conexio Stratus dev kit. Although there are many other IoT platforms that are cellular-based, however, following are some of the reasons why Conexio Stratus stands out from the crowd.
- The Conexio Stratus dev kit allows us to easily prototype an IoT solution as it comes with a prepaid 500MB of data with 10 years of global cellular service. No contract is required.
- The dev kit supports LTE-M and NB-IoT protocols and has integrated GPS as well, eliminating the need to buy and integrate an external GPS module.
- It also has onboard environmental sensors, specifically, Sensirion Sht4x temperature and humidity sensor and LIS2DH accelerometer from ST micro.
- Last but not least, the kit supports energy harvesting and battery recharging from solar. This is one of the missing features that is currently not found in many IoT devices.
In addition to the Stratus device, I also used a Stratus shield which supports Sparkful QWIIC connector, Mikro bus for Mikroe click boards, and Grove I2C connector for connecting external sensors and actuators. Using this shield, we have connected the BME280 weather click board from Mikroe for measuring temperature, humidity, and pressure. This is mainly to demonstrate how easy it is to interface and connect a third-party sensor module to the Stratus device without soldering.
No external MCU is Required!
Unlike other cellular-based IoT devices where you need to have a dedicated MCU to control other peripherals such as GPS, sensors, etc, Conexio Stratus eliminates the need for an external MCU. It simply combines the main MCU, cell, and GPS module in a tiny form factor enabled by the nRF9160 SiP. nRF9160 incorporates an Arm Cortex-M33 application processor solely for applications, a full LTE modem, RF Front End (RFFE), and a power management system, making it the most compact, complete, and energy-efficient cellular IoT solution on the market. Moreover, eliminating the need for an external MCU, cellular, or GPS module, cuts down the device integration cost and time.
So let’s dive into setting up the required software and hardware configurations.
Assembling the Hardware for initial Firmware Testing
Below are all the hardware pieces that we have used.
For the initial testing, we will plug in the main Stratus dev board and the Mikroe BME280 weather click board to the Stratus shield as shown below. The full hardware for the final deployment will be assembled and shown later in this tutorial.
Datacake Registration and Setup
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. In STEP 2, you can add one or more API devices. Next, assign the device name and hit Next.
Adding Database Fields
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 BME280 sensor
- Humidity - relative humidity readings from the BME280 sensor
- Pressure - environmental pressure readings from the BME280 sensor
Adding Integrations
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.
Note: 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 documentationto 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. The field (identifier) is where we will publish different measurements from the Stratus device.
Generate Access Token
When a user account is created and registered in the Datacake platform, a user access token is automatically generated. This API token acts as security and gives devices access to the user’s account.
Note: We will need this token to authenticate our Stratus device with the Datacake platform.
To view your personal access token, click “Edit Profile” and then “API”.
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.
MQTT Application CodeWe 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.
Add Datacake credentials to the Application Code
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.
# MQTT application configuration authentication
CONFIG_MQTT_PASS="DATACAKE_ACCESS_TOKEN"
CONFIG_MQTT_USER="DATACAKE_ACCESS_TOKEN"
Note the user name and password are the same.
MQTT Broker Configuration
Next, we need to configure the MQTT broker hostname and the port. Update the Datacake broker configuration with the following:
# MQTT broker configuration
CONFIG_MQTT_BROKER_HOSTNAME="mqtt.datacake.co"
CONFIG_MQTT_BROKER_PORT=8883
We will be using Port 8883 that uses a CA-signed server certificate.
MQTT Pub/Sub Configuration
To record the measurements to a specific Database Field of a Device, we will update the MQTT publish topics as follows:
# MQTT topics for recording measurement values
# Change this as per your Datacake MQTT Integration and fields
CONFIG_MQTT_PUB_TOPIC_TEMP="dtck-pub/<product_slug>/<device_id>/TEMPERATURE"
CONFIG_MQTT_PUB_TOPIC_HUM="dtck-pub/<product_slug>/<device_id>/HUMIDITY"
CONFIG_MQTT_PUB_TOPIC_PRES="dtck-pub/<product_slug>/<device_id>/PRESSURE"
CONFIG_MQTT_PUB_TOPIC_VER="dtck-pub/<product_slug>/<device_id>/VERSION"
CONFIG_MQTT_PUB_TOPIC_IMEI="dtck-pub/<product_slug>/<device_id>/IMEI"
CONFIG_MQTT_PUB_TOPIC_BAT="dtck-pub/<product_slug>/<device_id>/BATTERY"
CONFIG_MQTT_PUB_TOPIC_RSRP="dtck-pub/<product_slug>/<device_id>/RSRP"
CONFIG_MQTT_PUB_TOPIC_BUTTON="dtck-pub/<product_slug>/<device_id>/BUTTON"
# MQTT subscription topics
CONFIG_MQTT_SUB_TOPIC="dtck/conexio-stratus/<product_slug>/<device_id>/+"
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.
Program the Stratus Device
To compile the application, open a terminal window in the application directory and issue the following west
command
west build -b conexio_stratus_ns
Once the application is compiled successfully, connect the Stratus device and put it into the DFU mode.
Flash the compiled firmware using newtmgr:
newtmgr -c serial image upload build/zephyr/app_update.bin
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.
*** Booting Zephyr OS build v2.6.99-ncs1 ***
<inf> mqtt_app: Stratus MQTT Datacake sample started, version: v1.0.0
<inf> watchdog: Watchdog timeout installed. Timeout: 60000
<inf> watchdog: Watchdog started
<dbg> watchdog.watchdog_feed_enable: Watchdog feed enabled. Timeout: 30000
<inf> mqtt_app: Provisioning certificates
<inf> mqtt_app: LTE Link Connecting...
+CEREG: 2,"412D","03382810",7
+CSCON: 1
+CEREG: 5,"412D","03382810",7,,,"11100000","11100000"
%CESQ: 35,1,10,1
<inf> mqtt_app: LTE Link Connected!
<dbg> mqtt_app.modem_rsrp_handler: Incoming RSRP status message, RSRP value is 35
<inf> mqtt_app: IPv4 Address found 144.126.245.197
<inf> mqtt_app: client_id: 352656103852334
<inf> mqtt_app: TLS enabled
<inf> env_sensors: Environmental sensors initialized
<inf> mqtt_app: MQTT client connected<inf> mqtt_app: Subscribing to: dtck/conexio-stratus/4fbfe839-c8aa-4882-a890-02f981753f6d/+ len 59<inf> mqtt_app: SUBACK packet id: 1234
<inf> mqtt_app: Publishing: 26.06
<inf> mqtt_app: to topic: dtck-pub/conexio-stratus/4fbfe839-c8aa-4882-a890-02f981753f6d/TEMPERATURE len: 73
<inf> mqtt_app: Publishing: 23.24
<inf> mqtt_app: to topic: dtck-pub/conexio-stratus/4fbfe839-c8aa-4882-a890-02f981753f6d/HUMIDITY len: 70
...
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 🎉.
Visualizing Weather Data on Datacake Dashboard
After the firmware is up and running, head back to the Datacake dashboard and add the 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, Simple, and Elegant!
You can access the live device dashboard and the data from anywhere in the world at: https://app.datacake.de/pd/f66e9fed-996e-4b84-b44f-e3d4e458cd3e
Assembling the Final Deployment Ready Hardware
Now that we have our initial firmware and dashboard up and running, let’s assemble the complete hardware for deployment. Here, we have connected a small solar panel to the Stratus shield for recharging the LiPo battery. After turning the device ON by sliding the switch on the side of the Stratus main board, the complete hardware is mounted inside an Acrylic enclosure as shown below:
This is Just the Beginning…
This post demonstrates one of the many applications that you can create with the Conexio Stratus cellular IoT device. Now that we have no-code or low-code cloud platforms like Datacake, sending and visualizing IoT device data has become much easier than before. With prepaid 500MB of cellular data, you can track and log your weather data without the need for WiFi, Bluetooth, or even an SD card and from anywhere in the world. How cool is that!
Comments
Please log in or sign up to comment.