2016年6月25日土曜日

Raspberry piにAndroid TVを入れる

Raspberry piにAndroid TVを入れる

Ubuntuを使ってRaspberry PI3用のAndroid TVのSDカードの作成方法をメモしておきます。

1.以下からAndroid TVのイメージをダウンロード

http://geektillithertz.com/wordpress/index.php/2016/06/02/android-tv-for-raspberry-pi-3/

2. イメージをSDカードへ書き込み

以下の手順でイメージを解凍して書き込み
システム→設定→ハードウエア→ディスク

3. アプリの追加

作成したSDカードのdataパーティションのappフォルダにapkファイルを置くことで
アプリが追加できる。

pybeaconを使ってみる

pybeaconを使ってみる

今、はやり?のeddystoneをRaspberry PI3でやってみようかと思った次第です。。

1.Pybeaconをダウンロードし、解凍

$ wget https://pypi.python.org/pypi/PyBeacon/
$ unzip mastar.zip

2. bluzとbluez-hcidumpをインストール

$ sudo apt-get install bluez bluez-hcidump

3. PyBeaconのインストール

$ cd PyBeacon-master
$ sudo pip3 install PyBeacon

4. PyBeaconの実行

1. URLを送りたいので以下を使って送りたいURLを短縮する。

    https://goo.gl/

$ PyBeacon -u https://goo.gl/Aq18zF

でも実行できるがURLを切り替えたいのPythonで実行

#! /usr/bin/python3

import subprocess
import time

def main():
    cmd = "PyBeacon -u "
    url = ""
    counter = 0
    check = subprocess.check_output(cmd + url, shell=True, universal_newlines=True)

    while True:
        counter += 1
        url = ""
        if counter == 5:
            url = "https://goo.gl/Aq18zF"
        elif counter == 10:
            url = "https://goo.gl/epjq13"
            counter = 0

        if url != "":
            print(cmd+url)
            check = subprocess.check_output(cmd + url, shell=True, universal_newlines=True)
        time.sleep(1.0)

if __name__ == "__main__":
    main()

5. Ghomeの設定

設定→プライバシー→フィジカルウェブをONすると、
Raspberry PI3からアドバタイジングされたURLを受け取ることが可能。

2016年6月19日日曜日

RaspberryPI3で照度センサー(TSL2561)を使ってみる

RaspberryPI3で照度センサー(TSL2561)を使ってみる

照度センサー(TSL2561)をRaspberryPI3に接続してみた。

1.Raspberry PI3でI2Cを有効にする

$ sudo raspi-config

Advance Option->I2Cで有効にするし、再起動。

$ lsmod

i2c_bcm2708,i2c_devが見れていればOK.

2.以下のようにRaspberry PI3と接続

GND (TSL2561) -> GPIO04 (Raspberry Piの9pin)
VCC (TSL2561) -> 3.3v (Raspberry Piの1pin)
SDA (TSL2561) -> GPIO08 SDA1(Raspberry Piの3pin)
SCL (TSL2561) -> GPIO09 SCL(Raspberry Piの5pin)
$ sudo apt-get install i2c-tools python-smbus
$ sudo i2cdetect -y 1
$ sudo apt install libi2c-dev

このようにでてくればOK
enter image description here

3.PythonからI2Cを叩く準備

1. wiringpiのインストール

以下を参考。
http://takashin10mura.blogspot.jp/2016/06/wiringpipython.html

2. SMBUSのインストール

python-smbusはよくでてくるがpython3で使うとなると少し手間がかかります。
以下のようにすればできました。

wget http://ftp.de.debian.org/debian/pool/main/i/i2c-tools/i2c-tools_3.1.1.orig.tar.bz2

tar -xf i2c-tools_3.1.1.orig.tar.bz2
cd i2c-tools-3.1.1/py-smbus
mv smbusmodule.c smbusmodule.c.orig # make backup
$ sudo wget https://gist.githubusercontent.com/sebastianludwig/c648a9e06c0dc2264fbd/raw/2b74f9e72bbdffe298ce02214be8ea1c20aa290f/smbusmodule.c
$ sudo vi setup.py
  /usr/bin/python3に修正
$ sudo python3 setup.py build
$ sudo python3 setup.py install

3. smbusの確認

$ python3
$ import smbus
ここでエラーがでなければOK

4.TSL2561の制御

データシートを参考に以下のコードで照度を取得できました。

#! /usr/bin/python3
#coding: UTF-8
#TSL2561 照度センサー

import smbus
import time
import math

bus = smbus.SMBus(1)        #I2cバス番号
address = 0x39              #I2Cアドレス
command = 0x00

#i2c データ出力 1byte
def write(regist, value):
    bus.write_byte_data(address, regist, value)

#i2c データ読み込み 1byte
def read(regist):
    value = bus.read_byte_data(address, regist)
    return value

#i2c データ読み込み ブロック
def blockread(regist, num):
    value = bus.read_i2c_block_data(address, regist, num)
    return value

