Skip to content

modules: cloud: integrate nRF Cloud CoAP connectivity module#22

Merged
nmpluta merged 2 commits into
mainfrom
21-integrate-cloud-module
Sep 13, 2025
Merged

modules: cloud: integrate nRF Cloud CoAP connectivity module#22
nmpluta merged 2 commits into
mainfrom
21-integrate-cloud-module

Conversation

@nmpluta

@nmpluta nmpluta commented Sep 13, 2025

Copy link
Copy Markdown
Owner

MR Description

This MR integrates the cloud module from Asset Tracker Template v1.1.1 into the fire detection system, providing seamless nRF Cloud connectivity for sensor data transmission.

🎯 Overview

The integration adapts Nordic's proven cloud connectivity architecture to work with our fire detection system, enabling real-time sensor data transmission to nRF Cloud via CoAP protocol.

📋 Features Implemented

Cloud Module Integration (modules: cloud: integrate nRF Cloud CoAP connectivity module)

  • State Machine Architecture: Robust connection management with disconnected/connecting/connected states
  • ZBUS Integration: Seamless communication with sensor and network modules
  • Automatic Data Transmission: All fire detection sensors (BME280, CCS811, HM3301, SEN0466) data sent to cloud
  • Connection Resilience: Configurable backoff strategies (exponential/linear/none) for reconnection
  • Device Shadow Support: Configuration management via nRF Cloud device shadow
  • Shell Commands: Interactive cloud commands for testing and debugging
  • Comprehensive Error Handling: Watchdog integration and fatal error management
  • Credentials Management: Automatic nRF Cloud credentials validation

Timestamp Enhancement (modules: sensor: add configurable UTC timestamps to sensor data)

  • Configurable Timestamps: CONFIG_SENSOR_MODULE_TIMESTAMP enables UTC epoch timestamps
  • Smart Fallback: Uses date_time_now() when available, k_uptime_get() otherwise
  • Cloud Compatibility: Proper timestamp handling for nRF Cloud data correlation
  • Enhanced Logging: Human-readable timestamp display in controller module

🔧 Key Adaptations from Original Asset Tracker Template

Architecture Integration

- Original: GPS, accelerometer, battery sensors
+ Fire Detection: BME280, CCS811, HM3301, SEN0466 sensors
- Original: Location-based tracking
+ Fire Detection: Environmental monitoring (temp, CO2, CO, PM, etc.)

ZBUS Channel Mapping

Original Channel Fire Detection Equivalent Purpose
SENSOR_CHAN sensor_chan Environmental sensor data
NETWORK_CHAN network_chan Connectivity status
LOCATION_CHAN (removed) Not applicable for fire detection

Sensor Data Transmission

// Original Asset Tracker
nrf_cloud_coap_sensor_send("GPS", lat_lng, timestamp, confirmable);

// Fire Detection System
nrf_cloud_coap_sensor_send("TEMP", temperature, timestamp, confirmable);
nrf_cloud_coap_sensor_send("CO2", co2_level, timestamp, confirmable);
nrf_cloud_coap_sensor_send("CO", co_level, timestamp, confirmable);
nrf_cloud_coap_sensor_send("PM2_5", pm2_5_level, timestamp, confirmable);

Smart Timestamp Handling

  • With CONFIG_SENSOR_MODULE_TIMESTAMP=y: Real UTC timestamps for accurate cloud correlation
  • With CONFIG_SENSOR_MODULE_TIMESTAMP=n: Uses NRF_CLOUD_NO_TIMESTAMP to let nRF Cloud assign server time

🏗️ System Architecture

Fire Detection Application
    ↓
┌─────────────────────────────────────────────────────────────┐
│                    ZBUS Message Bus                         │
├─────────────────────────────────────────────────────────────┤
│ Sensor Module → Cloud Module → nRF Cloud CoAP              │
│ Network Module ↗              ↘ Device Shadow              │
│ Controller Module              ↘ Sensor Data Streaming     │
└─────────────────────────────────────────────────────────────┘
    ↓
nRF Cloud Platform

📊 Configuration Options

Cloud Module Settings

