網頁

2017年3月22日 星期三

Python 的 SimpleHTTPServer

參考 Arduino Yún 小試(2)透過瀏覽器點光明燈

vi lightUpL13Http.py
import sys
import SimpleHTTPServer
import SocketServer
sys.path.insert(0, '/usr/lib/python2.7/bridge/')
from bridgeclient import BridgeClient

class LedRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/ledOn':
            BridgeClient().put('state', '1')
        elif self.path == '/ledOff':
            BridgeClient().put('state', '0')
        self.path = '/led.html'
        return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

server = SocketServer.TCPServer(('0.0.0.0', 8000), LedRequestHandler)
server.serve_forever()

vi led.html
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type">
    <title></title>
  </head>
  <body>
     <p><a href="ledOn">On</a>&nbsp; <a href="ledOff">Off</a></p>
  </body>
</html>

python lightUpL13Http.py

http://arduino.local:8000/led.html


2017年3月10日 星期五

Arduino Yun

Yún Shield 不是 Yún
Yún Shield 是用來擴充 Arduino Leonardo 成為 Yún 的

Yún 有三個 Reset 按鈕
網路邊: 32U4 RST
USB邊: WLAN, 作用有兩種
  1. 按5秒,wifi 回AP模式 SSID=Arduino-Yun-XXXXXXXXXXXX, IP=192.168.240.1
      命令: wifi-reset-and-reboot
  2. 按30秒,linux 環境回復出廠值,清除板上的 Flash 記憶體
      命令: reset-to-factory-anyway
另一角: YUN RST

預設的密碼不是 arduino 就是 doghunter

WiFi: Linino-xxxxxxxxxxxx
IP: 192.168.240.1
PASSWORD: doghunter

opkg install xxxx.ipk
opkg remove xxxx
opkg remove xxxx --force-remove
opkg list-installed


編輯 /lib/functions.sh 加入
default_postinst() {
  return 0
}
default_prerm() {
  return 0
}

透過網路連到 colsole
root@arduino:~# telnet localhost 6571

使用 SD卡 擴充 Arduino Yun 的儲存空間

參考 Auto-Expanding of your File System using Pivot Overlay

df -h
查詢 Filesystem 使用狀態

插入 SD卡 會顯示在 /mnt/sda1

執行 overlay-only -i 命令, 第一次執行會要求安裝 Fdisk
在執行一次 overlay-only -i 命令, 會顯示下列選項
1. Pivot Overlay on SDCard (Experimental)
2. Revert Pivot Overlay on SDCard (Experimental)
3. Format SDCard
4. Exit and reboot
0. Exit

若沒有安裝 overlay-only, 使用下列命令
wget https://raw.githubusercontent.com/linino/linino_distro/lininoIO/package/linino/yun-scripts/files/usr/bin/overlay-only
chmod +x overlay-only
mv overlay-only /usr/bin

注意:若是你已經擴充了你的檔案系統,並且你想要更新 Arduino Yun 板,執行下列步驟
- uninstall all programs;
- execute the Revert Pivot Overlay;

Arduino Yun Graphoto2 2.5.2

cd /tmp
wget http://www.ibuyopenwrt.com/images/gphoto2_2.5.2-1_ar71xx.ipk
wget http://www.ibuyopenwrt.com/images/libgphoto2-drivers_2.5.2-1_ar71xx.ipk
wget http://www.ibuyopenwrt.com/images/libgphoto2_2.5.2-1_ar71xx.ipk
opkg update
opkg install libgphoto2_2.5.2-1_ar71xx.ipk
opkg install gphoto2_2.5.2-1_ar71xx.ipk
opkg install libgphoto2-drivers_2.5.2-1_ar71xx.ipk

參考網站 Arduino Yun Gphoto2 2.5.2

2017年2月23日 星期四

Raspberry

Start/Preferences/Appearance Settings
Menu Bar/Bottom

Start/Preferences/Raspberry Pi Configuration
System/Boot: To CLI

sudo vi /etc/default/keyboard
XKBLAYOUT="us"

sudo raspi-config
Interfacing Options/SSH

root/raspberry

sudo vi .config/pcmanfm/LXDE-pi/pcmanfm.conf
[volume]
mount_on_startup=0
mount_removable=0

sudo /etc/apt/sources.list
改 http://mirrordirector.raspbian.org/raspbian
為 http://archive.raspbian.org/raspbian

sudo apt-get update
sudo apt-get install gphoto2

先安裝 WittyPi 軟體,後安裝硬體
wget http://www.uugear.com/repo/WittyPi/installWittyPi.sh
sudo sh installWittyPi.sh
關機不要使用 shutdown, 改用下列命令
gpio mode 7 out

取得溫度
/opt/vc/bin/vcgencmd measure_temp


Compiling gphoto in raspberry pi

sudo apt-get install automake
sudo apt-get install autopoint
sudo apt-get install gettext
sudo apt-get install libtool
sudo apt-get install libusb-dev
sudo apt-get install libpopt-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libexif-dev