def ratio_calc(ambient, ir):
    # Avoid division by zero
    if (float(ambient) == 0):
        ratio = 9999
    else:
        ratio = (ir / float(ambient))

    return ratio

def init():
    #read ID
    print("id_reg=0x{0:02x}".format(read(0x8A)))
    #device enable
    write(0x80,0x03)
    power = 0x03
    while power != 0x03:
        power = read(0x80) & 0x03
        print("{0:02x}".format(power))
    #print("reg=0x{0:02x}".format(read(0x80)))

    #gain setting
    write(0x81,0x11)
    print("reg=0x{0:02x}".format(read(0x81)))

def read_lux():
    value0 = blockread(0xAC,2)
    ch0 = 256*value0[1]+value0[0]
#    print("reg=0x{0:04x}".format(ch0))

    value1 = blockread(0xAE,2)
    ch1 = 256*value1[1]+value1[0]
#    print("reg=0x{0:04x}".format(ch1))

    ratio = ratio_calc(ch0,ch1)
    if ((ratio >= 0) & (ratio <= 0.52)):
        lux = (0.0315 * ch0) - (0.0593 * ch0 * (ratio**1.4))
    elif (ratio <= 0.65):
        lux = (0.0229 * ch0) - (0.0291 * ch1)
    elif (ratio <= 0.80):
        lux = (0.0157 * ch0) - (0.018 * ch1)
    elif (ratio <= 1.3):
        lux = (0.00338 * ch0) - (0.0026 * ch1)
    elif (ratio > 1.3):
        lux = 0

    return lux

def main():
    init()
    counter = 0
    while True:
        counter += 1
        if counter == 5:
            lux = read_lux()
            print("lux={0:f}".format(lux))
            counter = 0

        time.sleep(1.0)

if __name__ == '__main__':
    main()

RaspberryPI3に簡単に外からアクセスする方法

RaspberryPI3に簡単に外からアクセスする方法

スマホからRaspberryPI3に簡単にアクセスできる方法を探していたところngrokというものを知りました。

1.ここからLinux ARM版をダウンロードし、インストール

$ wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip
$ unzip ngrok-stable-linux-arm.zip
$ sudo mv ngrok /usr/bin

2.ngrokにsign upし、Dashboardにあるauthtokenをコピーし、以下を実行する。

enter image description here

$ ngrok authtoken xxxxxxxxxxxxxxx

3.解放するポートを設定する

$ ngrok tcp 22
ngrok by @inconshreveable                                                                        (Ctrl+C to quit)

Tunnel Status                 online                                                                             
Version                       2.0.25/2.1.1                                                                       
Region                        United States (us)                                                                 
Web Interface                 http://127.0.0.1:4040                                                              
Forwarding                    tcp://0.tcp.ngrok.io:14274 -> localhost:22                                                                                                                                                        
Connections                   ttl     opn     rt1     rt5     p50     p90                                        
                              0       0       0.00    0.00    0.00    0.00    

4.試しにスマホから繋いでみる。

Google PlayからConnectBotをインストールし、以下を入れる。
SSH: user名@0.tcp.ngrok.io:14274

スマホからRaspberryPI3へアクセスできました。

5.ngroxを自動起動する。

$ sudo vi ~/.ngrok2/ngrok.yml
authtoken: xxxxx
region: ap
tunnels:
  ssh:
    proto: tcp
    addr: 22

rc.localにコマンドを記載

