2016/04/10

Arduino Yún:範例草稿碼YunSerialTerminal與套件管理指令opkg

這支草稿碼,可以讓Yun的ATmega32U4成為Linux端(AR9331、OpenWrt-Yun)的終端機,而我們從電腦經由終端機模擬軟體,便能以命令列介面存取OpenWrt-Yun。

YunSerialTerminal這支草稿碼的作用,其實是開兩個序列埠,扮演介於中間的橋樑角色,一個是Serial,連接到Yun板子上的micro B型USB埠(再連接到你的電腦),另一個是Serial1,這是ATmega32U4跟AR9331(OpenWrt-Yun)的連接介面。

電腦-終端機模擬軟體-USB線-Yun的ATmega32U4(運行YunSerialTerminal)-內部序列埠-AR9331(OpenWrt-Yun)。

經由USB線(非W-Fi)燒錄「檔案」-「範例」-「Bridge」-「YunSerialTerminal」後,先使用Arduino IDE內建的序列埠監控視窗(Serial Monitor),傳輸速率設為115200。看到類似下列畫面,執行各種Linux指令,但序列埠監控視窗實在很陽春,不支援色彩功能,因此看到一堆[1;34m之類的東西。

所幸可以使用其他終端機模擬軟體,例如Windows的Tera Term,畫面如下,試著以套件管理指令opkg,更新套件清單並安裝新套件fortune-mod。
每次想安裝套件之前,都必須執行指令「opkg update」,因為套件清單資料只存在於RAM,這是為了節省空間。然後執行指令「opkg install 套件名」安裝套件。

然後就可以執行指令fortune,每次執行都會現出某一名言錦句:
root@ArduinoYun:~# fortune
You're almost as happy as you think you are.
root@ArduinoYun:~# fortune
A day for firm decisions!!!!!  Or is it?
root@ArduinoYun:~# fortune
You never hesitate to tackle the most difficult problems.
root@ArduinoYun:~# fortune
Tuesday is the Wednesday of the rest of your life.

另外,指令「opkg list-installed」可列出已安裝的套件;「opkg remove 套件名」則是移除套件;「opkg find 套件名」可尋找你是否安裝了某套件。

當然啦,OpenWrt-Yun其實就是一套Linux,也就是說,你也能執行其他Linux指令。譬如ifconfig:
root@ArduinoYun:~# ifconfig
eth1      Link encap:Ethernet  HWaddr 90:A2:DA:F8:05:5D
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:4

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1429 (1.3 KiB)  TX bytes:1429 (1.3 KiB)

wlan0     Link encap:Ethernet  HWaddr 90:A2:DA:F8:05:5D
          inet addr:192.168.1.61  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:83 errors:0 dropped:0 overruns:0 frame:0
          TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:9521 (9.2 KiB)  TX bytes:8069 (7.8 KiB)


或是指令df查詢Yun內部Flash的用量:
root@ArduinoYun:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    6.9M    408.0K      6.5M   6% /
/dev/root                 7.5M      7.5M         0 100% /rom
tmpfs                    29.8M    100.0K     29.7M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/mtdblock3            6.9M    408.0K      6.5M   6% /overlay
overlayfs:/overlay        6.9M    408.0K      6.5M   6% /


當Yun無法連上網路時,便可使用這支草稿碼存取Yun的Linux系統,觀看Linux系統開機時輸出的訊息。當你忘記Yun的密碼時,也可使用這支草稿碼,登入後輸入指令「passwd」,然後輸入新密碼兩次即可。


參考資料:

No comments:

Post a Comment