Metadata-Version: 2.4 Name: pressure-sensor-server Version: 0.1.0 Summary: ESP32 pressure readings receiver using Flask + SQLite Requires-Python: >=3.10 Description-Content-Type: text/markdown Requires-Dist: flask>=3.0.0 # 压力数据接收服务器(Flask + SQLite, uv 管理) 本服务用于接收 ESP32 固件上报的压力数据,并提供增删改查接口。 - 语言/框架:Python 3.10+、Flask - 存储:SQLite(本地文件 `readings.db`) - 依赖管理:uv(PEP 标准 `pyproject.toml`) ## 快速开始(Windows PowerShell) 1) 安装 uv(任选一种): ```powershell irm https://astral.sh/uv/install.ps1 | iex ``` 或使用 pipx: ```powershell pipx install uv ``` 2) 安装依赖并创建虚拟环境: ```powershell cd dataServer uv sync ``` 3) 启动服务(两种方式): - 方式 A:Flask 命令(可热重载) ```powershell $env:FLASK_APP = "app.py" uv run flask run --host 0.0.0.0 --port 5000 ``` - 方式 B:直接运行 Python ```powershell uv run python app.py ``` > 如需我等待你手动启动服务:请直接告诉我,我会等待 30 秒再继续。 ## 配置 - 环境变量: - `DB_PATH`:SQLite 文件路径,默认 `./readings.db` - `HOST`:服务监听地址(用于 `python app.py`),默认 `0.0.0.0` - `PORT`:服务端口(用于 `python app.py`),默认 `5000` ## 接口说明 - 健康检查: - `GET /health` - 接收上报(供 ESP32 固件使用): - `POST /data` - JSON 示例: ```bash curl -X POST http://localhost:5000/data \ -H "Content-Type: application/json" \ -d '{"device_id":"test","timestamp":"2023-01-01T12:00:00Z","pressure":0.1,"voltage":2.5}' ``` - 查询列表: - `GET /api/readings?device_id=&start=&end=&page=1&page_size=50&sort=desc` - 获取单条: - `GET /api/readings/` - 新增: - `POST /api/readings`(同 `/data` 体) - 更新: - `PUT /api/readings/`(可部分字段) - 删除: - `DELETE /api/readings/` ## 备注 - 时间戳接受 ISO8601,支持 `Z`(将归一化为 `+00:00`)。未提供时间戳则使用服务器当前 UTC 时间。 - SQLite 采用 WAL 模式,适合多读少写。 - 若需持久化到指定目录,请设置 `DB_PATH` 并确保写权限。