TinyOS and Home

0

源起

開發一個客廳應用,需要佈署無線的感測器,與連上 internet 的裝置。

TinyOS

有些硬體會提到內建 tinyos ,TinyOS 本身就是為網路感測器所設計的作業系統。因為這類裝置有耗電低的門檻,運算資源受到限制,卻需要面對網路上密集的同步運作,所以需要特殊的作業系統來滿足。

既然是小型,代表其中的 C 函式庫支援也是小型的,採用 NesC 來編譯。

TinyOS 2.0 Tutorials

開發可以直接在電腦上運行所謂的 offline simulation,非常方便測試整個網路。

目前網上可以看到專案都是學術為主,商業往往資料比較少。

Harvard Network Sensor Testbed

無線感測網路運用於台灣不同林分微氣候觀測

台灣不同林分微氣候觀測WEB即時監測

無線感測器網路 Wireless Sensor Networks

如果需要實體測試,可以找下面連結。

moteiv

xbow.com

識方科技

集研

RFID and liveroom

0

源起

客廳應用,需要佈署無線的感測,與連上 internet 的裝置。

rfid links

rfid 的 tag 可以不用電很方便,價格更是低廉,只是讀取器比較貴,即使是 SDIO 版本也不便宜。因為通常需要買其中的 SDK 來用。

rfid shop

帝商科技

pnp rfid

rfid journal

acer pda

Interrogator

目前 EPC Reader Protocol Standard 尚未成為標準,所以各家有各家的做法。

EPC Reader Protocol Standard

Choosing an EPC Gen 2 Interrogator

mercury4 是個內嵌 TCP 服務的裝置,可以直接用 TCP 對談,語法是所謂的 RFID Reader Qurey Protocol (RQL) ,類似 SQL 語言,預設用 8080 port,裝置大約 US 1000

thingmagic mercury4

Alien ALR-9800 是 Linux 的裝置, 可用 TCP 來取得資料,用的是 Alien reader protocol/EPC reader protocol。

Alien ALR-9800

symbol XR 這系列直接用 HTTP 協定外包 reader protocol,省掉定義一些格式。同時這家公司也推出 wifi 的版本,連網路線都省了。

只是玩玩

rfidtoys

phidgets rfid reader

它也有 java 介面,該介面用 tcp 網路與一個 Phidget Server port 5001 對談,所以不需要 JNI 幫助。

phidgets linux support

IDM store 台灣

Why I like slax popcorn

0

源起

用 slax popcorn 有一段時間,將在這裡紀錄一些經驗。

好的一面 pro

  1. 圖形介面中比較小的
  2. 安裝新軟體非常容易
  3. 測試環境乾淨
  4. 可以借用龐大數量的自由軟體,只要該平台的 vm 虛擬軟體可以 boot cdrom 就可以。
  5. 搭 vmdk 做硬碟可以直接拷貝,複製一台機器。

不好的一面 con

  1. 乾淨環境的意思就是重開後一切消失。
  2. uselivemo 是直接蓋過去,不知如何 umount ,需要再找資料。

Apache in Slax

0

源起

apache 調試需要不同參數,所以建立這個 mo 順便測看看不同編譯的效能差異。

apache.mo

老步驟。

  1. cd /mnt/hda1
  2. wget httpd-2.2.3.tar.bz2
  3. tar jxvf httpd-2.2.3.tar.bz2
  4. cd httpd-2.2.3
  5. ./configure
  6. make
  7. checkinstall
  8. mv httpd-2.2.3-i386.tgz ../
  9. cd ..
  10. mkdir /mnt/hda1/work/apache
  11. installpkg -root /mnt/hda1/work/apache httpd-2.2.3-i386.tgz
  12. cd /mnt/hda1/work
  13. dir2mo apache apache-2.2.3.mo

test apache-2.2.3.mo

  1. reboot first
  2. uselivemod apache-2.2.3.mo
  3. /usr/local/apache2/bin/apachectl -k start
  4. netstat -at

結果要看大一點的檔案會發現開不起來,看 access log 發現都是 HTTP STATUS 206,沒有資料傳出,google 發現這篇有提到這個 sendfile syscall 的問題。同時查到 Unionfs 尚未支援 sendfile 的類似訊息。

根據建議,將 httpd.conf 做點修正,EnableSendfile 改 off 就可以跑起來,進一步參閱 EnableSendfile Directive

但是如果需要測試 sendfile 的話,就需要裝在別的檔案系統,例如之前裝在 tmpfs 的做法。

要先改 httpd.conf 讓它使用 EnableSendfile,同時 DocumentRoot 指到 /mnt/hda1/tmpfs/apache2/htdocs,重新開機後,另外加上可以填滿 htdocs 的東西。

  1. mount tmpfs /mnt/hda1/tmpfs -t tmpfs -o size=64m
  2. mkdir -p /mnt/hda1/tmpfs/apache2/htdocs
  3. cp something to htdocs
  4. /usr/local/apache2/bin/apachectl -k start

雙機作業

