LoginSignup
13
12

More than 5 years have passed since last update.

USB 温度計で気温を測る(TEMPer; ID=413d:2107)

Last updated at Posted at 2018-05-04

研究室のサーバールームの空調が止まって大変なことになったことがある.室温が上昇したら slack 通知するようなものを作った.そのときに USB 温度計の扱いに苦労したのでそのことについて書く.

Amazon で購入できる usb 温度計 TEMPer

付属のソフトウェアを使わずに温度を取ってこられるように,いろいろな人が github にプロジェクトを作っている.

どこかのタイミングでマイナーチェンジされており,私が購入したもの(venderID:productID = 413d:2107)は Github のリポジトリを clone するだけでは利用できなかった.

なんとか温度だけ取得する方法を見つけたので手順をまとめておく.

環境

  • Linux CentOS7
  • USB 温度計 TEMPer (venderID:productID = 413d:2107)

手順

購入した USB 温度計のデバイス ID の確認

$ lsusb
.
.
.
Bus 00X Device 00X: ID 413d:2107

USB温度計を接続した状態で lsusb コマンドを打つと, USB機器の一覧が表示される.ID が 413d:2107 のものがあることを確認する.

hidapi のインストール

(USB) HID 機器との通信用ライブラリの hidapi をインストールする.

$ git clone https://github.com/signal11/hidapi
$ cd hidapi/linux
$ make -f Makefile-manual

事前に依存パッケージのインストールが必要な場合がある.

On Linux, you will need to install development packages for libudev,
libusb and optionally Fox-toolkit (for the test GUI). On
Debian/Ubuntu systems these can be installed by running:
sudo apt-get install libudev-dev libusb-1.0-0-dev libfox-1.6-dev
If you downloaded the source directly from the git repository (using
git clone), you'll need Autotools:
sudo apt-get install autotools-dev autoconf automake libtool

TEMPerd のインストール

この USB 温度計用のライブラリをインストールする.

$ git clone https://github.com/hughesr/TEMPered
$ cd TEMPered
$ git checkout hack-413d-2107
$ git reset --hard 75aa1e2
$ cmake .
$ make
  • USB 温度計のデバイス ID がそもそも対応しているものなのであれば,clone して cmake するだけで良い.
  • cmake がインストールされていない場合はインストールしておく.

温度を取得する

USB 温度計を接続して utils 内の tempered を実行する.

$ utils/tempered
/dev/hidraw1 0: temperature 16.12 °C
/dev/hidraw1 1: Failed to get the temperature: Not enough data was read from the sensor.
/dev/hidraw1 1: no sensor data available

これで温度データが取得できる.

Python で温度データを利用する場合

温度以外の出力を省いて取得.

get_temperature.py
import subprocess

def getTemperature():
    response = subprocess.check_output('/absolute/path/to/tempered', universal_newlines=True)
    temperature = response.split(" ")[3]
    return temperature

temperature = getTemperature()

関連記事

13
12
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
13
12