วันศุกร์ที่ 29 ตุลาคม พ.ศ. 2553

บันทึกช่วยจำ : Serial Forwarder บน AVRORA simulator

มี Tutorial ของเรื่องนี้ที่  [1]
แต่มันมีข้อแตกต่างนิดหน่อย ที่ทำแล้วรู้สึกง่ายกว่า
เนื่องจากไม่ต้องเขียน code ใหม่ ใช้ที่มีอยู่แล้วตอนลง tinyOS [3]
ซึ่งจุดแตกต่างนี้ควรบันทึกไว้ดังนี้

1. การ compile ไฟล์ที่จะใช้ใน AVRORA ต่างจาก [1] ตรงที่จะใช้วิธีจาก [2] แทน ซึ่งจะได้ไฟล์นามกุล .elf แทนที่จะเป็น .od แบบของวิธี [1]

2. รันไฟล์ .elf ของ Base และ Sender บน AVRORA โดยใช้คำสั่งนี้
      java avrora.Main -platform=mica2 -simulation=sensor-network -seconds=160 -monitors=serial,real-time -nodecount=1,1 Base.elf Sender.elf 
    จะได้ผลเหมือนในรูปที่ 1 ใน [1]

3. ถ้ายังไม่ได้ลง  tos-install-jni ให้ลงก่อนด้วยคำสั่งนี้
      $ sudo tos-install-jni
      $ cd $TOSROOT/support/sdk/java/net/tinyos/tools
      $ make

    และต้องเพิ่ม environment สำหรับการเรียกใช้ serial forwarder ในไฟล์ ~/.bashrc ก่อน กรณีใช้ tmote sky จะเป็นดังนี้ (ดูเพิ่มเติมใน [4])
      #MOTECOM for tmote
      export MOTECOM=serial@/dev/ttyUSB0:telosb


4. เรียกใช้ serial forwarder ดังนี้
     java net.tinyos.sf.SerialForwarder -port 9002 -comm network@localst:2390
    จะได้ผลเหมือนในรูปที่ 6 ใน [1]

5. ส่วนโปรแกรม Listen ไม่ต้องมาคอมไฟล์เหมือนในรูป 2-5 ใน [1]   หากมีการทำขั้นตอนที่ 3 เรียบร้อยแล้ว ก็แค่เพียงใช้คำสั่งนี้
    java net.tinyos.tools.Listen -comm sf@localhost:9002
   ผลที่ได้จะเป็นดังรูปต่อไปนี้


อ้างอิง
[1] http://mythicalcomputer.blogspot.com/2008/10/using-serialforwarder-interface-of.html
[2] http://docs.tinyos.net/index.php/Avrora
[3] http://happinesslism.blogspot.com/2010/10/tinyos-avrora-simulator-ubuntu.html
[4] http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder

วันศุกร์ที่ 15 ตุลาคม พ.ศ. 2553

บันทึกช่วยจำ : ลง TinyOS และ AVRORA simulator บน Ubuntu

การลง TinyOS :
http://docs.tinyos.net/index.php/Getting_started_using_Ubuntu_9.10_and_TelosB_motes

การลง AVRORA simulator:
http://docs.tinyos.net/index.php/Avrora

จริงๆแล้วมี Tutorial สำหรับการลง TinyOS และ AVRORA simulator บน Ubuntu ตามลิงส์ด้านบน แต่ยังขาดรายละเอียดของการกำหนด environment เช่นพวก $TOSROOT หรือ $AVRORA รวมทั้ง CLASSPATH จึงขอเพิ่มเติมไว้ เผื่อครั้งหน้าที่ต้องลงจะได้ไม่ต้องนั่งงมโข่งอีกครั้ง

ขั้นตอนมีดังนี้
1. พิมพ์คำสั่งบน ubuntu terminal ดังนี้
$ sudo gedit ~/.bashrc

2. copy ข้อมูล environment ที่ปรากฎด้านนี้ลงในไฟล์ .bashrc

# environment variables for Tinyos and AVRORA
source /opt/tinyos-2.1.0/tinyos.sh
export TOSROOT=/opt/tinyos-2.1.0
export TOSDIR=$TOSROOT/tos
export AVRORA=$HOME/avrora
export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:$AVRORA/bin
export MAKERULES=$TOSROOT/support/make/Makerules
export PYTHONPATH=$TOSROOT/support/sdk/python

3. Save และปิดไฟล์ แล้วพิมพ์คำสั่ง
$ source ~/.bashrc