這次測希望用兩台機器來測,而不是單機測,所以直接把 slax.vmx 那個檔案夾複製一個,就生出另一台 slax2 機器可以用,還包含一顆一模一樣的硬碟(vmdk)可用。

但是用之前要先改一下網卡的硬體位址,免得衝到,所以打開 slax2 的 slax.vmx,將其中一行 ethernet0.generatedAddress 後面隨便加個一就可以了。

一開機會希望你建立一個新的識別,我是直接建立,不過開機後要立刻按 F2 去改 BIOS,讓 CDROM 先開機。開機完只要互相 ping 一下,確定網路已通就可以開始雙機暴走測試。

benchmark

TODO 未完待續。

httpmark.mo

0

有些事要先知道

部落格的文件發布時間不一致,有時寫的時候並沒有考慮到後來的發展,所以文件往往缺乏一貫與完整性,為避免看的人一頭霧水,於是在文件前稍微介紹一下這個練習的來龍去脈。

  1. 如何使用 vmplayer 玩 ISO 檔請參考 dsl in vmplayer
  2. slax 在 vmplayer 上玩請參考 Slax popcorn in vmplayer
  3. gcin 中文輸入請參考 gcin in slax popcorn
  4. jre/apr-tcnative/tomcat 請參考 Native Tomcat in Slax
  5. 網頁測試 autobench.mo 請參考 httperf and autobench

源起

之前包 autobench.mo 為求方便,只有加個輸出單張的 PNG 的 script 而已,這次想要修改一下輸出樣式,可以輸出一個簡易 HTML 報告, 這樣到底是要繼續改 bench2png 還是另外作 ? 這裡選擇另外作 shell script 來跑,因為 perl 不熟 :-)

要輸出 HTML 當然需要 HTTP 服務,內建要選小一點的,所以選 lighttpd 供測試與展示 HTML 使用。

lighttpd inside

注意編譯 lighttpd 期間需要 pcre 支援,安裝完並不需要這個 pcre。

  1. wget pcre; configure; make; checkinstall
  2. wget lighttpd; configure; make; checkinstall

試運轉後發現 lighttpd 需要使用 sendfile 支援,而這個部份似乎有點問題,必須考量將 www 等目錄掛在 tmpfs 上。

  1. cd /mnt/hda1/work
  2. mkdir httpmark
  3. installpkg -root httpmark ../httperf-0.8-i386-1.tgz
  4. installpkg -root httpmark ../autobench-2.1.2-i386-1.tgz
  5. installpkg -root httpmark ../lighttpd-1.4.11-i386-1.tgz
  6. cd httpmark
  7. mkdir -p usr/local/lighttpd/www/test
  8. mkdir -p usr/local/lighttpd/logs
  9. echo “httpmark work” > usr/local/lighttpd/www/index.html
  10. echo “httpmark test” > usr/local/lighttpd/www/test/index.html

這裡預設會輸出 4 個圖檔,與 4 個 tsv 檔。

<img src="hmark_1.png"/>
<a href="hmark_1.tsv.txt">hmark_1.tsv</a>
.....

同時放幾個 jpg 檔進去。test10k/test20k/test50k/test100k,同時把設定檔調一下。

  1. cp /mnt/hda1/lighttpd-1.4.11/doc/lighttpd.conf usr/local/lighttpd/
  2. cp /mnt/hda1/lighttpd-1.4.11/doc/rc.lighttpd usr/local/lighttpd/
  3. cd usr/local/lighttpd/

接下來改 lighttpd 啟動檔, vi my.lighttpd 如下,主要是一開始劃出 tmpfs 來掛的要求必須滿足。

#! /bin/sh
# Check lighttpd
LIGHTTPD_BIN=/usr/local/sbin/lighttpd
if [ ! -e $LIGHTTPD_BIN ]; then
        echo "ERROR : $LIGHTTPD_BIN DO NOT exist." 
        exit 0
fi
#
# check tmpfs for lighttpd
#
LIGHTTPD_HOME=/usr/local/lighttpd
LIGHTTPD_FS=/usr/local/tmpfs/lighttpd
target=`df -h | grep "$LIGHTTPD_FS"`
if [ "$target" == "" ]; then
        echo "Mount tmpfs in $LIGHTTPD_FS" 
        [ -e $LIGHTTPD_FS ] || mkdir -p $LIGHTTPD_FS
        mount tmpfs $LIGHTTPD_FS -t tmpfs -o size=24m
        mkdir -p $LIGHTTPD_FS/logs
        cp -r $LIGHTTPD_HOME/www/ $LIGHTTPD_FS
fi

LIGHTTPD_HOME=/usr/local/lighttpd
LIGHTTPD_CONF_PATH=$LIGHTTPD_HOME/lighttpd.conf