$ sudo vi /etc/rc.local
/usr/bin/ngrok start –all –config=/home/username/.ngrok2/ngrok.yml –log=stdout >> /dev/null
“`

6.Dashboardの確認

以下で接続のポートを確認し、SSH: user名@0.tcp.ngrok.io:ポートでアクセス
https://dashboard.ngrok.com/status

※14274を固定したい場合は月$5を払う必要がある。。

参考
http://www.mori-soft.com/2008-08-15-01-36-37/2008-12-07-09-39-26/222-ngrok-ssh
http://qiita.com/kaiinui/items/9e01d976066b1b5898a4
http://asukiaaa.blogspot.jp/2016/06/ipmvnoraspberry-pingrokurlssh.html

2016年6月15日水曜日

RaspberryPI3からIFTTTへトリガをかける

RaspberryPI3からIFTTTへトリガをかける

IFTTTのMaker ChannelでKEYは取得したので、
トリガをかけてみたいと思います。

1.requestsのインストール
Python3を使うことを前提としているので以下でrequestsをインストール

sudo pip3 install requests

2.post
Maker Channelで取得したSECRET_KEYとEVENTを入れてPushする。

import requests
import datetime
now = datetime.datetime.now()               requests.post("https://maker.ifttt.com/trigger/alert-temp/with/key/YOUR_SECRET_KEY", json={"value1": temperature,"value2": "{0:%Y-%m-%d %H:%M:%S}".format(now)})

3.作成したレシピのNotificationに
“{{Value2}}に 異常温度{{Value1}}が検出されました。”
と記載

意図通りIFTTTへ通知ができました。

2016年6月13日月曜日

RaspberryPI3とMilkCocoaを連携させてみる。

RaspberryPI3とMilkCocoaを連携させてみる。

Raspberry PI3で測定した温度をリアルタイムに表示する手段を探していたところMilkCocoaというサービスがあったので試してみました。

温度はDHT11を使ったので、Adafruit_Python_DHTを使いました。
Adafruit_Python_DHTの使い方は調べればでてくるのでそちらを参照。

MilkCocoaの準備

1.MilkCocoaでユーザー登録し、dashboardから新しいアプリを作るをクリック。

enter image description here

2.App Nameを入力し、新しいアプリを作るをクリック。

enter image description here

3.認証をクリックし、API Key認証新しいAPI KeyとAPI Secretのペアを生成するをクリック

enter image description here

4.データストアをクリックし、名前を入力。
ここではtempとした。
enter image description here

Raspberry PI側のPythonの準備

1.PythonSDKのインストール
 これを参考にインストール

2.APP_ID, API_KEY,SECRET,DB_NAME(datastore名)を以下のようにpythonのコード(dht11_milkcocoa.py)に入れる。
APP_IDは以下に記載のものです。
enter image description here

#! /usr/bin/python3

import Adafruit_DHT
import time
import milkcocoa.milkcocoa as milkcocoa

APP_ID = 'xxxxxx'
API_KEY = 'xxxxxx'
SECRET = 'xxxx'
DB_NAME = 'temp'

def add_count_record(temperature,humidity):
    try:
        mc_client = milkcocoa.Milkcocoa.connectWithApiKey(APP_ID, API_KEY, SECRET, useSSL=False)
        datastore = mc_client.datastore(DB_NAME)
        datastore.push({"temperature": temperature, "humidity": humidity})
    except Exception as e:
        print(e)

def main():
    counter = 0

    while True:
        counter += 1

        # 30秒ごとに検知回数をMilkcocoaに送信
        if counter == 30:
            humidity, temperature = Adafruit_DHT.read_retry(11, 4)
            add_count_record(temperature,humidity)
            print("Temp={0:0.1f}, Hum={1:0.1f}" .format(temperature,humidity))
            counter = 0

        time.sleep(1.0)

if __name__ == '__main__':
    main()

3.pythonを実行

$ sudo python3 ./dht11_milkcocoa.py

4.データストアの確認
リスト表示(更新)を押して以下のようにデータがでればMilkCocoaにデータが送られている。
enter image description here

MilkCocoaでのグラフ化

1.データストアでデータ可視化をクリック

2.DATASOURCESの下のAddをクリックし、以下を入力
 TYPE: Milkcocoa
 NAME: 温度(自由に記載OK)
 DATASTORE: temp
 API: push
enter image description here

3.ADD PANEで以下を追加
TYPE: Sparkline
TITLE: 温度(自由に記載可能)
VALUE: datasource[“Temp”][“value”][“temperature”]
INCLUDE LEGEND: YES
LEGEND: detection temperature/30sec

enter image description here

4.一度に表示する個数の設定。
以下の工具マークをクリックし、Columnsの値を設定することで表示するサンプル数を決められる。
enter image description here

参考
http://yura2.hateblo.jp/entry/2016/02/29/PIR%E3%82%BB%E3%83%B3%E3%82%B5(SB00412A-1)%E3%81%A8Milkcocoa%E3%81%A7%E7%B0%A1%E6%98%93%E8%A6%8B%E5%AE%88%E3%82%8A%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E3%82%92%E6%A7%8B%E7%AF%89

2016年6月11日土曜日

wiringPiをpythonから呼び出す。

wiringPiをpythonから呼び出す。

Raspberry PI3のGPIOを制御するにはwiringpi2を使ったほうがよいらしいので、試してみました。

1.wiringpi2のインストール

$ sudo apt-get update
$ sudo apt-get install python3-dev python3-pip
$ sudo pip3 install wiringpi2

2.wiringPi2-Pythonのインストール

$ git clone https://github.com/Gadgetoid/WiringPi2-Python.git
cd WiringPi2-Python
$ sudo python3 setup.py install

3.動作確認

$ sudo python3
>> import wiringpi2

以下のエラーがでた。

Traceback (most recent call last):
  File "/home/rpi3/Work/WiringPi2-Python/wiringpi2.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_wiringpi2', [dirname(__file__)])
  File "/usr/lib/python3.5/imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_wiringpi2'

解決方法

wiringpi_wrap.cを修正する必要があるらしい。

$ vi wiringpi_wrap.c
PyString_FromStringAndSize(x, len) PyUnicode_FromStringAndSize(x, len)を追加

追加する場所は以下の「+」のところです。

 #define PyString_FromString(x) PyUnicode_FromString(x)
+#define PyString_FromStringAndSize(x, len) PyUnicode_FromStringAndSize(x, len)
#define PyString_Format(fmt, args)  PyUnicode_Format(fmt, args)

再度、インストールし、実行することでうまくいきました。
結構、調べてるとpython2.xとpython3.xでだいぶ違う。。。

$ sudo python3 setup.py install
$ sudo python3
>> import wiringpi2
エラーがでなくなった!
>> wiringpi2.piBoardRev()

これでpythonからGPIOが制御できるようになったので少し遊んでみようかと思います。

2016年6月10日金曜日

RaspberryPI3でBlynk libraryを使ってみる

RaspberryPI3でBlynk libraryを使ってみる

IoT時代ということでここを参考にRaspberry PI3と温湿度センサーのDHT11を使って温度計測をしてみる。

スマホ側の準備

IFTTTの準備

1.IF by IFTTTをインストールし、アカウントは取得する。

2.IF by IFTTTを起動し、画面右上のすり鉢のようなアイコンをタップ

enter image description here

3.「My Recipes」を開いて「+」(プラス)アイコンをタップ

enter image description here

3.画面下の「Create a New Recipe」をタップ

enter image description here

4.If の右側の「+」をタップした後に、「Maker」を選択。
enter image description here

enter image description here

5.Trigger として 「Receive a web request」を選択し、Event Name に“alert-temp”と入力
※RaspberryPi側から送信する Event Name と同じ名称にする必要あり。

enter image description here  

6.then の右側の「+」をタップした後に、「IF Notifications」を選択。

enter image description here

enter image description here

7.Action として「Send a notification」を選択し、Notification に“異常温度が計測されました。”などと入力し、Continueをタップ。
enter image description here

8.「Finish」をタップすれば Recipe は完成し、My Receipesに登録されます。
enter image description here

9.「+」をタップし、Makerを選択し、
enter image description here

「設定」をタップ。
enter image description here

以下のキーをメモっておく。
enter image description here

Blynkの準備

1.Blynkをインストール
2.プロジェクトの作成
enter image description here

3.プロジェクト名を入れてHARDWARE MODELとして”Raspberry Pi 3B”を選択。
AUTH TOKENはメモしておくこと。

enter image description here

4.「+」をタップし、「Value Display S」を2つ、「History Graph」を 1 つ追加
enter image description here

enter image description here

4.「Value Display S」、「History Graph」はそれぞれ以下のように設定
[1つ目]
名称: “温度”
INPUT: “Virtual”の“V0”
FREQUENCY: “10sec”
enter image description here

[2つ目]
名称: “湿度”
INPUT: “Virtual”の“V1”
FREQUENCY: “10sec”
enter image description here

「History Graph」
上から順に、以下を設定。
“Virtual”の“V0”、“温度”
“Virtual”の“V1”、“湿度”、
SHOW LEGEND を“ON”
enter image description here

こんな感じになったら完成です。
enter image description here

Raspberry PI側の準備

Raspberry Pi 用の C言語で書かれた GPIOアクセスライブラリのWiringPiのインストール

$ git clone git://git.drogon.net/wiringPi
$ cd ./wiringPi
$ ./build

blynk-libraryのインストール

$ git clone https://github.com/blynkkk/blynk-library.git
$ cd blynk-library/linux
$ make clean all target=raspberry

Curlライブラリのインストール

$ sudo apt-get update
$ sudo apt-get install libcurl4-openssl-dev

ソースコードの編集

今回変更及び追加するファイル一覧は以下。
kuro-iotexp1.cpp 追加ソースコード
kuro-iotexp1.h 追加ヘッダファイル
Makefile 変更(パッチ適用)
main.cpp 変更(パッチ適用)

ソースファイルと差分ファイルをダウンロード

$ wget http://driver.cfd.co.jp/cfd-drv/files/kuro-iotexp_kit/kuro-iotexp1.cpp
$ wget http://driver.cfd.co.jp/cfd-drv/files/kuro-iotexp_kit/kuro-iotexp1.h
$ wget http://driver.cfd.co.jp/cfd-drv/files/kuro-iotexp_kit/Makefile.patch
$ wget http://driver.cfd.co.jp/cfd-drv/files/kuro-iotexp_kit/main.cpp.patch

パッチを適用

$ patch -u -b < Makefile.patch
$ patch -u -b < main.cpp.patch

main.cpp を編集

以下の行の xxxxxxxx の箇所を IFT

char url[] = "https://maker.ifttt.com/trigger/alart-temp/with/key/xxxxxxxxxxxxxxxxxxxxxx";

再ビルド

$ make clean all target=raspberry

実行

tokenはBlynkででてきたAUTH TOKENを入れる。

$ sudo ./blynk --token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[0] Blynk v0.3.7 on Linux
[5001] Connecting to blynk-cloud.com:8442
[5206] Ready (ping: 95ms).
[5692] Trouble detected: http://docs.blynk.cc/#troubleshooting-flood-error
Read DHT11
Temperature = 27 degree C, Humidity = 58 %

となったので動き出したし、Blynkのほうでもデータが取得できた。

しかし、IFTTTへのPushの動検ができていないため、
意図的にIFTTTにpushされる温度にしても、
“Push IFTTT”とでるがスマホ側でPushされない。

試しにhttps://ifttt.com/makerからHow to Trigger Eventsを
クリックし、evnet nameを入れるとちゃんとPushできたし、
Raspberry PIの端末で以下のcurlを実施してもPushできた。
enter image description here

IFTTTへの自動的にPushするのはもう少し別のサンプルを
見ながら理解を深めるとします。

2016年6月9日木曜日

AACGAIN

AACGAIN

UbuntuでMP3の音量を揃えるにはeasyMP3GainをUbuntuソフトウエアセンターから
インストールすればできるが、aacgainを別途インストールする必要がある。
以下でインストール可能

$ sudo add-apt-repository ppa:robert-tari/main
$ sudo apt-get update
$ sudo apt-get install aacgain

2016年6月8日水曜日

固定IP化したらPINGが通らなくなった

固定IP化したらPINGが通らなくなった

Raspberry PI3へのSSH通信が急にできなくなった。
調べてみると固定IP化したのが何か影響してそう。

enter image description here

この接続を完了するにはIPv4アドレス化が必要になりますにチェックがされてなかった。
これにチェックしたら今のところはうまくSSHでつながってます。

— 2016/6/11追記 —
やっぱりまたSSHでつながらくなったので調べたところ以下を試したら
うまく行っている。

$ sudo vi /etc/nsswithc.conf
#hosts:          files mdns4_minimal [NOTFOUND=return] dns
#hosts:          files dns

— 2016/6/12 追記 —
また、SSHでつながらなくなった。
ゲートウエイやwww.yahoo.jpは繋がるのにPCとRaspberry PI3だけがつながらない。
再度ググッてみたところルーターの再起動という手があった。

やってみたところSSHでつながるようになった。
だいぶ時間を取られました。
また、同じ状態になったらまずはルーターの再起動をしてみます。

2016年6月5日日曜日

Python3ではmysql-pythonが使えない

Python3ではmysql-pythonが使えない

Python3ではMysql-pythonが使えないということで
mysqlclientとmysql-connector-phythonを導入する必要があるということ。

$ sudo pip3 install mysqlclient
$ sudo pip3 install --upgrade pip

試しに以下のようにMySQLでデータベースを用意する。

$ mysql -u root -p
mysql> create database list;
mysql> create table list.personal(id int, name varchar(20));
mysql> show tables from list;
+----------------+
| Tables_in_list |
+----------------+
| personal       |
+----------------+
mysql> insert into list.personal(id,name) values(1,'Satoh');
mysql> select * from list.personal;
+------+-------+
| id   | name  |
+------+-------+
|    1 | Satoh |
+------+-------+
定義は省略できるので、以下でもOK.
mysql> insert into list.personal values(2,'Kondo');

以下のコード(dbsample.py)を作成し、データベースの読み出しと追加ができた。

python3 dbsample.py
#!/usr/bin/python3

import MySQLdb
def showUser():

    connector = MySQLdb.connect(
            user='root',
            passwd='mysql',
            host='localhost',
            db='list',
            charset="utf8")

    cursor = connector.cursor()

    # read
    cursor.execute("select * from personal")

    for row in cursor.fetchall():
        print("ID:" + str(row[0]) + "  NAME:" + row[1])

    # insert
    sql = u"insert into list.personal values(3,'Abe')"
    cursor.execute(sql)
    connector.commit()

    # read
    cursor.execute("select * from personal")

    for row in cursor.fetchall():
        print("ID:" + str(row[0]) + "  NAME:" + row[1])

    cursor.close
    connector.close

参考
http://note.kurodigi.com/python3-mysql/

Python - if name == ‘main‘: の意味に関しては以下が参考になった。
http://azuuun-memorandum.hatenablog.com/entry/2015/05/09/002549

2016年5月30日月曜日

VirtualBoxで入れた同じproxyのゲストOSにアクセスする

VirtualBoxで入れた同じproxyのゲストOSにアクセスする

1.ホストPCのネットワーク接続でアダプタを確認

2.”Virtual Box”にてゲストOSをクリックし、ネットワーク設定で以下を設定
 設定⇒ネットワーク⇒アダプター1で以下を設定
 割り当て: ブリッジアダプター
 名前: 先ほど調べたホストPCのアダプタ
 高度: プロミスキャストモード: すべて許可
 enter image description here
 
3.”VirtualBox”のファイル⇒環境設定⇒プロキシーでホストとポートを設定。
enter image description here

4.ゲストOS(Ubuntu mate16.04)を起動
Edit ConnectionsでIPアドレスを固定する。
enter image description here

enter image description here

5.ゲストOSの/etc/profileに以下を追加
 
 $ sudo vi /etc/profile
 # 最終行に追記 (プロキシサーバーを環境変数に設定)
MY_PROXY_URL="http://username:password@your.proxy.address:8080/"
HTTP_PROXY=$MY_PROXY_URL
HTTPS_PROXY=$MY_PROXY_URL
FTP_PROXY=$MY_PROXY_URL
http_proxy=$MY_PROXY_URL
https_proxy=$MY_PROXY_URL
ftp_proxy=$MY_PROXY_URL
export HTTP_PROXY HTTPS_PROXY FTP_PROXY http_proxy https_proxy ftp_proxy
$ source /etc/profile
$ sudo /etc/init.d/networking start
$ sudo vi /etc/rc.local
/etc/init.d/networking start
 

6.ホストもしくは他のPCから以下でゲストOSのサーバーにアクセスできた。
  http://10.56.87.88:8080/share/page/

2016年5月16日月曜日

node.jsでeddystoneを使ってみる

node.jsでeddystoneを使ってみる

iBeaconと同様な機能でGoogleのオープンソース版がeddystoneということで、
node.jsは入れたのですが、eddystoneを使うには以下も必要ということなのでインストールして送信実験をしたのですが、少し手間取ったのでメモしておきます。

$ npm install eddystone-beacon

http://dev.classmethod.jp/smartphone/eddystone-edison/
を参考にsample.jsをhttps://goo.gl/で短縮URLを取得して実行したが、
以下のエラーが発生

bleno warning: adapter state unauthorized, please run as root or with sudo
               or see README for information on running without root/sudo:
               https://github.com/sandeepmistry/bleno#running-on-linux

https://github.com/sandeepmistry/bleno#running-on-linux
を見てみるとRunning without root/sudoとするために以下が必要。

$ sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)

もう一度以下でを実行したら送信できました。

$ node ./sample.js

受信側はAndroidアプリのiBeacon & Eddystone Scannerで受信しました。

bleno のインストール

Peripheralsとなるためのライブラリらしい。

$ mkdir bleno
$ cd bleno
$ npm install bleno

http://dream-of-electric-cat.hatenablog.com/entry/2015/04/13/221940

2016年5月11日水曜日

VNCでアクセスすると日本語入力できない

VNCでアクセスすると日本語入力できない

UbuntuからRaspberry Pi3にインストールしたUbuntu MateにVNC接続したが日本語が入力できなかったがいろいろ調べた結果、以下でできたので忘れないようにメモしておきます。

リモート側のUbuntuの設定

1.RemminaのRDPでキーボードレイアウトを00000411-Japanese

Raspberry PI3側の設定

1.ibus-mozcのインストール

sudo apt-get install ibus-mozc

2.~/.vnc/xstartupに以下の文言を追加

$ vi ~/.vnc/xstartup
#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus
ibus-daemon -drx &

3.reboot
4.VNC接続する。
5.システム→設定→ユーザー向け→言語サポートで
 キーボード入力に使うIMシステムを”iBus”
6.reboot

これで半角全角キーを押すことで日本語入力できた。

https://gakupuro.com/uncategorized/vnc-ibus-mozc

2016年5月9日月曜日

ubuntu mateをraspberry pi3に再インストールしたらやること

ubuntu mateをraspberry pi3に再インストールしたらやること

VNCがgray screenのままうまくいかないないので、再インストールすることにしました。
忘れないように手順をメモしておきます。
ここまでやればRaspberry PIにディスプレイとマウス、キーボードを付けなくてもよくなります。

インストール
フォルダの日本語化
raspberry pi関連
言語サポート
黒枠対策
日本語入力
tightvncのインストール

インストール

1.ディスクでパーティションを削除して空き領域の状態でubuntu mateのイメージのリストア
enter image description here
2.raspberry pi3にSDカードを指して起動
 [注意事項]
 ・キーボードは日本語(98xx)
 ・自動的にログインにチェック

フォルダの日本語化

フォルダが日本語になっているので、以下で英語にする。
Bluetoothアプレットのローカルサービス->転送のIncoming FolderもDownloadsに変更すること。

LANG=C xdg-user-dirs-gtk-update

wifiの設定

パスワードを入れて接続しておく。
IPv4 SettingでManualとし、IPアドレスを固定しておく。
IP: 192.168.11.11
Netmask: 255.255.255.0
Gateway: 192.168.11.1
DNSサーバー:192.168.11.1

raspberry pi関連

Main MenuのRaspberry Pi Infomationで以下を実施。
1.Resizing the file systemでResize Nowをクリック
これをやらないとSDカードの容量を十分に使えない。
2.Kernel Updates

$ sudo rpi-update

3.X11のEnable化

$ sudo graphical enable

言語サポートとキーボード

これで日本語を設定しないとキーボードで日本語が打てない。
1.設定→ユーザー向け→言語サポートを選ぶとインストールするかと聞いてくるのでインストールする。
システム全体に適用をクリック。
2.再起動してもう一度、言語サポートを選択し、キーボード入力に使うIMシステムでfcitxとなっていることを確認。
3.ハードウエア→キーボードのレイアウトでキーボードの型式をPC-98xxシリーズを選択。
4.再起動すると画面上にキーボードのアイコンがでてくるので右クリックし、
 入力メソッドをMOZCにする。
 
 これでキーボードの半角を押すことで日本語が入力できるようになる。

黒枠対策

画面のまわりに黒枠ができて小さい状態になってました。
config.txtで以下の2つを実施することで回避できました。

$ sudo vi /boot/config.txt

①hdmi_group, hdmi_mode の先頭の ”#” を外して、
  hdmi_group=2
  hdmi_mode=82

②以下の4つがコメントアウトになっていたのではずす     
  overscan_left=0
  overscan_right=0
  overscan_top=0
  overscan_bottom=0

tightvncのインストール

$ sudo apt-get install tightvncserver
$ vncpasswd
#起動
$ vncserver :1
#ログの確認
$ less /home/rpi3/.vnc/rpi3-desktop\:1.log
Font directory '/usr/share/fonts/X11/75dpi/' not found - ignoring
Font directory '/usr/share/fonts/X11/100dpi/' not found - ignoring
xrdb: No such file or directory
xrdb: can't open file '/home/rpi3/.Xresources'

$ touch ~/.Xresources
$ sudo apt-get install xfonts-75dpi xfonts-100dpi


#自動起動の設定
$ sudo crontab -e
@reboot su -c “vncserver :1 -geometry 1920x1080 -depth 24” user

接続側のubuntuのremminaで接続(サーバーを192.168.11.11:5901)し、全画面にすると画面がでてくる。
その後、なぜかRaspberry Pi側でコンソールとTilda 1 Configが立ち上がるようになる。

Raspberry Pi側でシステム→設定→ユーザー向け→自動起動するアプリで
Tildaのチェックを外すして再起動。

2016年5月7日土曜日

Ubuntuで自動起動~cron~を使ってみる。

Ubuntuで自動起動~cron~を使ってみる。

Ubuntu mateで起動時に自動実行したいスクリプトがあれば
以下のようにcronに登録することで実行できる。

$ sudo crontab -e 
$ sudo update-alternatives --config editor 
vimを選択する。

以下のように起動時に自動で実行したいスクリプトを記載する
@reboot su -c "/home/usrname/mjpg-streamer/run.sh" usrname

[参考]
http://nort-wmli.blogspot.jp/2016/02/cron-osreboot-shellsh.html

bluetoothデーモンが起動しない

bluetoothデーモンが起動しない

Raspberry Pi3に入れているUbuntu Mateで
理由は分からないのですが、電源ONしたらいつも自動で立ち上がるBluetooth apletがいきなり起動しなくなりました。
statusを/etc/init.d/bluetooth statusで確認したところ以下のように
“Not enough free handles to register service”とエラーが起きているようです。

enter image description here

ここを参考に以下のようにもう一度bluetooth関連のパッケージを再インストールして、
bluemanを起動したらbluetooth apletが立ち上がりました。
でも再起動したらやっぱり立ち上がらない。

$ sudo apt-get install bluez bluez-alsa bluez-audio bluez-btsco bluez-compat bluez-cups bluez-dbg bluez-gstreamer bluez-hcidump bluez-pcmcia-support bluez-tools bluez-utils python-bluez bluewho indicator-bluetooth libbluetooth-dev libgnome-bluetooth11 libbluetooth3 python-gobject python-dbus

$ sudo apt-get install blueman
$ sudo blueman-manager

以下を実施したら再起動しても問題なくapletが立ち上がっているようです。

$ sudo apt-get install indicator-bluetooth

2016年5月2日月曜日

VNCでの解像度設定

VNCでの解像度設定

VNCをcronを使って自動起動する際に解像度もつける。

$ sudo crontab -e

@reboot su -c “vncserver :1 -geometry 1920x1080 -depth 24” user

を追加。再起動し、以下で起動しているかを確認

$ ps -ef | grep tightvnc | grep -v grep

[参考]
http://desktop-linux.namakemono345.com/ssh-vnc/

Raspberry PI3にubuntu mateを入れてみる

Raspberry PI3にubuntu mateを入れてみる

Raspberry Pi3にUbuntu Mateを入れてみました。(Ubuntu 14.04を使用)
環境を準備するまでの一通りをメモっておきます。

1.インストール
2.黒枠対策
3.日本語入力
4.フォルダの英語表記化
5.SSHを有効にする
6.VNC接続
7.lighttpd(サーバー)のインストール

インストール

  1. 以下からubuntu-mate-16.04-desktop-armhf-raspberry-pi.img.xzをダウンロード
    https://ubuntu-mate.org/raspberry-pi/

  2. 以下を実行

$ sudo apt-get install gddrescue xz-utils
$ unxz --verbose ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img.xz
$ sudo ddrescue -D --force ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img /dev/mmcblk0

~2016/6/5 追記~
コマンドでなくてもディスクで初期化した後に上記イメージをリストアでもいけます。

http://desktop-linux.namakemono345.com/raspberry-pi3-wifi/

黒枠対策

画面のまわりに黒枠ができて小さい状態になってました。
config.txtで以下の2つを実施することで回避できました。

$ sudo vi /boot/config.txt

①hdmi_group, hdmi_mode の先頭の ”#” を外して、
  hdmi_group=2
  hdmi_mode=82

②以下の4つがコメントアウトになっていたのではずす     
  overscan_left=0
  overscan_right=0
  overscan_top=0
  overscan_bottom=0

[参考]
http://edgewalk.wp.xdomain.jp/?p=370

キーボードの日本語化

配列が日本語キーボードではなかったので”キーボードの設定”
でレイアウトで”日本語”を追加し、型式を”PC-98xxシリーズ”に変更。
これで再起動したら”半角”を押すことで日本語入力もできた。

設定->ユーザー向け->言語サポート
インストールがでてきたらインストールする。
システム全体に適応“をクリックし再起動。
キーボード入力に使うIMシステムがfcixになっていれば再起動

システム->その他->fcixの入力メソッドを確認し、”Mozc“の記載がなければ再起動する。

キーボードの設定のレイアウトでキーボードの形式を”日本語(PC-98xxシリース)にする。

フォルダの英語表記化

$ LANG=C xdg-user-dirs-gtk-update

※Bluetoothのローカルサービスの転送のフォルダは自動で変わらないので、
 自分でDownloadに変更が必要。

Raspberry Pi Information

・Resize
WelcomeのRaspberry Pi InformationでResizeをクリック。
これによりSDカードの空領域も使えるようになる。

・X11をEnable

$ sudo graphical enable

・kernel update

sud rpi-update

SSHを有効にする

$ sudo apt-get install raspi-config
$ sudo raspi-config
メニューから"Advanced Options" を選択し、
SSHを選択し、Enable。
これでSSHで繋がるようになった。

VNC接続

$ sudo apt-get install tightvncserver
$ tightvncserver
 password: raspberry
$ sudo vi /etc/init.d/vncboot
$ sudo chmod 755 /etc/init.d/vncboot
$ sudo update-rc.d vncboot defaults
$ sudo reboot
$ ps -ef | grep tightvnc | grep -v grep
// ポートがListenしているかの確認
$ netstat -nlt
// 5901でLISTENしている。

ホスト側からRemminaでIP:5901で接続する。
すでにターミナルが立ち上がっているのでRaspberry PI側にて自動起動するプログラムにてTildaのチェックを外しておく。

vncbootは以下。

#! /bin/sh
# /etc/init.d/vncboot

USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
 start)
 echo "Starting VNC Server"
 #Insert your favoured settings for a VNC session
 su $USER -c '/usr/bin/vncserver :1 -geometry 1920x1080 -depth 24'
 ;;

 stop)
 echo "Stopping VNC Server"
 su $USER -c '/usr/bin/vncserver -kill :1'
 ;;

 *)
 echo "Usage: /etc/init.d/vncboot {start|stop}"
 exit 1
 ;;
esac

exit 0

lighttpdのインストール

$ sudo apt-get -y install lighttpd
// ドキュメントルートやポートを変える場合は以下のファイルを編集
$ sudo vi /etc/lighttpd/lighttpd.conf
// lighttpdが起動しているかの確認
$ ps aux | grep [l]ighttpd
www-data  9905  0.1  0.3   5472  3212 ?        Ss   21:06   0:00 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf

とlighttpd.confがプロセスであれば起動している。
別のPCから[http://IPアドレス:80]でアクセスでき、以下の画面が表示されればOK。
念のため、再起動し、同様にアクセスできるかを確認しておく。
(とりあえず何も設定しなくても自動起動してます。)

enter image description here
“`

