The Biosensing API is an API that streams real-time data from Polar heart rate sensors. It transmits real-time data such as heartbeats, RR peaks, and HRV.
- Clone the repository
git clone [email protected]:ServirGt/Biosensing-API.git
- Create an enviroment (optional but recommended)
python3 -m venv venv
- Activate the virtual environment
source venv/bin/activate
- Install requirements
pip3 install -r requirements.txt
uvicorn app:app --reload
- URL:
/set_address
- Method:
POST
- Description: Sets the address of the Polar device.
{
"address": "ADDRESS POLAR DEVICE"
}
{
"message": "Device address set to D12EA708-D2E2-A337-3E1B-C75976067C2F"
}
curl -X POST "http://localhost:8000/set_address" -H "Content-Type: application/json" -d '{"address": "ADDRESS POLAR DEVICE"}'
- URL:
/connect
- Method:
GET
- Description: Connects to the Polar device with the previously set address.
{
"message": "Connected to Polar device"
}
curl -X GET "http://localhost:8000/connect"
- URL:
/start_notifications
- Method:
GET
- Description: Starts heart rate and RR notifications from the Polar device.
{
"message": "Notifications started"
}
curl -X GET "http://localhost:8000/start_notifications"
- URL:
/stop_notifications
- Method:
GET
- Description: Stops notifications and returns the final average HRV.
{
"message": "Final average HRV: 85.23\nNotifications stopped"
}
curl -X GET "http://localhost:8000/stop_notifications"
- URL:
/heart_rate
- Method:
GET
- Description: Returns the latest heart rate reading.
{
"heart_rate": 65
}
curl -X GET "http://localhost:8000/heart_rate"
- URL:
/rr_peaks
- Method:
GET
- Description: Returns the latest RR peaks reading.
{
"rr_peaks": 1100
}
curl -X GET "http://localhost:8000/rr_peaks"
- URL:
/hrv
- Method:
GET
- Description: Returns the average HRV of the last 10 readings.
{
"hrv": 75.42
}
curl -X GET "http://localhost:8000/hrv"
We have provided a Postman collection to help you test and interact with the PolarAPI.
- Download the Biosense Postman Collection.
- Open Postman and go to the "Collections" tab.
- Click the "Import" button and select the downloaded JSON file.
- In Postman, go to the "Environments" tab.
- Click the "Import" button and select the Biosense Environment file.
- Ensure the
base_url
anddevice_address
variables are correctly set in the environment.
- Select the
Biosense
environment in Postman. - Use the requests in the
Biosense
collection to interact with the API.
- Scan: Sets the address of the Polar device.
- Set Address: Sets the address of the Polar device.
- Connect: Connects to the Polar device.
- Start Notifications: Starts heart rate and RR notifications.
- Stop Notifications: Stops notifications and returns the final average HRV.
- Heart Rate: Returns the latest heart rate reading.
- RR Peaks: Returns the latest RR peaks reading.
- HRV: Returns the average HRV of the last 10 readings.
Licensed under the MIT License, Copyright © 2023-present Servir