case "$1" in
    start)
        echo "Starting lighttpd..." 
        # check if lighttpd.pid file exists [mylighttpd.sh creates it.]
        if [ -e $LIGHTTPD_HOME/lighttpd.pid ] ; then
                pid=`cat $LIGHTTPD_HOME/lighttpd.pid`
                # check if process is still running
                if [ -d "/proc/$pid" ]; then
                        echo "lighttpd already running as process $pid.Stop it first.." 
                        exit 0
                fi
        fi
        $LIGHTTPD_BIN -f $LIGHTTPD_CONF_PATH &
        echo $! > $LIGHTTPD_HOME/lighttpd.pid
        ;;
    stop)
        echo "Shutting down lighttpd..." 
        if [ -e $LIGHTTPD_HOME/lighttpd.pid ] ; then
                pid=`pgrep lighttpd`
                kill $pid
                rm $LIGHTTPD_HOME/lighttpd.pid
        fi
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}" 
        exit 1
        ;;
esac

然後修改設定檔,將路徑指到 tmpfs 去。

vi usr/local/lighttpd/lighttpd.conf

server.document-root        = "/usr/local/tmpfs/lighttpd/www/" 
server.errorlog             = "/usr/local/tmpfs/lighttpd/logs/lighttpd.error.log" 
accesslog.filename          = "/usr/local/tmpfs/lighttpd/logs/access.log" 

接下來重開機測試 lighttpd。

#dir2mo httpbench httpmark-0.1.mo #reboot
  1. uselivemod httpmark-0.1.mo
  2. /usr/local/lighttpd/my.lighttpd start
  3. netstat -at
  4. check http://127.0.0.1/

gnuplot 的樣本檔

建立一個 gnuplot 的樣本檔,可以先跑看看,然後到時候用 sed 換字就好。

  1. cd /mnt/hda1/work/httpmark
  2. mkdir usr/local/httpmark
  3. cd usr/local/httpmark
  4. vi httpmark.plt
set terminal png small color
set key outside below
set key box
set grid
set output "results.png" 
set data style linespoints
set title "results.title" 
set xlabel "X Axis : dem_req_rate" 
set y2tics
set ytics nomirror
set y2label "Y2 Axis : Mbps" 
plot "results.tsv" using 1:2 every ::1 ti "req rate" , \
"results.tsv" using 1:3 every ::1 ti "conn rate" , \
"results.tsv" using 1:7 every ::1 ti "std_req_rate", \
"results.tsv" using 1:8 every ::1 ti "resp_time(ms)", \
"results.tsv" using 1:10 every ::1 ti "error", \
"results.tsv" using 1:($9*8/1024) every ::1 ti "net_io(Y2)" axis x1y2

關於 gnuplot 可以參考。

http://t16web.lanl.gov/Kawano/gnuplot/plot1-e.html#5.2 http://www.gnuplot.info/faq/faq.html http://www.gentoo.org/doc/en/articles/l-awk1.xml?style=printable

httpmark.sh

  1. vi httpmark.sh
  2. chmod +x httpmark.sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
echo "httpbench runing...." 
echo "test : $1" 
echo "low rate : $2" 
echo "high rate : $3" 
echo "num call : $4" 
echo "num conn  : $5" 
echo "rate step : $6" 

#
# check autobench
#
abcmd=/usr/local/bin/autobench
if [ ! -e $abcmd ]; then
        echo "autobench is not install." 
        exit 0
fi
#
# autobench need conf file
#
exaconf=/usr/local/etc/autobench.conf
aconf=$HOME/.autobench.conf
[ ! -e "$aconf" ] && cp $exaconf $aconf

#
# gnuplot template
#
HTTPMARK_HOME=/usr/local/httpmark
plt=$HTTPMARK_HOME/httpmark.plt
HTDOC=/usr/local/tmpfs/lighttpd/www
#
# run autobench
#
uri="/test" 
testfile="test10k.jpg" 
echo "Run autobench with num_call $4" 
tsvfile=hmark_$1.tsv
echo "tsv file : $tsvfile" 
pngfile=hmark_$1.png
echo "png file : $pngfile" 
title="hmark($testfile) n_call=$4,n_conn=$5" 
echo "title : $title" 
autobench --single_host --host1 127.0.0.1 \
 --port1 80 --uri1 $uri/$testfile --quiet \
 --low_rate $2 --high_rate $3 --rate_step $6 \
 --num_call $4 --num_conn $5 --timeout 5 \
 --file $tsvfile
# sed file
sed -e "s/results.tsv/$tsvfile/g" \
-e "s/results.png/$pngfile/g" \
-e "s/results.title/$title/g" $plt | gnuplot
mv $pngfile $HTDOC/
mv $tsvfile $HTDOC/$tsvfile.txt
echo "httpbench done." 
exit 0

  1. /usr/local/httpmark/httpmark.sh
  2. dir2mo httpmark httpmark-0.1.mo
  3. reboot

final run

  1. uselivemod gnuplot.mo
  2. uselivemod httpmark-0.1.mo
  3. /usr/local/lighttpd/my.lighttpd start
  4. /usr/local/httpmark/httpmark.sh 1 50 150 1 600 10

跑完可以到 http://127.0.0.1 去看結果,測試需要不斷調整觀察,這個部份是最難的,一直到找出轉折點,換成 httpmark.sh 2 xx xx xx xx xx 繼續跑,可以放 4 個結果。

download

httpmark-0.1.mo

Older posts: 1 2 3 4 5