A Python-Flask-based application for collecting environmental sensor data on a Raspberry Pi and sending it to a central hub for further analysis and processing.
-
Environmental Data Collection:
- Utilizes the MH-Z19 sensor for CO₂ detection.
- Reads temperature, humidity, and pressure from the BME680 sensor.
- Includes mock sensors for testing without physical hardware.
-
REST API:
- Exposes a Flask RESTful endpoint (
/sensor-data
) to retrieve sensor data. - Sends sensor data to a configured remote API via an HTTP POST request.
- Exposes a Flask RESTful endpoint (
-
Error Handling:
- Handles HTTP and network-related errors during data transmission.
- Provides meaningful error responses for easier debugging.
- Hardware:
- Raspberry Pi
- MH-Z19 and BME680 sensors (optional for testing).
- Software:
- Python 3.x
- Required Python libraries (see Dependencies).
-
Clone this repository:
git clone https://github.com/your-username/enviro-node-pi.git cd enviro-node-pi
-
Install dependencies using
pip
:pip install -r requirements.txt
-
Create a
.env
file in the project root and specify your central hub API URL:API_URL=http://your-central-hub-api-url
-
Run the Flask app:
python app.py
The app includes mock data for testing when the required sensors are not physically connected. You can use the mock sensor classes to simulate various conditions.
- Method:
GET
- Description: Retrieves environmental data from sensors and forwards it to the configured API endpoint.
- Success:
{ "message": "Data sent successfully" }
- Error:
{ "message": "Error sending POST request: [error details]" }
Flask
: Python web framework.requests
: For sending HTTP POST requests.- Python libraries for sensors (mh_z19, bme680) when available.
python-dotenv
: For environment variable management.
Install dependencies:
pip install Flask flask-restful requests python-dotenv mh_z19 bme680
Contributions and suggestions are welcome! Please feel free to submit a pull request or open an issue for enhancements or bugs.
This project is open-source and available under the MIT License.