git clone https://github.com/gphoto/libgphoto2.git
cd libgphoto2
autoreconf --install --symlink
./configure
make
sudo make install

git clone https://github.com/gphoto/gphoto2.git
cd gphoto2
autoreconf --install --symlink
./configure
make
sudo make install

LD_LIBRARY_PATH=/usr/local/lib;export LD_LIBRARY_PATH
alias sudo='sudo env LD_LIBRARY_PATH=$LD_LIBRARY_PATH'

gphoto2 --version


2017年1月11日 星期三

Arudino Yun 之 OS

Arduino 分裂成 org 和 cc
org 的 Arduino Yun 使用 LininoIO
cc 的 Arduino Yun 使用 OpenWrt
兩者個關係,實在是搞不清楚

電腦開啟 TFTPUtil GUI, 按下 Options
輸入 Path 和 Server IP Address 後按 OK
按 Start TFTP Server

透過 micro USB 連接到電腦
電腦開啟 Arduino IDE
Tools/Board/Arduino Yun
Tools/Port
File/Examples/Bridge/YunSerialTerminal
按 Upload 傳至 Arduino Yun
電腦開啟 Tera Term, 透過 Serial Port連至 Arduino Yun
若發現是一堆亂碼,修改 YunSerialTerminal 的 linuxBaud 為 115200

壓 Arduino Yun 上的 YUN RST(靠 LED 的按鈕)
並且快速透過 Tera Term(Serial Port) 按下 Enter 鍵,進入 U-Boot

以下使用 org 的 LininoIO
等出現 autoboot in 4 seconds (stop with 'lin'), 輸入 lin
此時會出現
linino>
連接 Arduino Yun 的網路(不能使用 wifi)
setenv serverip 192.168.1.70
setenv ipaddr 192.168.1.72
printenv
tftp 0x80060000 u-boot-linino-yun.bin;
請確認正確下載,若有問題請檢查網路設定
erase 0x9f000000 +0x40000;
cp.b $fileaddr 0x9f000000 $filesize;
tftp 0x80060000 lininoIO-generic-linino-yun-kernel.bin
erase 0x9fEa0000 +0x140000;
cp.b $fileaddr 0x9fea0000 $filesize;
tftp 0x80060000 lininoIO-generic-linino-yun-rootfs-squashfs.bin
erase 0x9f050000 +0xE50000;
cp.b $fileaddr 0x9f050000 $filesize;
erase 0x9f040000 +0x10000;
reset
setenv console ttyATH0,250000
saveenv
reset
透過 SSH 連上 ArduinoYun, 執行 lininoio -f stop
設定 ttyATH0 為 console

以下使用 cc 的 OpenWrt
等出現 autoboot in 4 seconds (type 'ard' to enter u-boot console), 輸入 ard
此時會出現
ar7240>
setenv serverip 192.168.1.70
setenv ipaddr 192.168.1.72
ping 192.168.1.70
tftp 0x80060000 openwrt-ar71xx-generic-linino-u-boot.bin
erase 0x9f000000 +0x40000
cp.b $fileaddr 0x9f000000 $filesize
erase 0x9f040000 +0x10000
tftp 0x80060000 openwrt-ar71xx-generic-yun-16M-kernel.bin
erase 0x9fEa0000 +0x140000
cp.b $fileaddr 0x9fea0000 $filesize
tftp 0x80060000 openwrt-ar71xx-generic-yun-16M-rootfs-squashfs.bin
erase 0x9f050000 +0xE50000
cp.b $fileaddr 0x9f050000 $filesize
bootm 0x9fea0000

org 的 LininoIO 參考資料
LininoIO OS upgrade from U-boot
Upgrade to Linino
Server at download.linino.org

使用網頁更新作業系統
下載最新的影像檔 Index of /linino_distro/lininoIO/latest
檔名有 mini 的是給 YunShield 用的,不要下載
連上 ArduinoYun 網頁
左上角 Applications/Arduino/Arduino Luci
輸入帳號密碼
System/"Backup/Flash Firmware"
點選 Flash new firmware image 的 "選擇檔案",選擇剛下載的影像檔

使用命令列更新作業系統
使用 ssh 連入系統
cd /tmp
wget http://download.linino.org/linino_distro/lininoIO/latest/lininoIO-generic-linino-yun-squashfs-sysupgrade.bin
sysupgrade -v -n lininoIO-generic-linino-yun-squashfs-sysupgrade.bin

使用網頁更新作業系統
下載最新的影像檔,並且解壓縮
連上 ArduinoYun 網頁,並登入
點 CONFIGURE
點 advanced configuration panel (luci)
System/"Backup/Flash Firmware"
點選 Flash new firmware image 的 "選擇檔案",選擇剛下載的影像檔

使用命令列更新作業系統
使用 ssh 連入系統,不能使用 YunSerialTerminal
run-sysupgrade /mnt/sda1/openwrt-ar71xx-generic-yun-squashfs-sysupgrade.bin