{"id":21814004,"url":"https://github.com/hoanhan101/pi-hub","last_synced_at":"2026-04-10T13:31:44.294Z","repository":{"id":52160199,"uuid":"132668782","full_name":"hoanhan101/pi-hub","owner":"hoanhan101","description":"A RESTful API monitoring solution for temperature and humidity sensor readings","archived":false,"fork":false,"pushed_at":"2022-06-27T16:10:30.000Z","size":47,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-21T09:29:25.915Z","etag":null,"topics":["raspberry-pi","rest-api","sensor"],"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/hoanhan101.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}},"created_at":"2018-05-08T21:47:55.000Z","updated_at":"2018-05-27T19:05:27.000Z","dependencies_parsed_at":"2022-08-28T15:52:38.188Z","dependency_job_id":null,"html_url":"https://github.com/hoanhan101/pi-hub","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hoanhan101/pi-hub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoanhan101%2Fpi-hub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoanhan101%2Fpi-hub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoanhan101%2Fpi-hub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoanhan101%2Fpi-hub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoanhan101","download_url":"https://codeload.github.com/hoanhan101/pi-hub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoanhan101%2Fpi-hub/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018013,"owners_count":26086235,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["raspberry-pi","rest-api","sensor"],"created_at":"2024-11-27T14:34:51.229Z","updated_at":"2025-10-14T05:39:54.738Z","avatar_url":"https://github.com/hoanhan101.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pi-hub\n\n**pi-hub** is a management system that stores temperature and humidity sensor readings from a \ncollection of Raspberry Pi and uses a simple RESTful API to provide a simple monitoring solution.\n\n## Project status\n\nThe project is complete. API is documented. Docker is available.\n\n## Table of Contents\n\n- [Getting Started](#getting-started)\n- [Structure](#structure)\n- [API](#api)\n- [Sensor Workshop](#sensor-workshop)\n\n## Getting Started\n\n**Build and run Docker containers**\n```sh\n./compose.sh\n```\n\n**Verify with `curl`**\n```sh\ncurl http://localhost:5000/test\n```\n\nSee the [API documentation](#api) for more details.\n\n### Structure\n\nFilename | Description\n--- | ---\n[Dockerfile](Dockerfile) | Dockerfile for pi-hub server: install dependencies, setup MySQL and expose endpoints.\n[compose.sh](compose.sh) | Script to orchestrate mysql-sever container and pi-hub server.\n[config.py](config.py) | Global configurations hub.\n[helper.py](helper.py) | Helper functions.\n[hub.py](hub.py) | Main server logic using flask, contains a list of available endpoints.\n[hub_test.py](hub_test.py) | Simple test for [hub.py](hub.py)\n[install_requirements.sh](install_requirements.sh) | Install python dependencies.\n[requirements.txt](requirements.txt) | Python dependencies.\n[sample_client.py](sample_client.py) | Sample client who uses pi-hub.\n[setup_mysql.py](setup_mysql.py) | Script to setup MySQL correctly: create database and setup tables.\n[sql.py](sql.py) | List of available SQL functions using MySQL Connector.\n[start.sh](start.sh) | Script for Docker container initialization, used by Dockerfile.\n\n## API\n\n**List of all available endpoints**\n\nMethod | Endpoint | Description\n--- | --- | ---\nGET/POST | `/test` | Test if the server is alive and reachable.\nGET | `/config` | Get a list of configurations.\nGET | `/scan` | Get a list of sensors with their locations.\nGET | `/read/all` | Get a list of all sensor readings.\nGET | `/read/max` | Get a maximum sensor readings.\nGET | `/read/last_hour` | Get all reading from the last hour.\nGET | `/read/last_hour/max` | Get a maximum reading from the last hour.\nGET | `/read/yesterday` | Get all reading from yesterday.\nGET | `/read/yesterday/max` | Get a maximum reading from yesterday.\nGET | `/read/\u003cint:id\u003e` | Get all reading for a specific sensor.\nGET | `/read/\u003cint:id\u003e/last_hour` | Get all reading for a specific sensor from the last hour.\nGET | `/read/\u003cint:id\u003e/yesterday` | Get all reading for a specific sensor from yesterday.\nPOST | `/write` | Publish a sensor reading to the system.\n\n**Sample responses**\n\n```sh\n/test\n    {'status': 'ok', 'timestamp': 'Sat May 26 16:41:38 2018'}\n\n/config\n    {'debug': True,\n     'mysql': {'database': 'sensor_workshop',\n               'host': 'mysql1',\n               'password': '',\n               'port': 3306,\n               'user': 'root'},\n     'pretty_json': True,\n     'url': 'http://54.172.51.227:5000'}\n\n/scan\n    {'sensors': [{'id': 5, 'location': 2}]}\n\n/read/all\n    [{'data': {'humidity': {'unit': '%', 'value': 60.1},\n               'temperature': {'unit': 'C', 'value': 20.2}},\n      'id': 5,\n      'timestamp': '2018-05-26 16:41:28'}]\n\n/read/max\n    [{'data': {'humidity': {'unit': '%', 'value': 60.1},\n               'temperature': {'unit': 'C', 'value': 20.2}},\n      'id': 5,\n      'timestamp': '2018-05-26 16:41:28'}]\n\n/read/last_hour\n    [{'data': {'humidity': {'unit': '%', 'value': 60.1},\n               'temperature': {'unit': 'C', 'value': 20.2}},\n      'id': 5,\n      'timestamp': '2018-05-26 16:41:28'}]\n\n/read/last_hour/max\n    ditto\n\n/read/yesterday\n    ditto\n\n/read/yesterday/max\n    ditto\n\n/read/1\n    ditto\n\n/read/1/last_hour\n    ditto\n\n/read/1/yesterday\n    ditto\n\n/write\n    {'error': None, 'id': 1, 'timestamp': 'Sat May 26 16:41:39 2018'}\n```\n\n## Sensor Workshop\n\nInstall git if you have not:\n```sh\nsudo apt-get install git\n```\n\nClone the project:\n```sh\ngit clone https://github.com/hoanhan101/pi-hub.git\n```\n\nCopy your program file into pi-hub folder. For example, my program's name is `read_sensor.py`:\n```sh\ncp read_sensor.py pi-hub/read_sensor.py\n```\n\nChange directory to pi-hub and install dependencies:\n```sh\ncd pi-hub \u0026\u0026 ./install_requirements.sh\n```\n\nAdapt this code to your program:\n```python\n\nimport time\nimport helper # This helper library will help us push the sensor reading to the collection server.\n\n# Imagine your functions' definitions are here. Below is your main program.\n\n# It will look similar to this.\n\n# Define a variable name SENSOR_ID to save your sensor id. For example, my sensor id is 1. \nSENSOR_ID = 1\n\n# Define your location, which is assigned by the visualization team. For example, my location is A10.\nLOCATION = 'A10'\n\n# Define how much time do you want to wait between each send to the server.\n# Any value from 15 to 30 seconds is good enough. Below will be too much overhead for the server.\n# You don't want to hurt the server, do you?\nSLEEP_TIME = 15\n\n# Loop forever.\nwhile True:\n    block = get_reading()\n    temp = convert_temp_reading(block[0], block[1], mode='celsius')\n    humidity = convert_humidity_reading(block[3], block[4])\n\n    # Publish the sensor reading to the server, providing sensor id and its location.\n    helper.post(SENSOR_ID, LOCATION, temp, humidity)\n\n    # Sleep for some time then repeat.\n    time.sleep(SLEEP_TIME)\n```\n\nAfter following these steps above, you should be able to send data to the server by executing:\n```sh\n./read_sensor.py\n```\n\nIf you receive an output like this, it means that you have successfully pulish your reading to the\nserver:\n```sh\n{'error': None, 'id': 1, 'timestamp': 'Sat May 26 16:41:39 2018'}\n```\n\nBravo!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoanhan101%2Fpi-hub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoanhan101%2Fpi-hub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoanhan101%2Fpi-hub/lists"}