2016年11月17日 星期四

[Ubuntu] Debian based package management

這張圖找好久, 果然還是有好心人畫, 感謝



reference: https://hughchao.hackpad.com/ep/pad/static/wrP2bgGpbe5

2016年11月12日 星期六

[RPi] Raspberry Pi 3 Bluetooth Beacon

兩行就可以了
sudo hciconfig hci0 leadv 3
sudo hcitool -i hci0 cmd 0x08 0x0008 18 02 01 06 03 03 aa fe 10 16 aa fe 10 00 00 65 64 75 70 6f 6c 69 2e 66 69 00 00 00 00 00 00 00

欄位的意義可參考這篇
http://blog.itist.tw/2014/05/ibeacon.html

這篇的欄位更清楚
https://hackaday.io/project/10314-raspberry-pi-3-as-an-eddystone-url-beacon


使用 physical web, iOS 讀取 notification 沒問題, 但 Android 反而讀不到, 可以參考這篇的作法(雖然目前還是沒收到...)
https://community.estimote.com/hc/en-us/articles/218451777-How-to-enable-Physical-Web-in-Chrome-

這篇是 Pi 3 + Android(Node.js) 的應用
https://www.hackster.io/inmyorbit/build-a-mobile-app-that-connects-to-your-rpi-3-using-ble-7a7c2c

實做 physical web(eddystone-url) 的套件
Node.js: https://github.com/don/node-eddystone-beacon
Python: https://github.com/google/eddystone/tree/master/eddystone-url/implementations/PyBeacon

[Python] decorator

在 python 很常用到

這幾篇寫得蠻清楚的,
http://thecodeship.com/patterns/guide-to-python-function-decorators/
http://missions5.blogspot.tw/2014/07/python-decorator.html

2016年11月8日 星期二

2016年11月6日 星期日

[Android] AndroidScreencast

因為 ubuntu 版本是 10.04 LTS 太舊了, 所以一堆問題要解決

要把 Android 的畫面打到 ubuntu 應該要有一堆方法, 記得之前用 Droid@Screen, 可是現在不知道怎麼了不能用

後來又看到 AndroidScreencast, 雖然感覺有點慢也將就著用吧

$ git clone https://github.com/xSAVIKx/AndroidScreencast
$ cd AndroidScreencast
$ mvn package

馬上報錯, 因為沒有裝 maven

$ sudo apt-get install maven2

結果軟體最低限制 Java 7 and Maven 3.2.5, 只好想辦法裝 maven3

因為沒有 apt, 只好抓 binary, 參考這篇文章, 可是現在只剩下 maven-3.2.2, 就加減用吧

再來是修改環境變數 JAVA_HOME, M2_HOME, MAVEN_HOME, M2 一堆

修改完還要把 maven2 移除掉才行

$ sudo apt-get autoremove maven2

確認版本
$ mvn -v
Apache Maven 3.2.2

終於可以編譯了

$ mvn package

編譯完成後執行發現又錯, 錯誤訊息在 app.properties, 要把
adb.path=adb.exe
改為
adb.path=adb
記得 adb 也要 export 到環境變數, 我是用鳥鳥的 appinventor 帶的 adb

最後終於可以執行了

$ java -jar target/androidscreencast-0.0.7s-executable.jar

唉, 舊版本就是該死



[RPi] 藍牙通訊

硬體:Pi 3
軟體:2016-05

Android 手機安裝 BlueTerm, 原始碼

修改 /etc/systemd/system/dbus-org.bluez.service, 將
ExecStart=/usr/lib/bluetooth/bluetoothd
改為
ExecStart=/usr/lib/bluetooth/bluetoothd --compat
重新載入設定檔
$ sudo systemctl daemon-reload


Pi 3 藍牙設定
$ sudo bluetoothctl
[bluetoothctl] power on
[bluetoothctl] scan on
[bluetoothctl] agent on
[bluetoothctl] pair MAC_ADDRESS
[bluetoothctl] trust MAC_ADDRESS
[bluetoothctl] exit
sudo rfcomm bind 0 MAC_ADDRESS


Pi 3 程式碼:
#!/usr/bin/python

import bluetooth
import thread
import time

server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )

port = 1 
server_sock.bind(("",port))
server_sock.listen(1)

client_sock,address = server_sock.accept()
print "Accepted connection from ", address

def receive_thread():
    while True:
        try:
            data = client_sock.recv(1024)
            print "received [%s]" % data

        except:
            print "SerialException: "

        time.sleep(0.1)

thread.start_new_thread(receive_thread, ()) 

while True:
    s = raw_input("RPi] ")
    client_sock.send(s)

client_sock.close()
server_sock.close()

reference:
* An Introduction to Bluetooth Programming
* Using smart phone (Android) to control LED on Raspberry Pi 3 through Bluetooth connection


如果透過 App Inventor 寫 Android 端程式, 可以參考這篇文章
http://howtomechatronics.com/tutorials/arduino/how-to-build-custom-android-app-for-your-arduino-project-using-mit-app-inventor/

目前還沒搞定, 之後會再打通這邊...
列出有用到的 PORT
import serial.tools.list_ports

ports = list(serial.tools.list_ports.comports())
for p in ports:
    print p