LoginSignup
5
4

More than 3 years have passed since last update.

Windows10にnobleをインストールする

Last updated at Posted at 2019-10-09

nobleとは

Node.jsでBluetooth LEを扱うためのモジュールです。

環境

※Windowsの場合、Bluetoothアダプタのデバイスドライバを差し替える作業をします。なるべくPC内蔵のBluetoothを使用せず、外付けのものを使用することをお勧めします。

Node.jsのインストール

こちらの記事が非常にわかりやすいです。
https://qiita.com/maecho/items/ae71da38c88418b806ff

Powershellでバージョンを確認します。(コマンドプロンプトでもいいです。)

> node -v
v10.16.3

nobleをインストール

試しにインストールしてみる

> npm install noble
(中略)
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\ProgramData\Anaconda3\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];

Python2じゃなきゃダメみたいです。

調べてみると、node-gypのインストールに失敗しているようです。
下記の記事で対策が紹介されています。
https://qiita.com/AkihiroTakamura/items/25ba516f8ec624e66ee7

PowerShellを管理者で実行して下記のコマンドを実行します。
(マシンスペックによっては10分ほど時間がかかるかもしれません。)

> npm install --global windows-build-tools

---------- Visual Studio Build Tools ----------
Successfully installed Visual Studio Build Tools.
------------------- Python --------------------
Successfully installed Python 2.7

Now configuring the Visual Studio Build Tools and Python...

All done!

+ windows-build-tools@5.2.2
added 145 packages from 99 contributors in 244.329s

再チャレンジ

> npm install noble
(中略)
+ noble@1.9.1
added 63 packages from 44 contributors, updated 1 package and audited 111 packages in 9.459s

うまくいきました。

デバイスドライバの差し替え

nobleのREADMEによると、Bluetoothアダプタのデバイスドライバを、ZadigというツールでWinUSBというドライバに書き換える必要があります。

ツールを起動して
image.png

Options -> List All Devices
image.png

Bluetoothアダプタを選択してReplace Driverをクリック
image.png

サンプルコードを実行

こちらの記事のコードで周辺のBLEデバイスを検索できれば成功です。
https://qiita.com/n0bisuke/items/00503d2b18fc4f413c4e

インストールされたpython2のパス問題

windows-build-toolsを入れたときにpython2がインストールされましたが、
Windowsの環境変数からPATHをみると
C:\Users\user\.windows-build-tools\python27
というパスが追加されていました。

私の環境ではこれのせいでpythonのデフォルトがpython2になってしまいました。
解決策としては、python3のpython.exeの名前をpython3.exeとする方法があります。

ただ、この方法ではなんとなく悔しいので、何かいい方法があれば教えていただけると嬉しいです。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4