Config Default Description
CLOUD_MODULE_CONFIRMABLE_MESSAGES n Use CoAP confirmable messages
CLOUD_MODULE_BACKOFF_INITIAL_SECONDS 60 Initial reconnection delay
CLOUD_MODULE_BACKOFF_TYPE LINEAR Backoff strategy
CLOUD_MODULE_THREAD_STACK_SIZE 6144 Cloud thread stack size

nRF Cloud Integration

CONFIG_NRF_CLOUD=y
CONFIG_NRF_CLOUD_COAP=y
CONFIG_NRF_CLOUD_CLIENT_ID_SRC_IMEI=y
CONFIG_NRF_CLOUD_CHECK_CREDENTIALS=y

🔍 Transmission Data Points

The system automatically transmits all fire detection sensor readings:

  • Environmental: Temperature, humidity, air pressure
  • Air Quality: CO2, VOC levels
  • Particulate Matter: PM1.0, PM2.5, PM10
  • Hazardous Gas: CO concentration
  • Network Quality: RSRP, connection evaluation

The integration provides a robust foundation for cloud-connected fire detection systems.

Original Source: Asset Tracker Template - Cloud Module

Closes #21

Signed-off-by: Natalia Pluta pluta.natalia.m@gmail.com

Add CONFIG_SENSOR_MODULE_TIMESTAMP option to conditionally include UTC epoch
timestamps in sensor messages using date_time_now() instead of k_uptime_get().
Update controller logging to display human-readable timestamp format.

Refs: #21

Signed-off-by: Natalia Pluta <pluta.natalia.m@gmail.com>
@nmpluta nmpluta linked an issue Sep 13, 2025 that may be closed by this pull request
@nmpluta nmpluta requested a review from Copilot September 13, 2025 01:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR integrates nRF Cloud CoAP connectivity by adapting Nordic's cloud module from the Asset Tracker Template. The system now transmits sensor data (temperature, humidity, air pressure, CO2, VOC, particulate matter, and CO levels) to nRF Cloud using CoAP protocol with configurable timestamps.

  • Adds a complete cloud connectivity module with state machine architecture and automatic reconnection handling
  • Implements configurable UTC timestamps for sensor data with fallback mechanism
  • Refactors error handling to use a common app_common.h header instead of app_fatal_error.h

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
app/src/modules/sensor/sensor_module.h Adds conditional timestamp field to sensor messages
app/src/modules/sensor/sensor_module.c Implements UTC timestamp generation with fallback logic
app/src/modules/sensor/Kconfig.sensor Adds timestamp configuration option
app/src/modules/network/network_shell.c Minor shell output enhancement for RSRP display
app/src/modules/network/network_module.c Updates include to use common error handling
app/src/modules/controller/controller_module.c Conditionally logs timestamps based on configuration
app/src/modules/cloud/ Complete cloud module implementation with CoAP connectivity
app/src/app_fatal_error.h Removed in favor of common error handling
app/src/app_common.h New common header with error handling and utility macros
app/prj.conf Adds nRF Cloud and CoAP configuration
app/Kconfig Includes cloud module configuration
app/CMakeLists.txt Adds cloud module to build

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread app/src/modules/cloud/cloud_module.c Outdated
Integrate and adapt cloud module from Asset Tracker Template v1.1.1 providing:
- State machine-based nRF Cloud CoAP connectivity management
- ZBUS communication with sensor and network modules
- Automatic sensor data transmission to nRF Cloud
- Connection management with exponential/linear backoff strategies
- Device shadow support and shell commands for cloud interaction
- Watchdog integration and comprehensive error handling
- Replace app_fatal_error.h with app_common.h for enhanced error handling

Includes all necessary nRF Cloud configuration, CoAP client setup,
and integration with existing fire detection system architecture.

Refs: #21

Signed-off-by: Natalia Pluta <pluta.natalia.m@gmail.com>
@nmpluta nmpluta force-pushed the 21-integrate-cloud-module branch from 5efe6cc to c2d814d Compare September 13, 2025 12:43
@nmpluta nmpluta merged commit ebef25a into main Sep 13, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate cloud module

2 participants