Introduction | Theory | Lab | Course Home
The Networked Environmental Monitor is designed as a modular, multi-threaded application that leverages the networking capabilities of the Raspberry Pi 4B. The architecture is centered around a message-passing paradigm, which decouples the different components of the system and allows for concurrent operation.
graph TD
subgraph Hardware
A[BME280 Sensor] --> B(I2C Bus);
end
subgraph Zephyr RTOS on Raspberry Pi 4B
B --> C[Sensor Thread];
C -->|Sensor Data| D[Message Queue];
D --> E[Web Server Thread];
E --> F(TCP/IP Stack);
end
subgraph Network
F --> G[Ethernet];
G --> H[Web Browser];
end
I[Main Thread] --> C;
I --> E;
I --> J[Shell Interface];
K[Power Management] --> C;
K --> E;
K --> F;
The multi-threaded architecture allows for concurrent operation, which is essential for a responsive and efficient embedded system.
Sensor Thread: This thread will wake up at a configurable interval (e.g., every 5 seconds), read the temperature, humidity, and pressure from the BME280 sensor, and then put the data into the message queue. After posting the data, the thread will go back to sleep.
Web Server Thread: This thread will create a listening socket and wait for incoming HTTP requests. When a request is received, it will read the latest sensor data from the message queue (or a shared data structure) and generate an HTML or JSON response.
A message queue is the ideal communication primitive for this application for several reasons:
sensor_reading struct, in a thread-safe manner.While the Raspberry Pi 4B is not a low-power device, we can still apply power management principles:
A simple HTTP server will be implemented using Zephyr’s socket APIs. The server will have a single endpoint (/) that returns the latest sensor data.
GET /HTTP/1.1 200 OK
Content-Type: text/html
<html>
<head><title>Smart Weather Station</title></head>
<body>
<h1>Smart Weather Station</h1>
<p>Temperature: 25.5 C</p>
<p>Humidity: 45.2 %</p>
<p>Pressure: 1012.5 hPa</p>
</body>
</html>
Following the principles from Chapters 14 and 15, the project will be structured in a modular and configurable way:
sensor_manager.c, web_server.c) to promote code reuse and maintainability.CONFIG_SENSOR_READ_INTERVAL: The interval in seconds between sensor readings.CONFIG_WEB_SERVER_PORT: The port for the web server.This architectural design provides a solid foundation for building a robust, efficient, and maintainable Networked Environmental Monitor. The next section will provide the step-by-step guide to implementing this design.