質問するログイン新規登録

Q&A

0回答

181閲覧

pythonでの、Bluetooth Battery MonitorのAPI利用について

suchiepai

総合スコア0

Bluetooth

Bluetoothとは短距離の間でデータを交換するための無線通信規格である。固定・モバイル両方のデバイスから、短波の電波送信を行うことで、高いセキュリティをもつパーソナルエリアネットワーク(PAN)を構築する。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

0グッド

1クリップ

投稿2026/01/11 14:39

編集2026/01/12 03:43

0

1

実現したいこと

画像にあるextraの値を得たいです

前提

Bluetooth Battery MonitorのAPIに問い合わせ

###質問の内容
win11でBluetooth Battery Monitorというbluetoothデバイスのバッテリー状況を
モニタするアプリを利用しているのですが(有料、試用期間あり)、
常時表示ができません。ですが、
https://www.bluetoothgoodies.com/info/battery-monitor-api/
このようなAPIが提供されているため、自作に挑戦してみようと思いました。
そこでコードを作ってみたのですが、
画像のようにJBL Soundgear Senceのextraとして
"L:100 R:99 C:50"の値があるはずだと思うのですが、nullになってしまいます。

Bluetooth Battery Monitorの画面。Soundgear Senceのextraが取得できています
イメージ説明
自作コードの実行結果。取得できず、nullに
イメージ説明

なぜなのかわかりません。
よろしくお願いします。

該当のソースコード

python 3.13.3, pyside6 6.10.1, requests 2.32.5 import sys, os import time import requests import json import atexit from PySide6.QtCore import Qt from PySide6.QtWidgets import (QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QMessageBox ) class MainWindow(QWidget): def __init__(self): super().__init__() atexit.register(self.closing_process) self.label_device_01 = QLabel() self.label_device_02 = QLabel() self.label_device_03 = QLabel() self.label_device_04 = QLabel() self.label_device_05 = QLabel() layout_v = QVBoxLayout() layout_h = QHBoxLayout() layout_v.addWidget(self.label_device_01) self.setLayout(layout_v) self.get_devices() def get_devices(self): devices = requests.get(r"http://127.0.0.1:9876/devices") return_data = {"status": devices.status_code, "data": devices.json()} json_str = json.dumps(return_data, ensure_ascii=False, indent=4) self.label_device_01.setText(json_str) def closing_process(self): QMessageBox.information(None,"","closing_process実行") if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() #window.setWindowTitle("BluetoothBatteryMonitorUI") window.setWindowFlag(Qt.FramelessWindowHint) window.show() sys.exit(app.exec())

試したこと

params = {"extra": "extra"} devices = requests.get(r"http://127.0.0.1:9876/devices", params=params)

としてみました。
・Bluetooth Battery Monitorは購入済みです。
・paramsの値をvalue、string、keyなど組み合わせてみました。
・soundgearを一旦削除して、再ペアリングしました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

hiroki-o

2026/01/11 15:23 編集

リンク先の仕様を読んだところ、extraにはnullではなく、何らかの文字列を指定するようです。 あと、ソースが見づらいので ```Python ここにソースを貼る ``` ようにしてください。質問は編集できます。 (追記) extraにはnullではなくextraを指定したのですね。失礼しました。
suchiepai

2026/01/11 23:28

コメントありがとうございます。 質問を修正しました。これで合ってますでしょうか。
hiroki-o

2026/01/12 02:45 編集

修正ありがとうございました。 現状、Bluetooth Battery Monitorを起動している状態で、 curl http://127.0.0.1:9876/devices を叩くと何が返ってきますか? (結果を質問に追記してください)
suchiepai

2026/01/12 02:57

コマンドプロンプトで実行するということですよね。 Soundgear 未接続 ``` {"devices":[{"connected":false,"extra":null,"icon":"C:\\Windows\\System32\\DDORes.dll,-3021","level":80,"name":"Aukey EP-B26"},{"connected":false,"extra":null,"icon":"C:\\Windows\\System32\\DDORes.dll,-3021","level":99,"name":"JBL Soundgear Sense"}],"version":"2.23.2.1"} ``` Soundgear接続 ``` {"devices":[{"connected":false,"extra":null,"icon":"C:\\Windows\\System32\\DDORes.dll,-3021","level":80,"name":"Aukey EP-B26"},{"connected":true,"extra":null,"icon":"C:\\Windows\\System32\\DDORes.dll,-3021","level":98,"name":"JBL Soundgear Sense"}],"version":"2.23.2.1"} ``` このようになりました。
hiroki-o

2026/01/12 03:19

それでnullとなるのは謎ですね。 もしかして無料期限が切れると値を返さなくなるとか... うちのBluetooth機器でextraを返すものがあったら、試してみます。 基本的には、返ってきたJSONからextraの値をパースする方向になると思います。
suchiepai

2026/01/12 03:43

お時間を割いていただきありがとうございます。 「試したこと」を追加しました。
dodox86

2026/01/14 11:23

試す環境が無いので質問文からの推測ですが、name: "JBL Soundgear Sense"のデバイスの"connected"が"false"になってます。これはBluetoothのペアリングは済んでいるけども、バッテリー情報、つまりextraの値を取る為に必要なBluetooth接続をしていない状態で、その為にnullなのでは?と思いました。他の情報はBluetooth接続していなくてもペアリング済みであれば取得できる情報なのだと思います。
dodox86

2026/01/14 11:31

extraの値はAPIの解説によると > Using the API > Current API implements only one endpoint GET /devices, which returns the JSON object that contains the following attributes. とあるので、HTTPリクエスト自体には期待するextraの値をセットする訳ではなく、返ってくるHTTPレスポンス中のJSONオブジェクト/文字列情報の中のextraを参照するだけ、のように読めます。つまり、要求時にセットする訳ではない。 > Try the API. > Enter the following command into the command prompt window: curl http://127.0.0.1:9876/devices > You should see the JSON response. とあるので、シンプルなHTTPのGETメソッドです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.29%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問