2016年5月1日日曜日

Raspberry Pi3にAndroid6.0を入れてみる

Raspberry Pi3にAndroid6.0を入れてみる

Raspberry Pi3にAndroid6.0を入れてみました。
※Ubuntu14.04を使用

  1. 以下からimgをダウンロード
    http://www.mediafire.com/download/cabo6z8ky1adgsj/marshrpi3wifibt19042016.img.bz2

  2. SDカードを差し、ユティリティ−→ディスクでSDカードを初期化

  3. “端末”で先ほどダウンロードして解凍したフォルダに移動
  4. 先ほどのイメージを以下のコマンドでSDカードにコピーする

    sudo dd if=marshrpi3wifibt19042016img of=/dev/mmcblk0 bs=1M
  5. Raspberry Pi3にSDカードを入れる

Androidは起動はしましたが、特にやることはないのでここまで。

Ubuntuのカーネルのバージョンアップ

Ubuntuのカーネルのバージョンアップ

1.カーネルのバージョンの確認

$ uname -r

2.探してみる

$ apt-cache search linux-image-

3.ダウンロード

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.5-unstable/linux-headers-4.1.5-040105_4.1.5-040105.201508101730_all.deb
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.5-unstable/linux-headers-4.1.5-040105-generic_4.1.5-040105.201508101730_amd64.deb
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.1.5-unstable/linux-image-4.1.5-040105-generic_4.1.5-040105.201508101730_amd64.deb

4.以下であげてみる

$ sudo dpkg -i *.deb
$ sudo update-grub
$ sudo reboot