{"id":18336493,"url":"https://github.com/reinskywalker/esp32-rest-sensor","last_synced_at":"2025-04-09T19:55:48.840Z","repository":{"id":244278429,"uuid":"814653866","full_name":"reinskywalker/esp32-rest-sensor","owner":"reinskywalker","description":"A dead simplee esp32 REST sensor for temp and humidity","archived":false,"fork":false,"pushed_at":"2024-06-14T11:58:10.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T19:55:44.369Z","etag":null,"topics":[],"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/reinskywalker.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}},"created_at":"2024-06-13T12:35:56.000Z","updated_at":"2024-06-14T11:58:13.000Z","dependencies_parsed_at":"2024-11-05T20:11:36.211Z","dependency_job_id":"afb8cc75-0e78-4b17-b43b-0e58fc944385","html_url":"https://github.com/reinskywalker/esp32-rest-sensor","commit_stats":null,"previous_names":["reinskywalker/esp32-rest-sensor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reinskywalker%2Fesp32-rest-sensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reinskywalker%2Fesp32-rest-sensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reinskywalker%2Fesp32-rest-sensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reinskywalker%2Fesp32-rest-sensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reinskywalker","download_url":"https://codeload.github.com/reinskywalker/esp32-rest-sensor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103911,"owners_count":21048245,"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":[],"created_at":"2024-11-05T20:08:06.334Z","updated_at":"2025-04-09T19:55:48.818Z","avatar_url":"https://github.com/reinskywalker.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"The Python Flask code snippet you provided sets up a simple web server capable of receiving POST requests containing JSON data, specifically for temperature and humidity values. Here's a detailed breakdown of its components and functionality:\n\n![](https://raw.githubusercontent.com/reinskywalker/esp32-rest-sensor/main/image/image.png)\n\n### Flask Application Overview\n\n- **Application Setup**: The application is built using Flask, a lightweight WSGI web application framework in Python. It is designed to be quick and easy to get started with, making it an excellent choice for simple web APIs.\n\n### Route Description\n\n- **Endpoint**: `'/data'`\n  - This endpoint listens for POST requests. It is intended to receive JSON data that includes temperature and humidity readings.\n  \n- **Function**: `sensor_data()`\n  - This function processes incoming POST requests to the `/data` endpoint.\n  \n### Request Handling\n\n- **JSON Data Retrieval**: \n  - `data = request.get_json()` extracts JSON data from the incoming POST request. Flask automatically handles the parsing of JSON data if the `Content-Type` header of the request is set to `application/json`.\n  \n- **Data Processing**:\n  - The temperature and humidity values are extracted from the JSON data using `data.get('temperature')` and `data.get('humidity')`. The `.get()` method is used for safe access, which returns `None` if the specified key does not exist, rather than throwing an error.\n  - These values are then printed to the console with the format: `\"Received temperature: {t}°C, humidity: {h}%\"`. This logging is helpful for debugging and monitoring the data received by the server.\n\n### Response Construction\n\n- **Response JSON Object**:\n  - A response JSON object is constructed containing a message stating `\"Data received successfully\"`, along with the received `temperature` and `humidity` values. This response confirms to the client that the data was received and processed.\n  \n- **Response Return**:\n  - `return jsonify(res), 200` sends the response back to the client. The `jsonify` function from Flask converts the Python dictionary into a JSON response. The `200` HTTP status code indicates that the request has been processed successfully.\n\n### Server Execution\n\n- **Running the Server**:\n  - `if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)`\n  - This condition ensures that the Flask server runs directly when the script is executed, not when imported as a module.\n  - `host='0.0.0.0'` tells the server to be accessible externally, not just locally. It listens on all network interfaces.\n  - `port=5000` specifies that the server will be accessible on TCP port 5000, which is the default port for Flask development servers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freinskywalker%2Fesp32-rest-sensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freinskywalker%2Fesp32-rest-sensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freinskywalker%2Fesp32-rest-sensor/lists"}