Home > Other >Special Application Circuits > IoT-based weather data logger

IoT-based weather data logger

Source: InternetPublisher:睡不醒的小壮 Keywords: IoT Cellular Networks Data Loggers Updated: 2024/12/27

    In this article, you will learn how to build a low-cost (and low-code) weather data logger using the Conexio Stratus suite and Datacake.

    background

    Temperature readings in buildings can be a major concern for heating experts, social landlords and even homeowners to ensure that the temperature within the property is constant and regularly controlled. A properly managed indoor climate guarantees a comfortable environment for the users and helps save energy.

    This article will demonstrate how to:

    Create your own IoT-based weather data dashboard for free.

    Create your first device on Datacake and connect a Conexio Stratus running ZephyrRTOS to the Datacake platform via an MQTT broker.

    Assemble the required hardware.

    Use Conexio Stratus devices to capture important environmental data from BME280 sensors, as well as other vital signs such as 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 Conexio Stratus Suite?

Wi-Fi service may not be the most reliable and may not even be an option for users in some places. For example, if you want to monitor and deploy a sensor device in the middle of a farm where there is no WiFi but you have good cellular coverage. This is where cellular connectivity comes in handy and that is why I decided to go with the cellular-based Conexio Stratus development kit. Although there are many other cellular-based IoT platforms, here are some of the reasons why Conexio Stratus stands out.

    The Conexio Stratus Development Kit makes it easy for us to prototype IoT solutions because it comes with 500MB of prepaid data and 10 years of global cellular service. No contracts required.

    The development kit supports LTE-M and NB-IoT protocols and also integrates GPS, eliminating the need to purchase and integrate an external GPS module.

    It also has onboard environmental sensors, specifically the Sensirion Sht4x temperature and humidity sensor and LIS2DH accelerometer from ST micro.

    Last but not least, the kit supports energy harvesting and solar cell charging. This is one of the missing features not found in many IoT devices currently.

pYYBAGMFyn6ABQtiAALJaXsqCRo826.png

    In addition to the Stratus device, I also used the Stratus shield, which supports the Sparkful Qwiic connector, the Mikro bus for the Mikroe click board, and the Grove I2C connector for connecting external sensors and actuators. Using this shield, we connected Mikroe's BME280 weather click board to measure temperature, humidity, and pressure. This was mainly to demonstrate how easy it is to connect third-party sensor modules to the Stratus device without soldering.

poYBAGMFynqAMGzlAALykbTNWwE604.png

    No external MCU required

    Unlike other cellular-based IoT devices that require a dedicated MCU to control other peripherals such as GPS, sensors, etc., Conexio Stratus does not require an external MCU. It simply combines the main MCU, cell, and GPS module in a tiny form factor powered by the nRF9160 SiP. The nRF9160 contains an Arm Cortex-M33 application processor just for the application, a complete 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. In addition, no external MCU, cellular, or GPS module is required, reducing device integration cost and time.

    So let's dive into setting up the required software and hardware configuration.

    Assembling the hardware for initial firmware testing

    Here is all the hardware we used:

poYBAGMFynaAMuMWAAM-c0cGHYU879.png

    For initial testing, we plugged the main Stratus development board and the Mikroe BME280 Weather Click Board into the Stratus Shield as shown below. The complete hardware for the final deployment will be assembled and shown later in this article.

pYYBAGMFynKACx8kAATXig5pLo4422.png

    Datacake Registration and Setup

    Register and create a user account on the Datacake platform here. Your first two devices are free.

    Before we can store any measurement readings via MQTT, we need to set up a device on the Datacake platform. After registration and account activation, go to the Fleet view of the Datacake workspace.

poYBAGMFym6AXEdsAABtvjeRB0I164.png

    Click Add Device in the upper right corner and the following pop-up window will pop up.

pYYBAGMFymqAMDhbAAHkfPH4pVo817.png

    In STEP 1, select the device type as “API” and under Datacake Product select New Product. Then assign a name to your device under “Product Name”. In this tutorial, we will name the product “Conexio Stratus”.

poYBAGMFymaAbIQxAAFgCevDt-g349.png

    In STEP 2, you can add one or more API devices. Next, assign a device name and click Next.

pYYBAGMFyl2AYTekAAF7e4NFWL8974.png

    Finally, in STEP 3, select a Datacake plan. To create a device, you must select a payment plan. Since Datacake allows you to create up to two devices for free, you can select the Free plan and click Add 1 Device.

    Your device is now registered with 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 a device name and click Next.

    Adding Database Fields

    OK. At this point we need to define the fields in the device's database that will host the measurements sent from the Stratus device over MQTT.

poYBAGMFyliAGlXbAACHY5P8UD0206.png

    In Datacake, navigate to the Configuration tab and scroll down to the Fields section and click the Add Field button.

pYYBAGMFylSAWbDMAAAuRBdSWVw440.png

    This will open a modal with multiple data types. In this article, we will add multiple fields starting with temperature of type "Float". Datacake will automatically fill in the "Identifier" field. See the snippet below for more details.

poYBAGMFylCATDAyAAE4pGhWUEk893.png

    Once you have completed the field details, click on Add Field to complete the field. Below you will see all of the different fields we have added for this sample application. These fields include:

