Skip to content

Network-Connected Environmental Station Demo#44

Open
alieissa-commits wants to merge 9 commits into
eclipse-threadx:mainfrom
alieissa-commits:main
Open

Network-Connected Environmental Station Demo#44
alieissa-commits wants to merge 9 commits into
eclipse-threadx:mainfrom
alieissa-commits:main

Conversation

@alieissa-commits

Copy link
Copy Markdown
Contributor

Network-Connected Environmental Station Demo

Summary

The Network-Connected Environmental Station demo (app/demos/network_station/) is an integrated IoT application demonstrating how to coordinate the Eclipse ThreadX RTOS, FileX FAT file system, and NetX Duo TCP/IP stack on resource-constrained microcontrollers.

The application periodically polls temperature and humidity data (supporting both a physical I2C HTS221 sensor and an automatic mathematical simulator fallback), logs the readings locally as CSV records to a virtual FAT RAM disk, and forwards them to a separate network thread. The network thread dynamically monitors Ethernet cable status, resolves an IP via DHCP, resolves the broker hostname via DNS, and publishes the logs as JSON telemetry payloads over MQTT. The threads communicate using an asynchronous, decoupled queue pipeline utilizing an Evict Oldest circular policy to prevent system blocking and preserve the newest real-time data during network outages.


Key Features

1. Environmental Station Application (app/demos/network_station/)

  • Multi-Threaded RTOS Pipeline: Wires together sensor_thread (polls data every 2s), logger_thread (writes data locally to a FAT filesystem), and network_thread (publishes JSON telemetry via MQTT).
  • I2C Sensor & Fallback: Communicates with the physical HTS221 sensor on I2C1, automatically falling back to a mathematical sine-wave simulation loop (mock_sensor.c) if no sensor is physically detected at startup.
  • FileX RAM Disk Logger: Formats and mounts a virtual 32 KB FAT RAM Disk inside the board's internal memory and logs CSV records to sensor_log.txt.
  • MQTT Telemetry & Reconnection: Configures NetX Duo DHCP/DNS clients to resolve and connect to the public Mosquitto broker (test.mosquitto.org:1883) using a client ID derived from the board's unique hardware ID. Telemetry is formatted as JSON.
  • Evict-Oldest Queue Policy: Employs an evict-oldest circular queue between the logger and network threads to handle network outages. If the link is lost, the newest data is prioritized on the wire while the full history remains safely recorded in the local FileX database.

2. Unified 256-Color Logging (ansi_colors.h)

  • Added a shared header app/ansi_colors.h containing VT100-compatible color codes to replace standard harsh terminal colors with a modern, muted color scheme.
  • Subsystem Tags: Muted Slate Gray (\x1b[38;5;243m) is used for all prefix tags (e.g. [System], [HAL], [NetX], [Logger Thread]), pushing the tags into the visual background.
  • State Colors: The message text color represents its priority:
    • Soft Green (MSG_SUCCESS) for successes.
    • Muted Gold/Orange (MSG_WARNING) for alerts/link changes.
    • Coral/Red (MSG_ERROR) for disconnections/failures.
  • Refactored board_init.c and the other demos (threadx_basic and netx_echo) to use this shared logging header for consistency.

Verification

  • The demo compiles successfully with the GNU ARM Toolchain (-Werror active) with a Flash size of ~165.9 KB and RAM size of ~415.8 KB.
  • Validated dynamic network reconnection, queue eviction logs, local RAM Disk writing, and MQTT WebSocket telemetry arrival on target hardware.
  • All commits are fully signed off in compliance with the Developer Certificate of Origin (DCO).

alieissa-commits and others added 9 commits July 7, 2026 20:24
…d default to threadx_basic

Signed-off-by: alieissa-commits <ali.eissa.dev@gmail.com>
Signed-off-by: alieissa-commits <ali.eissa.dev@gmail.com>
Co-authored-by: Codex <codex@openai.com>
Signed-off-by: alieissa-commits <ali.eissa.dev@gmail.com>
Signed-off-by: alieissa-commits <ali.eissa.dev@gmail.com>
Signed-off-by: alieissa-commits <ali.eissa.dev@gmail.com>
Signed-off-by: alieissa-commits <ali.eissa.dev@gmail.com>
Signed-off-by: alieissa-commits <ali.eissa.dev@gmail.com>
…tion demo

Signed-off-by: alieissa-commits <ali.eissa.dev@gmail.com>
Signed-off-by: alieissa-commits <ali.eissa.dev@gmail.com>
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.

2 participants