Skip to content

Adem-Aoun/multithreaded-sensor-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sensor Logger 🖥️📊

A multi-threaded sensor logger written in C ⚡ that simulates temperature 🌡️, humidity 💧, and light 💡 sensors.

Data from each sensor is collected concurrently using POSIX threads and logged to a CSV file 📑 with timestamps ⏱️.

👉 This project is especially useful as a teaching tool and as a foundation for real-time applications in Embedded Linux 🐧, such as IoT devices, Raspberry Pi data loggers, or sensor gateways.


📂 Project Structure

sensor-logger/
├── bin/                  # Executable + generated CSV logs
│   ├── sensor_logger     # Compiled binary
│   └── 2025-08-29 17:12:39.csv
├── include/              # Headers and implementations
│   ├── csv_logger.c
│   ├── csv_logger.h
│   ├── threads.c
│   └── threads.h
├── src/                  # Entry point
│   └── main.c
└── Makefile              # Build script

⚙️ Features

  • 🧵 Concurrent threads for:
    • 🌡️ Temperature sensor
    • 💧 Humidity sensor
    • 💡 Light sensor
    • 📑 CSV logger
  • 🔒 Thread synchronization using pthread_mutex and pthread_cond
  • 📊 CSV file output with timestamp-based filenames
  • 🛠️ Easily extendable for real sensors (replace rand() with hardware drivers)
  • ⚡ Designed with Embedded Linux real-time logging in mind

🚀 Build & Run

1. Build the project

make

This will create the executable in bin/sensor_logger ⚙️.

2. Run the logger

./bin/sensor_logger

3. Output

The program generates a CSV log in the bin/ folder 📂 with the current timestamp ⏱️ as its filename.

Example content:

timestamp,temp,humidity,light
2025-08-29 17:12:41,25.00,60.00,128
2025-08-29 17:12:42,30.00,55.00,200
2025-08-29 17:12:43,28.00,70.00,90

📦 Requirements

  • 🖥️ GCC compiler
  • 🧵 POSIX threads (pthread)

✅ Tested on:

  • Ubuntu 22.04 🐧
  • GCC 11+

🛠️ Possible Improvements

  • 🛑 Add graceful exit handling (e.g., stop threads on CTRL+C)
  • ⚙️ Add configuration file for sampling rate
  • 🌍 Replace simulated values with real sensor readings
  • 📂 Add JSON/SQLite logging in addition to CSV

📜 License

This project is licensed under the MIT License — feel free to use and modify it.

About

A multi-threaded sensor logger written in C that simulates temperature, humidity, and light sensors and saves data to CSV.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors