Skip to content

angulastudio/Biosensing-API

Repository files navigation

Biosensing API

forthebadge forthebadge forthebadge

Table of Contents

  1. Description
  2. Installation
  3. Base URL
  4. Endpoints
  5. Example Scripts
  6. Postman Collection

Description

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.

Installation

  1. Clone the repository
   git clone [email protected]:ServirGt/Biosensing-API.git
  1. Create an enviroment (optional but recommended)
   python3 -m venv venv
  1. Activate the virtual environment
   source venv/bin/activate
  1. Install requirements
   pip3 install -r requirements.txt

Running the API

   uvicorn app:app --reload

Base URL

http://localhost:8000

Endpoints

1. Set Device Address

  • URL: /set_address
  • Method: POST
  • Description: Sets the address of the Polar device.

Request Body

{
    "address": "ADDRESS POLAR DEVICE"
}

Response

{
    "message": "Device address set to D12EA708-D2E2-A337-3E1B-C75976067C2F"
}

Example usage

curl -X POST "http://localhost:8000/set_address" -H "Content-Type: application/json" -d '{"address": "ADDRESS POLAR DEVICE"}'

2. Connect to Polar Device

  • URL: /connect
  • Method: GET
  • Description: Connects to the Polar device with the previously set address.

Response

{
    "message": "Connected to Polar device"
}

Example usage

curl -X GET "http://localhost:8000/connect"

3. Start Notifications

  • URL: /start_notifications
  • Method: GET
  • Description: Starts heart rate and RR notifications from the Polar device.

Response

{
    "message": "Notifications started"
}

Example usage

curl -X GET "http://localhost:8000/start_notifications"

4. Stop Notifications

  • URL: /stop_notifications
  • Method: GET
  • Description: Stops notifications and returns the final average HRV.

Response

{
    "message": "Final average HRV: 85.23\nNotifications stopped"
}

Example usage

curl -X GET "http://localhost:8000/stop_notifications"

5. Get Heart Rate

  • URL: /heart_rate
  • Method: GET
  • Description: Returns the latest heart rate reading.

Response

{
    "heart_rate": 65
}

Example usage

curl -X GET "http://localhost:8000/heart_rate"

6. Get RR Peaks

  • URL: /rr_peaks
  • Method: GET
  • Description: Returns the latest RR peaks reading.

Response

{
    "rr_peaks": 1100
}

Example usage

curl -X GET "http://localhost:8000/rr_peaks"

7. Get HRV

  • URL: /hrv
  • Method: GET
  • Description: Returns the average HRV of the last 10 readings.

Response

{
    "hrv": 75.42
}

Example usage

curl -X GET "http://localhost:8000/hrv"

Postman Collection

We have provided a Postman collection to help you test and interact with the PolarAPI.

Importing the Collection

  1. Download the Biosense Postman Collection.
  2. Open Postman and go to the "Collections" tab.
  3. Click the "Import" button and select the downloaded JSON file.

Setting Up Environment Variables

  1. In Postman, go to the "Environments" tab.
  2. Click the "Import" button and select the Biosense Environment file.
  3. Ensure the base_url and device_address variables are correctly set in the environment.

Using the Collection

  1. Select the Biosense environment in Postman.
  2. Use the requests in the Biosense collection to interact with the API.

Requests Available on the Collection

  • 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.

License

Licensed under the MIT License, Copyright © 2023-present Servir

Releases

No releases published

Packages

No packages published

Languages