TeslasuitDocumentation
APIs

Read heart rate

C# 7.3+ · Teslasuit XR5+ · SDK 2.5.1+

Read live heart rate from a Teslasuit photoplethysmography (PPG) node: start raw streaming and print the heart rate as each reading arrives.

Code for heart rate data#

using System;
using System.Linq;
using System.Threading;
using TsSDK;
using TsAPI;

internal static class Program
{
    private static void Main()
    {
        // Resolve the native library and create the single root instance.
        TsRoot.InitSDKInstallation();
        using var tsRoot = new TsRoot();

        // Poll until a device is attached (Control Center owns the connection).
        IDevice device = null;
        while (device == null)
        {
            Console.WriteLine("Waiting for a device...");
            device = tsRoot.DeviceManager.Devices.FirstOrDefault();
            Thread.Sleep(100);
        }

        Console.WriteLine($"Using device: {device.ProductType}");

        IPpg ppg = device.Biometry.Ppg;

        // Processed updates arrive on a background thread.
        ppg.ProcessedUpdated += OnProcessedUpdated;

        ppg.Start();

        Console.WriteLine("Press Enter to end");
        Console.ReadLine();

        ppg.Stop();
        ppg.ProcessedUpdated -= OnProcessedUpdated;
    }

    private static void OnProcessedUpdated(IProcessedPpgData data)
    {
        foreach (ProcessedPpgNodeData node in data.NodesData)
        {
            // The suit has one PPG sensor node, so it's always the suit itself.
            if (node.isHeartrateValid)
            {
                Console.WriteLine($"Heart rate: {node.heartRate}");
            }
        }
    }
}

Expected output#

Waiting for a device...
Using device: Suit
Press Enter to end
Heart rate: 72
Heart rate: 74
...

Explore these references and guides to build on this example and get the most out of Teslasuit PPG features:

Essential API references#

Practical guides & examples#

Deeper dives & broader concepts#

  • PPG main concept: The conceptual background behind the photoplethysmography subsystem.
  • Teslasuit Main Concepts: Fundamental articles explaining Teslasuit technology and how PPG fits within the larger suite of subsystems.