หมายเหตุ1:
มี simulator สำหรับ wireless sensor network อยู่สองตัวเด่นๆ
ตัวแรกคือ TOSSIM อันนี้เป็นของกลุ่ม berkeley
ตัวที่สองคือ AVRORA ตัวที่อธิบายไว้ข้างบน ซึ่งเป็นของกลุ่ม UCLA
แต่เนื่อง AVRORA มีข้อดีที่สามารถ monitor พลังงานของ sensor node ได้
และใช้ง่ายกว่า(ความคิดเห็นส่วนตัว) จึงเป็นตัวเลือกที่น่าสนใจมาก

หมายเหตุ2:
หากทำตามขั้นตอนที่ 1 ใน Tutorial ของ AVRORA แล้วเจอ error ใช้คำสั่งนี้เลย
$ sudo apt-get install cvs

หมายเหตุ3: 
ถ้ามีปัญหาเกี่ยวกับการ run java tools ไปดูที่ลิงส์นี้
https://sensorweb.cs.gsu.edu/wiki/index.php/Tinyos#Troubleshooting

วันจันทร์ที่ 11 ตุลาคม พ.ศ. 2553

บันทึกช่วยจำ : ข้อมูล GPS

มีข้อมูล GPS จากอุปกรณ์อะไรก็ได้ที่อ่านค่า longitude และ latitude ได้
แต่อยากรู้ว่าค่า longitude และ latitude นี้อยู่ตรงไหนของโลก วิธีง่ายๆคือ
ไปที่เว๊บนี้ http://www.gpsvisualizer.com/map_input
แล้วใส่ค่า longitude และ latitude ก็จะได้แผ่นที่อันสวยสดงดงามแล้ว

อาจจะมีวิธีที่ง่ายกว่านะ ลองหาดู...

วันจันทร์ที่ 4 ตุลาคม พ.ศ. 2553

บันทึกช่วยจำ : สร้าง reference ด้วย BibTex

ทำมาสองครั้งสองครา แต่นานๆจะได้ทำ
พอจะต้องทำ ลืมวิธีทุกที ต้องจดเก็บไว้สักหน่อย

การสร้าง reference แบบอัตโนมัติในการเขียนบทความวิชาการด้วย Latex โดยใช้ BibTex

อุปกรณ์ :
1. Kile : โปรแกรม latex editor บน Ubuntu
2. ต้องแน่ใจว่า KbibTex ถูกพ่วงมากับ Kile แล้ว ถ้าไม่ถูกพ่วงดู link นี้ http://www.unix-ag.uni-kl.de/~fischer/kbibtex/kile.html
3. IEEE BibTex Template จาก link นี้ http://www.ieee.org/conferences_events/conferences/publishing/templates.html

ขั้นตอน
1.สร้าง bib file ด้วย KbibTex ตั้งชื่อให้เขา สมมุติว่าชื่อ paper.bib
ตัวอย่างของ bib file
----------------------------------------------
@InProceedings{ Barrenetaxea08,
    author = "Guillermo Barrenetxea and Fran?ois Ingelrest and Gunnar Schaefer and Martin Vetterli and Olivier Couach and Marc Parlange",
    title = "SensorScope: Out-of-the-Box Environmental Monitoring",
    booktitle = "Int. Conf. on Information Processing in Sensor Networks (ISPN)",
    volume = "0",
    isbn = "978-0-7695-3157-1",
    year = "2008",
    pages = "332--343",
    doi = "http://doi.ieeecomputersociety.org/10.1109/IPSN.2008.28",
    publisher = "IEEE Computer Society",
    address = "Los Alamitos, CA, USA"
}
-------------------------------------------------------------------

2.ในพื้นที่ของ latex ที่ต้องการให้มี section ของ reference ใส่คำสั่งนี้
\bibliographystyle{IEEEtran}
\bibliography{IEEEabrv,paper}
บรรทัดแรกเป็นการเรียกใช้ IEEEtran.bst ใน Template ที่ดาวน์โหลดมา
บรรทัดสองเป็นการเรียกใช้ IEEEabrv.bib ใน Template ที่ดาวน์โหลดมา และเรียกใช้ paper.bib ที่สร้างขึ้นมา

3.ในจุดที่ต้องการอ้างอิงให้พิมคำสั่ง
\cite{Barrenetaxea08}

