======温度・湿度センサー====== 参考 * https://www.infiniteloop.co.jp/blog/2013/02/raspberrypitem/ * http://blog.bnikka.com/raspberrypi/am2302dht22raspberrypi.html * http://tomo.blue/others/raspberrypi/%E6%B8%A9%E5%BA%A6%E3%83%BB%E6%B9%BF%E5%BA%A6%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/ GPIO端子 * 黄 (+) P1(1:3V) * 緑 (Out) P123(4:GPIO4) * 青 (-) P1の上の段 24(6:gnd) pythonインストール $ sudo apt-get update $ apt-get upgrade # apt-get upgradeすると、kernelがかきかわるので、fsprotectが無効になるはず・・・ (http://www.sabo-net.info/2015/06/09/raspberry-pi%E3%82%92readonly%E3%81%AB%E3%81%97%E3%81%A6%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E4%BF%9D%E8%AD%B7%EF%BC%81/) Adafruit_Python_DHTのソースコードを取得 $ sudo apt-get install build-essential python-dev $ sudo git clone https://github.com/adafruit/Adafruit_Python_DHT.git $ cd Adafruit_Python_DHT $ sudo python setup.py install 動作確認 $ cd examples $ sudo ./AdafruitDHT.py 22 4 Temp=19.0*C Humidity=46.0% スクリプト作成(temperature) $ cp AdafruitDHT.py temp.py $ vi temp.py if humidity is not None and temperature is not None: print '{}'.format(temperature) (ここを編集) - - - - 拡張 - - - - f=open('/var/log/temp.log', 'w') f.write('{:.1f}'.format(temperature)) f.close() - - - - スクリプト作成(humidity) $ cp AdafruitDHT.py humid.py $ vi humid.py if humidity is not None and temperature is not None: print '{}'.format(humidity) #!!!!!!!←ここを左記のように編集!!!!!!!! (ここを編集) $ sudo cp temp.py /usr/local/bin $ sudo cp humid.py /usr/local/bin apache導入 $ sudo apt-get install apache2 Mumin導入 $ sudo apt-get install munin munin-node Munin用スクリプト準備(temperature) $ sudo vi /usr/share/munin/plugins/temp #!/bin/sh #%# family=auto #%# capabilities=autoconf GETNUM=`python /usr/local/bin/temp.py 22 4` if [ "$1" = "autoconf" ]; then if [ -n ${GETNUM} ] ; then echo yes exit 0 else echo no exit 0 fi fi if [ "$1" = "config" ]; then echo 'graph_title temperature' echo 'graph_args -r --lower-limit 0' echo 'graph_vlabel C' echo 'graph_category Weather' echo 'total.label temperature' echo 'total.min 0' echo 'total.draw LINE2' echo 'total.type GAUGE' exit 0 fi echo "total.value $GETNUM"; Munin用スクリプト準備(humidity) $ sudo vi /usr/share/munin/plugins/humid #!/bin/sh #%# family=auto #%# capabilities=autoconf GETNUM=`python /usr/local/bin/humid.py 22 4` if [ "$1" = "autoconf" ]; then if [ -n ${GETNUM} ] ; then echo yes exit 0 else echo no exit 0 fi fi if [ "$1" = "config" ]; then echo 'graph_title humidity' echo 'graph_args -r --lower-limit 0' echo 'graph_vlabel %' echo 'graph_category Weather' echo 'total.label humidity' echo 'total.min 0' echo 'total.draw LINE2' echo 'total.type GAUGE' exit 0 fi echo "total.value $GETNUM"; munin用スクリプトの実行権限等を設定 $ chmod 755 /usr/share/munin/plugins/temp $ chmod 755 /usr/share/munin/plugins/humid $ sudo ln -s /usr/share/munin/plugins/temp /etc/munin/plugins/temp $ sudo ln -s /usr/share/munin/plugins/humid /etc/munin/plugins/humid munin pluginフォルダの設定 $ sudo chmod 755 /etc/munin/plugin-conf.d/ $ sudo vi /etc/munin/plugin-conf.d/temp [temp] user root $ sudo vi /etc/munin/plugin-conf.d/humid [humid] user root # vi /etc/munin/munin.conf dbdir /var/munin/lib htmldir /var/munin/www munin実行フォルダの設定 # mkdir /var/munin # mv /var/lib/munin /var/munin/lib # mv /var/cache/munin/www /var/munin/www # cd /var/www/html/ # ln -s /var/munin/www ./munin # vi /etc/apache2/conf-enabled/munin.conf Alias /munin "/var/munin/www" #Require local Require all granted Options None # vi /etc/apache2/conf-enabled/munin.conf #Require local Require all granted … munin のリスタート # /etc/init.d/munin stop # /etc/init.d/munin-node stop www/libをUSBメモリに作成する場合 # sudo chown -R munin.munin /var/munin/lib # sudo chown -R munin.munin /var/munin/www # chown -h munin.munin …. シンボリックリンクの場合は-hオプションを指定 # /etc/init.d/munin-node restart # apache2ctl restart USBメモリの準備 # fdisk /dev/sda Command (m for help): n Command (m for help): w # mkfs.ext4 /dev/sda1 # fdisk -l # blkid /dev/sda1 /dev/sda1: UUID="64ec5b43-30cf-4082-8129-78ee1c6a633d" TYPE="ext4" PARTUUID="64670bc5-b82f-43c6-82e3-d2577c356f60" # mkdir /mnt/usb01 # vi /etc/fstab UUID="c21e1887-bf12-4a2c-9303-abd2dd7c0127" /mnt/usb01 ext4 defaults 0 2 # mkdir /mnt/usb01 # mount -a # cp -r /var/munin /mnt/usb01 # chown -R munin.munin /mnt/usb01/munin # mv /var/munin /var/munin.org; ln -s /mnt/usb01/munin /var/munin (障害の際、/var/munin.orgを新usb01にコピーしchown してもよい) =====補足===== 黒ケースのIFで使うなら AdafruitDHT.py 22 3 でOK # sudo ./AdafruitDHT.py 22 3 [Chasis GND] - 茶 - [Sensor -] [Chasis 3.3V ] - 赤 - [Sensor out] [Chasis SCL ] - 橙 - [Sensor +] [Chasis SDA ] - 橙 - (open)