Software Architecture
FreeRTOS-based firmware with concurrent multitasking, MQTT cloud connectivity, and over-the-air updates.
FreeRTOS Task Architecture
Concurrent tasks with priority-based preemptive scheduling ensure deterministic real-time behavior for fish detection, IMU sensing, telemetry, and system reliability.
app_watchdog
The system guardian task. Monitors all other tasks for stalls by tracking periodic check-ins. If any task fails to report within 5 seconds, the watchdog triggers a full system reset via the hardware WDT. A 15-second grace period at startup prevents false resets during initialization.
mqtt_connection_task
The communication backbone. Manages the full Wi-Fi connection lifecycle and maintains a persistent MQTT session with the Azure-hosted broker. Handles subscription management and drains the publish queue every 100 ms, ensuring sensor data and fish detection events are delivered to the cloud with minimal latency. The 8 KB stack accommodates the TLS and MQTT library overhead.
ota_update_task
Over-the-air firmware update handler. Listens on the CyberRod/Update MQTT topic for update commands. When triggered (payload "1"), downloads the new firmware image via HTTP OTAF v2 from the Azure VM and applies it to the Si917 SoC. The 200 ms polling interval keeps latency low while preserving CPU cycles for the time-critical fish detection task.
fish_detection_task
The core sensing loop with the fastest period in the system. Continuously reads ultrasonic distance data over UART, classifies fish proximity into three states (none, near, very near), and publishes both the raw distance in millimeters and the detection classification to MQTT. The 20 ms period (50 Hz) provides responsive real-time fish detection without overwhelming the broker.
temperature_upload_task
Environmental telemetry uploader. Reads temperature and relative humidity from the SHT4x sensor over I2C every 300ms and publishes both values to their respective MQTT topics. The period balances responsive telemetry with the gradual nature of environmental changes.
imu_task
Motion and acceleration sensing task. Reads 3-axis acceleration and 3-axis angular velocity from the IMU sensor over the shared I2C0 bus. Computes acceleration magnitude and detects sudden rod jerks or vibrations that may indicate fish bite events. Publishes acceleration data to MQTT for real-time dashboard visualization and post-session analysis.
Communication Protocols
MQTT messaging, Wi-Fi connectivity, and HTTP-based over-the-air firmware updates.
MQTT Publish Topics
Sensor data and detection events are published to the Azure-hosted Mosquitto broker at 20.230.132.231:1883 with client ID si917-devboard-cyberrod.
# Fish proximity classification
Topic: CyberRod/Fish_detection
Format: integer (0 = no fish, 1 = near, 2 = very near)
# Ultrasonic distance reading
Topic: CyberRod/Distance
Format: string (distance in mm)
# SHT4x temperature reading
Topic: CyberRod/Temperature
Format: string (degrees Celsius, 2 decimal places)
# SHT4x humidity reading
Topic: CyberRod/Humidity
Format: string (%RH, 2 decimal places)
# IMU acceleration data
Topic: CyberRod/Acceleration
Format: string (X,Y,Z acceleration values)
MQTT Subscribe & OTA Update
The device subscribes to a single command topic. Sending "1" triggers an HTTP OTAF v2 firmware download from the Azure VM.
# OTA update trigger
Topic: CyberRod/Update
Action: Send payload "1" to initiate
# OTA update process
Protocol: HTTP OTAF v2
Source: Azure Virtual Machine
File: wifi_http_otaf_soc.rps
Target: Si917 SoC flash
# Broker connection
Host: 20.230.132.231
Port: 1883
Client ID: si917-devboard-cyberrod
Safety & Reliability
Multi-layered fault detection ensures the device recovers autonomously from any software or hardware failure.
Hardware Watchdog Timer
Dedicated hardware WDT that cannot be disabled in software. The app_watchdog task services it periodically; if the firmware crashes entirely, the WDT times out and forces a hard system reset.
Task Stall Detection
The watchdog task tracks the last check-in time from every other task. If any task fails to report within 5 seconds, the system identifies the stalled task and triggers a reset. A 15-second grace window at boot accommodates slow initialization sequences.
Stack Overflow Hook
FreeRTOS vApplicationStackOverflowHook is enabled. If any task exceeds its allocated stack, the hook fires immediately and resets the system, preventing silent memory corruption that could cause unpredictable behavior in the field.
Malloc Failure Hook
The vApplicationMallocFailedHook callback catches heap exhaustion at runtime. If pvPortMalloc returns NULL, the hook triggers a system reset rather than allowing a NULL-pointer dereference to crash the device unpredictably.
HardFault Handler
A custom HardFault_Handler captures the fault at the ARM Cortex-M level. Whether caused by an invalid memory access, bus error, or usage fault, the handler initiates a clean system reset to restore operation without manual intervention.
Node-RED Dashboard
Real-time monitoring interface built with Node-RED v4.1.8 and FlowFuse Dashboard 2.0, featuring a custom nautical-themed design.
Live Sensor Gauges
Real-time gauges display ultrasonic distance, fish detection state, temperature, and humidity. Data streams from MQTT are displayed with sub-second latency, giving anglers immediate environmental awareness.
Historical Charts
Time-series line charts track temperature and humidity trends over configurable windows. Distance readings plot fish approach patterns, enabling post-session analysis of fishing conditions.
OTA Update Trigger
A dashboard button publishes to CyberRod/Update, triggering the OTA task on the device. Firmware updates can be deployed remotely without physical access to the fishing rod, critical for field deployments.
Nautical-Themed UI
Custom CSS gives the FlowFuse Dashboard a nautical aesthetic with ocean blues, signal-flag accents, and maritime typography. The theme reinforces the fishing context while maintaining clean data readability in outdoor lighting conditions.
Task Summary
Complete specification of all FreeRTOS tasks, their resource allocation, and scheduling parameters.
| Task | Stack | Priority | Period | Function |
|---|---|---|---|---|
app_watchdog |
2048 | Realtime | 1000 ms | Monitor all tasks, trigger WDT reset on stall |
mqtt_connection_task |
8192 | Above Normal | 100 ms | Wi-Fi + MQTT broker session, publish queue |
ota_update_task |
4096 | Normal | 200 ms | Listen for OTA trigger, download via HTTP OTAF v2 |
fish_detection_task |
2048 | Normal | 20 ms | Ultrasonic UART read, fish classification, publish |
temperature_upload_task |
3072 | Normal | 3000 ms | SHT4x I2C read, publish temperature + humidity |
imu_task |
2048 | Normal | 100 ms | IMU I2C read, acceleration & gyro, publish rod motion |