4.ใน Kile คอมไฟล์ bib.file
  -4.1 เน้นว่าต้องมีข้อ 3 อย่างน้อยหนึ่งคำสั่ง ไม่งั้นคอมไพล์ด้วย error เพราะนี้คือ bug
  -4.2 ต้องคอมไฟล์ latex ด้วย การกด Alt+6 ก่อน
  -4.3 ต้องทำ 4.2 ก่อน 4.4 ไม่งั้นคอมไพล์ไม่ผ่าน มันคือ bug เช่นกัน
  -4.4 คอมไฟล์ bib file ด้วยการกด Alt+-
  -4.5 ทำขั้นตอน 4.2 อีกครั้ง ถ้าให้ชัวร์สักสองครั้ง

5. ผลที่ได้
  -5.1 ที่ข้อความที่อ้างอิงด้วย \cite{Barrenetaxea08}ก็จะเกิดข้อความ "[1]" ขี้นมา
         ตัวอย่างเช่น
         "in environmental monitoring [1]" 

        ถ้าเรียก \cite{label ที่ปรากฎใน bib file} อีกครั้งจะขึ้นข้อความ "[2]"

  -5.2 ตรงส่วนของ reference ก็จะเป็นประมาณนี้

[1] G. Barrenetxea, F. Ingelrest, G. Schaefer, M. Vetterli, O. Couach, and
M. Parlange, “Sensorscope: Out-of-the-box environmental monitoring,” in
Int. Conf. on Information Processing in Sensor Networks (ISPN), vol. 0.
Los Alamitos, CA, USA: IEEE Computer Society, 2008, pp. 332–343.

bib file ที่เราสร้างไว้จะสามารถนำไปใช้ในการเขียนบทความใหม่ได้อีกต่อไป (ใช้ซ้ำได้นั้นเอง) คราวหน้าจะไม่ต้องสร้างใหม่

วันศุกร์ที่ 1 ตุลาคม พ.ศ. 2553

บันทึกช่วยจำ : ว่าด้วยการจัดการข้อมูล sensor nodes

มีข้อมูลดิบจาก sensor nodes อยู่ 94 ไฟล์ ไฟล์ละสี่สิบกว่าเมกกะไบต์
แต่ต้องการแค่ 3000 บรรทัดในวันเวลาเดียวกันจากทุกไฟล์มาใช้
จะจัดการมันอย่างไร ขืนนั่งทำมือ (do manually) คงเหนื่อยนัก

ต้องเขียน code จัดการมัน
เนื่องจากได้ตัดขาดจาก window มานานนม
ทุกอย่างจึงเกิดขึ้นบน Ubuntu หนึ่งในระบบปฏิบัติการแบบ Linux

Top layer ก็ถูกเขียนด้วย shell script ไว้สำหรับเรียกใช้ second layer ซึ่งเขียนด้วย C++

ใน shell script ก็ยัดชื่อไฟล์จะที่อ่านและที่จะบันทึกเข้าไปอย่างซื่อๆ ซึ่งมีรายละเอียดดังต่อไปนี้
########################

#!/bin/sh                   
# Written by Tossaporn Srisooksai
########################
for foo in 3 5 7 8 9
do
 ./rawdata_management 2007 03 23 00 00 3000 1 "sensorscope-meteo-$foo.txt" "$foo.csv"
done

for foo in 10 11 12 13 14 15 17 18 19 21 23 24 25 26 27 30 31 32 33 34 35 36 37 39 40 41 42 43 44 45 46 47 49 50 51 53 54 55 56 57 59 60 61 62 63 64 65 66 68 69 70 71 72 73 75 76 79 80 81 82 84 85 87 88 89 92 93 94 95 96 97 98 99
do
 ./rawdata_management 2007 03 23 00 00 3000 2 "sensorscope-meteo-$foo.txt" "$foo.csv"
done

for foo in 100 103 104 105 106 107 109 111 121 122 #201 202 203 204 206 207
do
 ./rawdata_management 2007 03 23 00 00 3000 3 "sensorscope-meteo-$foo.txt" "$foo.csv"
done

exit 0
========================

อย่าลืมเปลี่ยน mode ด้วยคำสั่ง sudo chmod a+x ก่อนที่จะรัน

ส่วน rawdata_management (second lalyer) ซึ่งถูกเขียนด้วย C++ เป็นดังนี้

/***************************************************/
/* Preparing raw data of sensor nodes for Octave */
/* Written by Tossaporn Srisooksai 30/9/2010       */
/***************************************************/

