Streaming the data (real-time) from PineTime watch to PC/laptop with InfiniTime? #1470
Replies: 58 comments
-
The companion itd can do that for you. You can also write your own program if you want. You can pair with the watch via Bluetooth LE and subscribe to the according services. Just ask or see the docs for more details. Specifically for heart rate I would not trust the sensor for scientific purposes though, but that is only my take. It depends on what you want to do with it. |
Beta Was this translation helpful? Give feedback.
-
Here are a few additional info to @minacode's answer. InfiniTime exposes a few data via BLE:
The companion app can read those data (polling) or subscribe to the corresponding BLE characteristics to receive a notification each time the value changes (using the BLE NOTIFY functionality). |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your great help. I am very new to PineTime and InfiniTime. I know how to program though. My goal is simply to stream the data (real-time) from the PineTime watch to PC. And I've looked into both the InfiniTime document and the companion itd. May I please ask if can I directly start my project using the companion itd alone or do I need to do something with InfiniTime first? Are the two independent of each other? My last question is do you have any document/tutorial more beginner friendly to start with a PineTime Watch development kit? I find InfiniTime fascinating but have lost my direction in browsing the official document. I haven't been able to do anything with InfiniTime and my PineTime Watch development kit. Which should be the very first step? Thank you both for everything. Best regards |
Beta Was this translation helpful? Give feedback.
-
It's very simple.
Itd is not a project of InfiniTimeOrg, but itd exists only for InfiniTime and the author of itd is part of the itd community. Itd is not the only companion on Linux but it is the best supported one. There seems to be active communication between them. @JF002 can probably say this better. I don't know about the development kit, sorry. |
Beta Was this translation helpful? Give feedback.
-
It mostly depends on what you want to do. If InfiniTime already exposes the data you want to stream (steps, HR, battery), you don't need to change anything to InfiniTime. Same goes for the companion apps : ITD (but also Amazfish, Siglo, Gadgetbridge,...) already support most of the functionality from InfiniTime, so you probably won't need to do anything for them to work with InfiniTime.
InfiniTime and the companion apps are effectively independent projects, but we all work together to create a nice ecosystem around the PineTime. There are multiple companion apps that currently support the PineTime. Some of them also support other devices:
There are quite a lot of documentation available but it's probably a bit scattered around the web. Here are a few links
Thanks!
Yeah, I understand. We are currently trying to re-work the documentation but this is progressing slowly...
The first step would probably be to setup a development environment (or with docker for InfiniTime and/or for the companion app of your choice (refer to the project documentation). You can also use InfiniSim, the InfiniTime simlator to do some development. It mostly simulate the UI, and not the BLE connectivity, though. Then, if you have the devkit, you will also want to set it up with your SWD probe (here and here). |
Beta Was this translation helpful? Give feedback.
-
@minacode ,
My question is how do I start itd to trigger the watch to pair with my PC? I am sorry I am new to linux. I did something below but if didn't work: USAGE: COMMANDS: GLOBAL OPTIONS: |
Beta Was this translation helpful? Give feedback.
-
starts it.
makes it start every time when booting. So you have to do a separate start the first time. See here. (Since you are new to linux: there are also A prompt should appear on your linux and a code on your watch. |
Beta Was this translation helpful? Give feedback.
-
@minacode However, no prompt appears on my Linux and no code on my watch, either. Any idea? Thank you so much again. |
Beta Was this translation helpful? Give feedback.
-
Well, seems like you are connected 😉 Does itctl work? |
Beta Was this translation helpful? Give feedback.
-
@minacode, USAGE: COMMANDS: OPTIONS: [lui@crossbow ~]$ itctl get heart ` My last question is I'd love to display the heat rate data in number and line graph trough the itgui as shown in the picture below, however the itgui document is hard to follow, could you please elaborate a bit about how to use the itgui command? Thank you from the bottom of my heart. Cheers |
Beta Was this translation helpful? Give feedback.
-
To be clear, I find the following instruction from itgui hard to follow, could you please make it beginner friendly. Like where is cmd/itgui. Really appreciate it itgui In cmd/itgui, there is a gui frontend to the socket of itd. It uses the Fyne library for Go. Before compiling, certain prerequisites must be installed. These are listed on the following page: https://developer.fyne.io/started/#prerequisites It can be compiled by running: go build ./cmd/itgui Cross-compilation Due to the use of OpenGL, cross-compilation of itgui isn't as simple as that of itd and itctl. The following guide from the Fyne website should work for itgui: https://developer.fyne.io/started/cross-compiling. |
Beta Was this translation helpful? Give feedback.
-
You should be able to just run |
Beta Was this translation helpful? Give feedback.
-
Then move into the dir
and build according to the docs you cited with
Then run it with
which is basically just the path to it, depending on where you currently are. If this fails it might be due to me not testing this while typing or because you need to install the Also I would always recommend to install updates. Why stay on an older version? |
Beta Was this translation helpful? Give feedback.
-
@minacode I really appreciate your great support. You are so warm-hearted. And we are getting there |
Beta Was this translation helpful? Give feedback.
-
@FintasticMan Hi, thank you so much for your input. Just let you know that just run itgui on the command-line doesn't get that gui running somehow |
Beta Was this translation helpful? Give feedback.
-
@stevensu1838 you could pipe the itctl values into a file and read it regulary (30s intervals, for example) and pipe this again into another file. |
Beta Was this translation helpful? Give feedback.
-
The timestamped values are literally the most fine-grained x-y-coordinates for his plot he could ask for... |
Beta Was this translation helpful? Give feedback.
-
True, but depending on how the plot is made he may need the additional data points with unchanged values. |
Beta Was this translation helpful? Give feedback.
-
@Anachron Thank you both so much. I want the time interval every 1s or every 5s or every 30s. I do think I need the additional data points with unchanged values to make the plotting continuous. I am trying out your will. And can you please say a bit more about how 1) read the file regulary (30s intervals, for example) and 2) pipe this again into another file. I've never done this before. Cheers |
Beta Was this translation helpful? Give feedback.
-
@minacode @Anachron You guys are amazing! I've record the data with timestamps as @minacode instructed. And I am trying to read it regularly (5s intervals, for example) and pipe this again into another file. Do you know how to read it every a few seconds? Also, please let me know how I can add the additional data points with unchanged values to fill some of the empty value while reading the file regularly. You guys are awesome. I learn a lot from you all |
Beta Was this translation helpful? Give feedback.
-
I think you can just rename your file to a And don't name your files |
Beta Was this translation helpful? Give feedback.
-
@minacode Hi Thanks a lot for your tip. Yes, I can plot the unregular data points. My problem is I will try to plot the heart rate data from PineTime watch with the data from other smartwatches. For those watches, the heart rate data is logged every 5 or 10 or 30 seconds. To compare the data from PineWatch and other watches (such as sumsung watch), I think I will need to plot the data in the same figure in one plotting. So they will share the same X and Y axis. Did make myself clear? What do you think? How do I plot two data sets, one with regular intervals and the other one with the irregular interval, in the same plotting to compare? Thanks a lot. You save my life |
Beta Was this translation helpful? Give feedback.
-
Please find below an example of the two sets of data that I want to plot in one figure and compare. Please let me know if you have any good ideas. Cheers. |
Beta Was this translation helpful? Give feedback.
-
Are you sure? Sorry, but come on... Every technical help around InfiniTime aside, but if that is what you are researching then you should be able to figure out how to plot two graphs in the same diagram. I am not going to do your job. |
Beta Was this translation helpful? Give feedback.
-
@minacode Hi I think you misunderstood me, I will keep exploring and come back to you. Don't get pissed off by stupid questions. I've learnt a lot from you, you've helped me a lot and I hope you will be happy. Anyway, Let me think about it and come back to you soon. Be happy |
Beta Was this translation helpful? Give feedback.
-
Don't get me wrong. I gladly helped you and don't believe in "stupid questions". It's no problem to be inexperienced with Linux and such. We all start somewhere.
But I don't want to plot or interpret your numbers for you. That is not a technical problem. And its not even difficult. You know that the PineTimes values are constant between the data points, so you can perfectly estimate them. |
Beta Was this translation helpful? Give feedback.
-
@minacode Hi Thanks a lot for your understanding. Please forgive me if I ask the following question wrong. I am plotting the PineTime data your helped me saved and I am plotting it in matlab. I find this example on plotting very similar data. I can use the their code to plot their example data with no problem. However, when I switch to our data PineHeartOutput.csv, it throws the following errors: I don't really understand our data is the same as the example data. The only difference is we don't have AM or PM in the end of timestamps. Sorry if you don't even use matlab. Just feel like you know everything. Thanks a lot for all your help |
Beta Was this translation helpful? Give feedback.
-
I am not familiar with Matlab, sorry. The error says that the |
Beta Was this translation helpful? Give feedback.
-
In case you are familiar with Python, here's a snippet from a project that I am working on that reads heart rate data from InfiniTime using a library called bleak (https://github.com/hbldh/bleak). It won't work if the watch is already connected to a device. This script will handle the connection. Of course you would want to remove all of the seizure monitor related stuff. Don't worry about the copyright or the licence, you're welcome to use the code however you like. __author__ = "Benjamin Mickler"
__copyright__ = "Copyright 2022 Benjamin Mickler"
__credits__ = ["Benjamin Mickler"]
__license__ = "GPLv3 or later"
__version__ = "20221126"
__maintainer__ = "Benjamin Mickler"
__email__ = "[email protected]"
"""
This file is part of The Seizure AI Project.
The Seizure AI Project is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version.
The Seizure AI Project is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
The Seizure AI Project. If not, see <https://www.gnu.org/licenses/>.
"""
import asyncio
from bleak import BleakClient, BleakScanner
import requests
import json
import signal
import traceback
# MAC address: ff:1c:2a:bf:8a:3b
print("A small neural network to try to detect a seizure in 10 heart rate samples. All predictions are done on the server. Please use sparingly as the server only has 1GB of RAM and may not be able to make many predictions at once. It's only an experiment, don't rely on it to alert you to seizures. Copyright © Benjamin Mickler 2022\n")
threshold = input("Threshold (blank for 0.8): ")
if threshold == "":
threshold = 0.8
else:
threshold = float(threshold)
name = input("Heart rate monitor name (blank to use InfiniTime): ")
if name == "":
name = "InfiniTime"
def get_mac_address(name):
print(f"Searching for {name}")
from bleak import discover
devices = asyncio.run(BleakScanner.discover())
for d in devices:
if d.name == name:
return d.address
return None
readings = []
_models_response = requests.get("https://seizure.ai.benmickler.com/models")
_models = json.loads(_models_response.json())
models = {}
for i, model in enumerate(_models, start=1):
models[i] = model
service_uuid = "0000180d-0000-1000-8000-00805f9b34fb"
char_uuid = "00002a37-0000-1000-8000-00805f9b34fb"
async def run(address, loop):
disconnected_event = asyncio.Event()
def disconnected_callback(client):
print("Device disconnected")
disconnected_event.set()
client = BleakClient(address, loop=loop, disconnected_callback=disconnected_callback)
try:
await client.connect()
print(f"Connected: {client.is_connected}")
await client.start_notify(char_uuid, callback)
await disconnected_event.wait()
except Exception as e:
#print(traceback.format_exc())
pass
finally:
if client.is_connected:
print("\nDisconnecting")
await client.stop_notify(char_uuid)
await client.disconnect()
def callback(sender, data):
print("Received: {0}".format(data[-1]))
readings.append(data[-1])
if len(readings) >= 10:
print()
r = requests.post("https://seizure.ai.benmickler.com/predict", json={"model_name": model, "heart_rate": readings})
request_json = json.loads(r.json())
if "error" in request_json:
print(f"Error: {request_json['error']}")
else:
print(f"Result: {request_json['result']}")
print(f"Seizure: {'yes' if float(request_json['result']) >= threshold else 'no'}")
readings.pop(0)
if __name__ == "__main__":
print("Models:")
for k, v in models.items():
print(f"{k}: {v}")
model_input = int(input("Model: "))
if model_input not in models:
print("Invalid model")
exit(1)
model = models[model_input]
loop = asyncio.new_event_loop()
address = get_mac_address(name)
if address is None:
print(f"Could not find device with name {name}")
address = input("Please enter MAC address: ")
asyncio.run(run(address, loop)) |
Beta Was this translation helpful? Give feedback.
-
Let's continue this post in Discussions :-) |
Beta Was this translation helpful? Give feedback.
-
Verification
Pitch us your idea!
Streaming the data (real-time) from PineTime watch to PC/laptop with InfiniTime?
Description
Hi team
I am a researcher from an university, and we've been working on a project aiming to stream live data (such as heart rate data) from Pine Time watch to the PC/laptop. I've learned that the InfiniTime might be a good way to make our goal happen. May I please ask if streaming the data (real-time) from PineTime watch to PC/laptop is doable with InfiniTime? If so, I will give it a try. Cheers
Beta Was this translation helpful? Give feedback.
All reactions