{"id":26330996,"url":"https://github.com/viniciusmecosta/peatdata","last_synced_at":"2026-04-21T04:04:36.568Z","repository":{"id":272053468,"uuid":"915388970","full_name":"viniciusmecosta/PeatData","owner":"viniciusmecosta","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-29T13:24:53.000Z","size":242,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-29T14:11:12.093Z","etag":null,"topics":["docker-compose","fastapi","python","sqlalchemy","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/viniciusmecosta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-11T18:07:04.000Z","updated_at":"2025-05-29T13:05:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"7bfdeeaf-1add-4fea-8c77-e541a5c4759f","html_url":"https://github.com/viniciusmecosta/PeatData","commit_stats":null,"previous_names":["viniciusmecosta/peat-data","viniciusmecosta/apitempumipython","viniciusmecosta/peatdata"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/viniciusmecosta/PeatData","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciusmecosta%2FPeatData","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciusmecosta%2FPeatData/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciusmecosta%2FPeatData/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciusmecosta%2FPeatData/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viniciusmecosta","download_url":"https://codeload.github.com/viniciusmecosta/PeatData/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viniciusmecosta%2FPeatData/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259747216,"owners_count":22905310,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker-compose","fastapi","python","sqlalchemy","sqlite"],"created_at":"2025-03-15T22:18:57.460Z","updated_at":"2026-04-09T21:33:21.844Z","avatar_url":"https://github.com/viniciusmecosta.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Peat Data API Documentation\n\n\u003cp align=\"center\"\u003e \u003cstrong\u003eA comprehensive API for managing data from IoT devices, applications, and notifications.\u003c/strong\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/Python-3.9-blue?logo=python\u0026logoColor=white\" alt=\"Python Version\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/FastAPI-0.115.12-blue?logo=fastapi\u0026logoColor=white\" alt=\"FastAPI Version\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/SQLAlchemy-2.0-blue?logo=sqlalchemy\u0026logoColor=white\" alt=\"SQLAlchemy Version\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/Pydantic-2.10-blue\" alt=\"Pydantic Version\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/Docker-Supported-blue?logo=docker\u0026logoColor=white\" alt=\"Docker Support\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/MQTT-paho--mqtt-green?logo=mqtt\" alt=\"MQTT Client\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/license-MIT-green\" alt=\"License\"/\u003e\n\u003c/p\u003e\n\n-----\n\n## Table of Contents\n\n- [Overview](#overview)\n- [Getting Started](#getting-started)\n- [Authentication](#authentication)\n- [MQTT Client](#mqtt-client)\n- [Technologies Utilized](#technologies-utilized)\n- [Endpoints](#endpoints)\n    - [Temp-Humi Endpoints](#temp-humi-endpoints)\n    - [Level Endpoints](#level-endpoints)\n    - [Phone Endpoints](#phone-endpoints)\n    - [Email Endpoints](#email-endpoints)\n    - [Admin Endpoints](#admin-endpoints)\n- [Usage Examples](#usage-examples)\n\n-----\n\n## Overview\n\nThe **Peat Data API** provides a comprehensive interface for:\n\n- Receiving data from IoT devices via an MQTT server and storing it in the database.\n- Allowing mobile applications to retrieve historical data.\n- Managing contacts for notifications.\n- Administrative functions for data management.\n\n-----\n\n## Getting Started\n\n### 1\\. Clone the repository\n\n```bash\ngit clone https://github.com/viniciusmecosta/PeatData.git\ncd PeatData\n````\n\n### 2. Create and activate a virtual environment\n\n```bash\npython -m venv .venv\nsource .venv/bin/activate  # Linux/macOS\n.venv\\Scripts\\activate     # Windows\n```\n\n### 3. Create a `.env` file\n\nCreate a `.env` file in the root directory of the project with the required environment variables. Use `example.env` as\na template.\n\n```env\nAPI_TOKEN=your_token_here\nMQTT_BROKER=your_broker_here\nMQTT_PORT=your_port_here\nMQTT_USER=your_user_here\nMQTT_PASSWORD=your_password_here\nMQTT_TOPIC_SENSOR=your_sensor_topic_here\nMQTT_TOPIC_LEVEL=your_level_topic_here\n```\n\n### 4. Install dependencies\n\n```bash\npip install -r requirements.txt\n```\n\n### 5. Run the server\n\n```bash\nuvicorn app.main:app --reload\n```\n\n---\n\n## Authentication\n\nAll API endpoints require Bearer Token authentication. Include the token in the `Authorization` header of each request.\n\n```http\nAuthorization: Bearer YOUR_ACCESS_TOKEN\n```\n\n---\n\n## MQTT Client\n\nThe API acts as an MQTT client, subscribing to topics defined in the environment variables (`MQTT_TOPIC_SENSOR`,\n`MQTT_TOPIC_LEVEL`). It processes incoming messages and stores the data in the database using the `paho-mqtt` library.\n\n---\n\n## Technologies Utilized\n\n* **Language:** Python 3.9\n* **Framework:** FastAPI\n* **ASGI Server:** Uvicorn\n* **ORM:** SQLAlchemy\n* **Data Validation:** Pydantic\n* **MQTT Client:** Paho-MQTT\n* **Database:** SQLite\n* **Containerization:** Docker\n* **Environment Variables:** python-dotenv\n\n---\n\n## Endpoints\n\n### Temp-Humi Endpoints\n\n* `POST /temp-humi`: Submit temperature and humidity data to the database.\n* `GET /temp-humi`: Retrieve temperature and humidity data based on query parameters (`avg`, `last`, `days`, `date`).\n\n### Level Endpoints\n\n* `POST /level`: Submit feeder occupation level data to the database.\n* `GET /level`: Retrieve level data based on query parameters (`avg`, `last`, `days`, `date`).\n\n### Phone Endpoints\n\n* `POST /phone`: Add a new phone number to the database.\n* `GET /phone`: Retrieve all registered phone numbers.\n\n### Email Endpoints\n\n* `POST /email`: Add a new email address to the database.\n* `GET /email`: Retrieve all registered email addresses.\n\n### Admin Endpoints\n\n* `POST /generate-temp-humi-data`: Generate mock temperature and humidity data.\n* `DELETE /temp-humi`: Delete all sensor data records.\n* `POST /generate-level-data`: Generate mock level/distance data.\n* `DELETE /level`: Delete all level data records.\n* `POST /generate-email/{n}`: Generate `n` mock email records.\n* `DELETE /email`: Delete all email records.\n* `POST /generate-phone/{n}`: Generate `n` mock phone records.\n* `DELETE /phone`: Delete all phone records.\n\n---\n\n## Usage Examples\n\n### Python Example\n\n```python\nimport requests\n\nurl = \"http://127.0.0.1:8000/temp-humi\"\nheaders = {\"Authorization\": \"Bearer YOUR_ACCESS_TOKEN\"}\ndata = {\"temperature\": 23.5, \"humidity\": 60.0}\n\nresponse = requests.post(url, json=data, headers=headers)\nprint(response.json())\n```\n\n### cURL Example\n\n```bash\ncurl -X POST \\\n  http://127.0.0.1:8000/temp-humi \\\n  -H \"Authorization: Bearer YOUR_ACCESS_TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"temperature\":23.5,\"humidity\":60.0}'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviniciusmecosta%2Fpeatdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviniciusmecosta%2Fpeatdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviniciusmecosta%2Fpeatdata/lists"}