#include   //iostream
#include    //fstream
#include       //string
#include      //stdio.h
#include     //stdlib.h
using namespace std;

int main (int argc, const char* argv[]) {
  if (argc != 10)
  {
   cout << "\nUsage: < YYYY MM DD HH mm line_max mode input_file output_file> " << endl;
   exit(0);
  }
  string line;         //input file stream
  string target_date;  //checking start date
  string target;       //setting start date
  char input_file[20];
  char output_file[20];
  int flag = 0;         // flag of writing output file
  int i = 0;            // copied line counter
  int i_max;            // max of copied line
  int mode;             // mode of node number
  int n;                // pointer the space existed in line stream
  int j;               
 
  //get the start date
  target = argv[1];
  target += ' ';
  target += argv[2];
  target += ' ';
  target += argv[3];
  target += ' ';
  target += argv[4];
  target += ' ';
  target += argv[5];
  //cout << target << endl;

  // max of copied line
  i_max = atoi(argv[6]);
 
  // mode of node number
  mode = atoi(argv[7]);

  // open input and output file
  ifstream inFile (argv[8]);
  ofstream outFile (argv[9]);
   

  if (inFile.is_open())
  {
    while (!inFile.eof() )
    {
      getline (inFile,line);
      target_date.assign(line,mode+1,16);  //check the start date
      //cout << target_date << endl;
        if ( target_date == target )
        { flag = 1;                       // output file can be written now
        }
        if (outFile.is_open())
        { if (( flag == 1) && (i < i_max ))
          {
            for (j=1; j<18; j++)   // change space to ","
            {
              n=line.find_first_of(" ",1);
              line.replace(n,1,",");
            }
            outFile << line << endl;   //write line to output file
            //cout << line;
            i=i+1;     
          }
        }
        else cout << "Unable to open output file";
    }
    inFile.close();         //close file
    outFile.close();
  }

  else cout << "Unable to open raw data file"; 
  return 0;
}



========================

คอมไฟล์ไว้ที่โฟลเดอร์เดียวกับ shell script ด้วยคำสั่ง g++ -o rawdata_management rawdata_management.cpp

จบ........

บันทึกช่วยจำ : เกริ่นนำ

เนื่องจากการเสื่อมสภาพของหน่วยความจำสมอง
ข้อมูลบางอย่างบันทึกไว้ในคอม ยังค้นหาไม่เจอ
จึงคิดจะบันทึกไว้ในที่ google ช่วยค้นหาให้ได้

แต่จะสร้างบล๊อกอีกบล๊อกเพื่อช่วยจำอีกก็กระไรอยู่
แค่บล๊อกนี้บล๊อกเดียวก็ไม่ค่อยได้อัปเดทแล้ว

ก็ฝากๆฝังๆบันทึกช่วยจำไว้ในบล๊อกนี้ก็แล้วกัน

ถ้าใครเคยไปอ่านสมุดเลกเชอร์ของคนอื่นแล้วงงๆ
ฉันใดก็ฉันนั้น เรื่องบันทึกช่วยจำของผมก็จะทำให้ท่านรู้สึกเยี่ยงนั้นเช่นกัน

แต่หากมันบังเอิญไปมีประโยชน์กับท่านใด
แล้วอยากถามรายละเอียดเพิ่มเติมก็คอมเมนส์ไว้ในบล๊อก
ผมจะพยามยามอธิบายความคิดอันสับสันของตัวเองให้ฟัง
ซึ่งมันอาจจะทำให้ท่านงงเพิ่มขึ้นอีกก็เป็นได้ 555

วันสุขของน้อง

มีน้องคนหนึ่งโทรมา
บอกมาว่ามีเรื่องทุกข์ร้อนมาปรึกษา
แต่ไม่รู้ทุกข์ร้อนอย่างไรของมัน
มันคุยไปหัวเราะร่วนไป...

แล้วเราก็ไม่ได้คุยเรื่องทุกข์ร้อนเท่าไร
เพราะแวะออกข้างทางอยู่เรื่อย

แต่ประเด็นคือมันโทรมาฝากฝังให้ดูแลน้องอีกคน
บอกว่าอย่าออกสื่อมากนัก
ฟังดู..เหมือนน้องคนนี้จะชื่อฟิล์มนะ

วันนี้วันศุกร์...ก็คิดป่านนี้น้องคงสุขล้นแล้ว

ขอจบบทความซึ่งเต็มไปด้วยภาษาลูกเสือนี้ แบบงงๆ