|
1 | | -# Scalable UDP Server for Low-Latency Humidity Data Transmission |
| 1 | +# Scalable UDP Server for Low-Latency Data Transmission 🚀 |
2 | 2 |
|
3 | | -An advanced, open‐source project that implements a UDP server to serve live humidity and temperature data from a connected sensor |
| 3 | + |
4 | 4 |
|
5 | | -## Table of Contents |
| 5 | +Welcome to the **Scalable UDP Server for Low-Latency Data Transmission**! This repository offers an advanced open-source IoT solution designed to deliver real-time sensor data efficiently. Our server focuses on low-latency humidity data transmission, ensuring that you receive your data when you need it most. |
6 | 6 |
|
7 | | -- [Features](#features) |
8 | | -- [Repository Structure](#repository-structure) |
9 | | -- [Architecture Overview](#architecture-overview) |
10 | | -- [Setup and Installation](#setup-and-installation) |
11 | | - - [Hardware Setup](#hardware-setup) |
12 | | - - [Software Setup](#software-setup) |
13 | | - - [Docker Deployment](#docker-deployment) |
14 | | - - [CI/CD Workflows](#cicd-workflows) |
15 | | -- [Usage](#usage) |
16 | | -- [Testing](#testing) |
17 | | -- [Contribution Guidelines](#contribution-guidelines) |
18 | | -- [License](#license) |
19 | | -- [Contact](#contact) |
| 7 | +[Download the latest release](https://github.com/hari-vdh/Scalable-UDP-Server-for-Low-Latency-Data-Transmission/releases) and start your journey with us! |
20 | 8 |
|
21 | 9 | --- |
22 | 10 |
|
23 | | -## Features |
| 11 | +## Table of Contents |
24 | 12 |
|
25 | | -- **Real-Time Sensor Data Acquisition:** Reads live temperature and humidity data from a DHT sensor. |
26 | | -- **Simulation Mode:** Option to simulate sensor readings for development and testing purposes. |
27 | | -- **Low-Latency UDP Server:** Serves sensor data over UDP in near real-time with an emphasis on fast response times. |
28 | | -- **Advanced Logging and Error Handling:** Comprehensive logs (both to console and file) and robust error/retry mechanisms. |
29 | | -- **Modular Architecture:** Additional utility modules, services for analytics, notifications, caching, and metrics collection. |
30 | | -- **Containerized Deployment:** Fully dockerized solution with a Dockerfile and docker-compose for easy deployment and scalability. |
31 | | -- **CI/CD Integration:** Automated testing, linting, and deployment pipelines using GitHub Actions. |
32 | | -- **Extensible Codebase:** Structured to allow for easy expansion and integration with additional services and features. |
| 13 | +1. [Features](#features) |
| 14 | +2. [Installation](#installation) |
| 15 | +3. [Usage](#usage) |
| 16 | +4. [Configuration](#configuration) |
| 17 | +5. [Testing](#testing) |
| 18 | +6. [Contributing](#contributing) |
| 19 | +7. [License](#license) |
| 20 | +8. [Support](#support) |
33 | 21 |
|
34 | 22 | --- |
35 | 23 |
|
36 | | -## Repository Structure |
| 24 | +## Features 🌟 |
37 | 25 |
|
38 | | -``` |
39 | | -Scalable-UDP-Server-Humidity/ |
40 | | -├── .env # Environment variables |
41 | | -├── .gitignore # Git ignore rules |
42 | | -├── Dockerfile # Docker build configuration |
43 | | -├── docker-compose.yml # Docker Compose deployment file |
44 | | -├── README.md # Project overview and instructions |
45 | | -├── requirements.txt # Python dependencies |
46 | | -├── config.py # Centralized configuration settings |
47 | | -├── docs/ |
48 | | -│ ├── architecture.md # System architecture description |
49 | | -│ ├── design_decisions.md # Rationale behind design decisions |
50 | | -│ └── changelog.md # Project change log |
51 | | -├── scripts/ |
52 | | -│ ├── setup.sh # Environment setup script |
53 | | -│ ├── run_tests.sh # Script to execute unit tests |
54 | | -│ └── deploy.sh # Deployment automation script |
55 | | -├── ci/ |
56 | | -│ ├── .github/ |
57 | | -│ │ └── workflows/ |
58 | | -│ │ ├── python-app.yml # CI workflow for testing and linting |
59 | | -│ │ └── deploy.yml # Deployment workflow |
60 | | -│ └── lint.yml # Linting configuration |
61 | | -├── src/ |
62 | | -│ ├── sensor_reader.py # Sensor module for reading (or simulating) data |
63 | | -│ ├── udp_server.py # UDP server implementation with multithreading |
64 | | -│ ├── utils/ # Utility modules for logging, formatting, etc. |
65 | | -│ │ ├── logger.py # Custom logger configuration |
66 | | -│ │ ├── decorators.py # Function decorators (e.g., retry, timeit) |
67 | | -│ │ ├── exceptions.py # Custom exception definitions |
68 | | -│ │ └── data_formatter.py # Helper functions to format sensor data |
69 | | -│ └── services/ # Supplementary services for analytics and metrics |
70 | | -│ ├── analytics.py # Data analytics service |
71 | | -│ ├── notification.py # Notification service (stub) |
72 | | -│ ├── caching.py # In-memory caching mechanisms |
73 | | -│ └── metrics.py # Metrics collection and reporting |
74 | | -├── tests/ # Unit and integration tests |
75 | | -│ ├── test_sensor_reader.py |
76 | | -│ ├── test_udp_server.py |
77 | | -│ └── test_utils.py |
78 | | -└── examples/ # Example client and sample data files |
79 | | - ├── sample_client.py # Sample UDP client script |
80 | | - └── sample_data.json # Example JSON data output |
81 | | -``` |
| 26 | +- **Real-Time Data Transmission**: Our server efficiently handles low-latency data transmission using UDP. |
| 27 | +- **Modular Design**: Easily extend the server with additional modules as your needs grow. |
| 28 | +- **Extensive Logging**: Track your server's performance and data flow with built-in logging capabilities. |
| 29 | +- **Simulation Modes**: Test your setup with simulated data before deploying to production. |
| 30 | +- **Containerization with Docker**: Simplify deployment and scaling with Docker support. |
| 31 | +- **Integrated CI/CD Workflows**: Streamline your development process with continuous integration and delivery. |
| 32 | +- **Open Source**: Contribute to our project and help us improve! |
82 | 33 |
|
83 | 34 | --- |
84 | 35 |
|
85 | | -## Architecture Overview |
| 36 | +## Installation ⚙️ |
86 | 37 |
|
87 | | -The repository is organized into several layers to ensure clear separation of concerns: |
| 38 | +To get started, follow these steps to install the server on your machine. |
88 | 39 |
|
89 | | -- **Sensor Module:** |
90 | | - Handles reading data from a physical sensor using the Adafruit_DHT library or simulates readings if a sensor is unavailable. |
| 40 | +### Prerequisites |
91 | 41 |
|
92 | | -- **UDP Server:** |
93 | | - A multithreaded server that listens for UDP client requests and responds with JSON-formatted sensor data. |
| 42 | +- Python 3.7 or higher |
| 43 | +- Docker (optional, but recommended) |
| 44 | +- Git |
94 | 45 |
|
95 | | -- **Utility Modules:** |
96 | | - Custom logging configurations, decorators, exception handling, and data formatting functions that support maintainability and debugging. |
| 46 | +### Clone the Repository |
97 | 47 |
|
98 | | -- **Service Layer:** |
99 | | - Provides additional functionality (analytics, notifications, caching, metrics) and acts as a foundation for further feature integrations. |
| 48 | +Open your terminal and run the following command: |
100 | 49 |
|
101 | | -- **CI/CD and Containerization:** |
102 | | - Uses GitHub Actions for automated testing, linting, and deployments. Containerization via Docker ensures consistency across various deployment environments. |
103 | | - |
104 | | ---- |
105 | | - |
106 | | -## Setup and Installation |
| 50 | +```bash |
| 51 | +git clone https://github.com/hari-vdh/Scalable-UDP-Server-for-Low-Latency-Data-Transmission.git |
| 52 | +cd Scalable-UDP-Server-for-Low-Latency-Data-Transmission |
| 53 | +``` |
107 | 54 |
|
108 | | -### Hardware Setup |
| 55 | +### Install Dependencies |
109 | 56 |
|
110 | | -- **Sensor Connection:** |
111 | | - Connect your DHT sensor (e.g., DHT22) to your hardware (such as a Raspberry Pi) using the GPIO pin defined in `config.py`. |
| 57 | +Use pip to install the required Python packages: |
112 | 58 |
|
113 | | -### Software Setup |
| 59 | +```bash |
| 60 | +pip install -r requirements.txt |
| 61 | +``` |
114 | 62 |
|
115 | | -1. **Clone the Repository:** |
| 63 | +### Running with Docker |
116 | 64 |
|
117 | | - ```bash |
118 | | - git clone https://github.com/your-username/Scalable-UDP-Server-Humidity.git |
119 | | - cd Scalable-UDP-Server-Humidity |
120 | | - ``` |
| 65 | +If you prefer to run the server using Docker, you can build and run the Docker image with: |
121 | 66 |
|
122 | | -2. **Create and Activate a Virtual Environment:** |
| 67 | +```bash |
| 68 | +docker build -t scalable-udp-server . |
| 69 | +docker run -p 8080:8080 scalable-udp-server |
| 70 | +``` |
123 | 71 |
|
124 | | - ```bash |
125 | | - python3 -m venv venv |
126 | | - source venv/bin/activate |
127 | | - ``` |
| 72 | +--- |
128 | 73 |
|
129 | | -3. **Install Dependencies:** |
| 74 | +## Usage 📊 |
130 | 75 |
|
131 | | - ```bash |
132 | | - pip install -r requirements.txt |
133 | | - ``` |
| 76 | +Once you have installed the server, you can start using it to transmit humidity data. |
134 | 77 |
|
135 | | -4. **Environment Variables:** |
136 | | - Create or update the `.env` file with appropriate values (an example file is included in the repository). |
| 78 | +### Starting the Server |
137 | 79 |
|
138 | | -### Docker Deployment |
| 80 | +To start the server, run the following command: |
139 | 81 |
|
140 | | -1. **Build and Run with Docker Compose:** |
| 82 | +```bash |
| 83 | +python server.py |
| 84 | +``` |
141 | 85 |
|
142 | | - ```bash |
143 | | - docker-compose up --build |
144 | | - ``` |
| 86 | +The server will listen for incoming UDP packets on the specified port. |
145 | 87 |
|
146 | | - This command builds the container image, starts the UDP server, and maps the UDP port as configured in `.env`. |
| 88 | +### Sending Data |
147 | 89 |
|
148 | | -### CI/CD Workflows |
| 90 | +You can send data to the server using any UDP client. Here is a simple example using Python: |
149 | 91 |
|
150 | | -- **Testing and Linting:** |
151 | | - The repository includes GitHub Actions workflows located in `ci/.github/workflows/python-app.yml` and `ci/lint.yml` which run tests and lint checks on every push and pull request. |
| 92 | +```python |
| 93 | +import socket |
152 | 94 |
|
153 | | -- **Automated Deployment:** |
154 | | - See `ci/.github/workflows/deploy.yml` for details on deployment pipelines. |
| 95 | +UDP_IP = "127.0.0.1" |
| 96 | +UDP_PORT = 8080 |
| 97 | +MESSAGE = b"Humidity: 45%" |
155 | 98 |
|
156 | | ---- |
| 99 | +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 100 | +sock.sendto(MESSAGE, (UDP_IP, UDP_PORT)) |
| 101 | +``` |
157 | 102 |
|
158 | | -## Usage |
| 103 | +### Viewing Logs |
159 | 104 |
|
160 | | -### Running the UDP Server Locally |
| 105 | +Logs are saved in the `logs` directory. You can view the logs to monitor data transmission and server performance. |
161 | 106 |
|
162 | | -To run the server directly on your local machine: |
| 107 | +--- |
163 | 108 |
|
164 | | -```bash |
165 | | -python src/udp_server.py |
166 | | -``` |
| 109 | +## Configuration ⚙️ |
167 | 110 |
|
168 | | -The server listens on the IP and UDP port specified in `config.py` and responds with live sensor data. |
| 111 | +The server configuration is stored in a `config.json` file. You can modify the following settings: |
169 | 112 |
|
170 | | -### Interacting with the Server |
| 113 | +- **host**: The IP address the server will listen on. |
| 114 | +- **port**: The port number for incoming data. |
| 115 | +- **log_level**: The level of logging (e.g., DEBUG, INFO, WARNING). |
171 | 116 |
|
172 | | -Refer to the example client located in `examples/sample_client.py` to test the server: |
| 117 | +Example `config.json`: |
173 | 118 |
|
174 | | -```bash |
175 | | -python examples/sample_client.py |
| 119 | +```json |
| 120 | +{ |
| 121 | + "host": "0.0.0.0", |
| 122 | + "port": 8080, |
| 123 | + "log_level": "INFO" |
| 124 | +} |
176 | 125 | ``` |
177 | 126 |
|
178 | | -The client sends a UDP packet and prints the sensor data received as a JSON response. |
179 | | - |
180 | 127 | --- |
181 | 128 |
|
182 | | -## Testing |
| 129 | +## Testing 🧪 |
183 | 130 |
|
184 | | -The project includes comprehensive unit and integration tests: |
| 131 | +We provide a set of tests to ensure the server operates as expected. To run the tests, use the following command: |
185 | 132 |
|
186 | | -- **Run All Tests:** |
187 | | - |
188 | | - ```bash |
189 | | - bash scripts/run_tests.sh |
190 | | - ``` |
| 133 | +```bash |
| 134 | +pytest tests/ |
| 135 | +``` |
191 | 136 |
|
192 | | -- **Test Coverage:** |
193 | | - The tests are located in the `tests/` directory and cover sensor readings, UDP server responses, and utility functions. |
| 137 | +You can add your own tests in the `tests` directory. |
194 | 138 |
|
195 | 139 | --- |
196 | 140 |
|
197 | | -## Contribution Guidelines |
198 | | - |
199 | | -Contributions are welcome and encouraged! To contribute: |
200 | | - |
201 | | -1. **Fork the Repository:** |
202 | | - Create a personal fork of the project on GitHub. |
203 | | - |
204 | | -2. **Create a Feature Branch:** |
205 | | - Use a descriptive branch name (e.g., `feature/add-enhanced-logging`). |
206 | | - |
207 | | -3. **Implement Your Changes:** |
208 | | - Follow the established coding style and include tests for your changes. |
| 141 | +## Contributing 🤝 |
209 | 142 |
|
210 | | -4. **Submit a Pull Request:** |
211 | | - Provide a clear description of your changes and reference any related issues. |
| 143 | +We welcome contributions! If you would like to contribute to the project, please follow these steps: |
212 | 144 |
|
213 | | -For detailed contribution guidelines, please refer to the `CONTRIBUTING.md` file or contact the maintainers. |
| 145 | +1. Fork the repository. |
| 146 | +2. Create a new branch (`git checkout -b feature/YourFeature`). |
| 147 | +3. Make your changes. |
| 148 | +4. Commit your changes (`git commit -m 'Add some feature'`). |
| 149 | +5. Push to the branch (`git push origin feature/YourFeature`). |
| 150 | +6. Open a Pull Request. |
214 | 151 |
|
215 | 152 | --- |
216 | 153 |
|
217 | | -## License |
| 154 | +## License 📜 |
218 | 155 |
|
219 | | -This project is distributed under the [MIT License](LICENSE). Please see the LICENSE file for more details. |
| 156 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
220 | 157 |
|
221 | 158 | --- |
222 | 159 |
|
223 | | -## Contact |
| 160 | +## Support 💬 |
224 | 161 |
|
225 | | -For any inquiries, bug reports, or feature requests, please open an issue on [GitHub Issues](https://github.com/AkhilRai28/Scalable-UDP-Server-Humidity/issues). |
| 162 | +If you have any questions or issues, please check the [Releases](https://github.com/hari-vdh/Scalable-UDP-Server-for-Low-Latency-Data-Transmission/releases) section for updates or create an issue in the repository. |
226 | 163 |
|
227 | 164 | --- |
228 | 165 |
|
229 | | -Enjoy using and contributing to this open-source project! Your support helps us improve and expand the capabilities of this IoT solution. |
| 166 | +Thank you for using the **Scalable UDP Server for Low-Latency Data Transmission**! We hope you find it useful for your IoT projects. Happy coding! |
0 commit comments