RSRP - LTE signal strength value

    Battery - used to record the voltage of a connected LiPo battery

    IMEI - Conexio Stratus International Mobile Equipment Identity (IMEI) number

    Version - The firmware version running on the device

    Temperature - Ambient temperature reading from the BME280 sensor

    Humidity - Relative humidity readings from the BME280 sensor

    Pressure - Ambient pressure reading from the BME280 sensor

poYBAGMFykuAZrjzAACfNMbxa2g174.png

    Add Integration

    Next, just below the Fields section, you will find the Integrations section. To forward data from your device via MQTT, a connection to Datacake must be established. Click Configure and the MQTT Integration Information window will pop up.

poYBAGMFykaAM_AMAAAk6VUUzH0073.png

    The Datacake platform provides an MQTT broker with TLS encryption, which allows subscription and logging of data.

    With the help of this platform, you can:

    Forward incoming device data to external services via MQTT

    Store data in Datacake Cloud via MQTT

    To log measurements to Datacake Cloud, we will publish the data to the corresponding topic structure, as shown in the MQTT integration window.

poYBAGMFykOAQD-ZAACyl-H9OB0377.png

    NOTE: Copy the Agent Name above and the Topic we will use later in the firmware configuration.

    Datacake's MQTT topic prefix follows the following structure:

    dtck-pub/《product_slug》/《device_id》/《field_name》

    The last element in the topic structure is the field name of the measurement, which appears in the database field we created earlier. This field (identifier) ​​is where we will publish the different measurements from the Stratus device.

    Generate Access Token

    When a user account is created and registered on the Datacake platform, a user access token is automatically generated. This API token acts as security and allows the device to access 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 , then click API .

pYYBAGMFyj6AV6rkAAE0WRUQwqk604.png

    To view your access token, click on Show. Now copy this access token to a safe place as we will need it later.

    At this point we have all the details needed to connect and publish data from our Conexio Stratus device to Datacake. Now let's move on to the device firmware side of things.

    MQTT application code

    We have extended the sample MQTT application provided in the nRF Connect SDK to make it easy to connect the Stratus kit to an MQTT broker to send and receive data from the Datacake platform.

    The extended sample application connects to Datacake and publishes data to the configured publish topic. On a button press event, the application publishes device health values ​​to Datacake and periodically publishes environmental data such as temperature and humidity.

    The full application can be found below this article.

    Add Datacake credentials to your application code

    First, we 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 that the username and password are the same.

    MQTT broker configuration

    Next, we need to configure the MQTT broker hostname and 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 use port 8883 using a CA signed server certificate.

    MQTT Publish/Subscribe Configuration

    To log measurements to a specific database field for the device, we will update the MQTT publish topic 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/

    # MQTT subscription topics
CONFIG_MQTT_SUB_TOPIC="dtck/conexio-stratus/

    For example, using the Product-Slug my-product , Device-ID 6b98a3bb-9ae1-418f-9375-f23091a849cd , and Field-Identifier TEMPERATURE would publish a message to:

    dtck-pub/my-product/6b98a3bb-9ae1-418f-9375-f23091a849cd/TEMPERATURE

    The payload will hold the value you want to log into that specific database field.

    publish("dtck-pub/my-product/6b98a3bb-9ae1-418f-9375-f23091a849cd/TEMPERATURE", 25.00)

    At this point, the MQTT parameter configuration has been set.

    Programming Stratus Devices

    To compile the application, open a terminal window in the application directory and issue the following west command

    west build -b conexio_stratus_ns
After successfully compiling the application, connect the Stratus device and put it into DFU mode.

    Use newtmgr to flash the compiled firmware:

    newtmgr -c serial image upload build/zephyr/app_update.binOpen
the 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, please allow a few minutes for it to register to the network and establish an LTE connection with the tower. Since the Stratus device is pre-configured to automatically connect to the LTE network, no additional SIM activation is required.

    *** Booting Zephyr OS build v2.6.99-ncs1 ***

    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 topic. Your Stratus device is now active and communicating with the Datacake cloud.

    Visualizing Weather Data on a Datacake Dashboard

    Once the firmware is up and running, return to the Datacake dashboard and add the graph widget to your workspace. You will now see device data flowing into Datacake and populating beautiful graphs. Below is the sample dashboard we created.

pYYBAGMFyjWAeNNwAAEkKS5KSHA441.png

    You can access real-time device dashboards and data from anywhere in the world: https://app.datacake.de/pd/f66e9fed-996e-4b84-b44f-e3d4e458cd3e

    Assembling the final deployment-ready hardware

    Now that we have the initial firmware and dashboard up and running, let's assemble the full hardware for deployment. Here we attach a small solar panel to the Stratus shield, which is used to charge the LiPo battery. After turning the device on by sliding the switch on the side of the Stratus motherboard, the full hardware is installed inside the acrylic enclosure, as shown below:

poYBAGMFyjGAFsVQAAcYXqhZWgw858.png

poYBAGMFyi2AeP54AAW2r2c8QXE608.png

    in conclusion

    This post demonstrates one of the many applications you can create using a 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 from anywhere in the world without WiFi, Bluetooth, or even an SD card.

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号