build automation using wireless sensor network

307
ระบบอาคารอัจฉริยะโดยใชเครือขายเซ็นเซอรไรสาย นายเอกชัย ยอดตาคํา นางสาวกัญญณัฐ มนตประเสริฐ นางสาวชรินรัตน วงศธนะรักษ นายสถาพร สงาศรี ปริญญานิพนธนี้เปนสวนหนึ่งของการศึกษาตามหลักสูตร ปริญญาวิศวกรรมศาสตรบัณฑิต สาขาวิชา วิศวกรรมไฟฟา ภาควิชาวิศวกรรมไฟฟา คณะวิศวกรรมศาสตร มหาวิทยาลัยเทคโนโลยีพระจอมเกลาพระนครเหนือ ปการศึกษา 2550

Upload: a-omm-ratt

Post on 28-Apr-2015

158 views

Category:

Documents


13 download

TRANSCRIPT

Page 1: Build Automation Using Wireless Sensor Network

ระบบอาคารอจฉรยะโดยใชเครอขายเซนเซอรไรสาย นายเอกชย ยอดตาคา นางสาวกญญณฐ มนตประเสรฐ

นางสาวชรนรตน วงศธนะรกษ

นายสถาพร สงาศร

ปรญญานพนธนเปนสวนหนงของการศกษาตามหลกสตร ปรญญาวศวกรรมศาสตรบณฑต

สาขาวชา วศวกรรมไฟฟา ภาควชาวศวกรรมไฟฟา คณะวศวกรรมศาสตร มหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ

ปการศกษา 2550

Page 2: Build Automation Using Wireless Sensor Network

Building Automation System Using Wireless Sensor Network

Mr. Ekachai Yordtakam

Ms. Ganyanut Monprasert

Ms. Charinrat Wongtanarak Mr. Sataporn Sa-ngasri A PROJECT REPORT SUBMITTED IN PARTIAL FULFILMENT OF THE REQUIREMENTS

FOR THE DEGREE OF BACHELOR OF ELECTRICAL ENGINEERING DEPARTMENT OF ELECTRICAL ENGINEERING

FACULTY OF ENGINEERING KING MONGKUT’S UNIVERSITY OF TECHNOLOGY NORTH BANGKOK

ACADEMIC YEAR 2007

Page 3: Build Automation Using Wireless Sensor Network

ปรญญานพนธเรอง : ระบบอาคารอจฉรยะโดยใชเครอขายเซนเซอรไรสาย ชอ : นายเอกชย ยอดตาคา นางสาวกญญณฐ มนตประเสรฐ นางสาวชรนรตน วงศธนะรกษ นายสถาพร สงาศร สาขาวชา : วศวกรรมไฟฟา ภาควชา : วศวกรรมไฟฟา คณะ : วศวกรรมศาสตร อาจารยทปรกษา : ดร.พงษศกด กรตวนทกร ปการศกษา : 2550

คณะวศวกรรมศาสตร มหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ อนมตใหปรญญานพนธนเปนสวนหนงของการศกษาตามหลกสตรปรญญาวศวกรรมศาสตรบณฑต สาขาวศวกรรมไฟฟา

..................................................................... หวหนาภาควชาวศวกรรมไฟฟา (รองศาสตราจารย ดร.วรา วราวทย) ..................................................................... ประธานกรรมการ (ดร.พงษศกด กรตวนทกร) ..................................................................... กรรมการ (รองศาสตราจารยเวช วเวก)

..................................................................... กรรมการ (ผชวยศาสตราจารยสทธพร เกดสาอางค)

ลขสทธของภาควชาวศวกรรมไฟฟา คณะวศวกรรมศาสตร

มหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ

Page 4: Build Automation Using Wireless Sensor Network

Project Report Title : Building Automation System Using Wireless Sensor Network Name : Mr. Ekachai Yordtakam Ms. Ganyanut Monprasert Ms. Charinrat Wongtanarak Mr. Sataporn Sa-ngasri Major Field : Electrical Engineering Department : Electrical Engineering Faculty : Engineering Project Advisor : Dr. Phongsak Keeratiwintakorn Academic Year : 2007

Accepted by the Faculty of Engineering, King Mongkut’s University of Technology North Bangkok in Partial Fulfillment of the Requirements for the Degree of Bachelor of Electrical Engineering.

.......................................................... Head of the Department of Electrical Engineering (Assoc. Prof. Dr. Vara Varavithya)

.......................................................... Chairperson (Dr. Phongsak Keeratiwintakorn)

.......................................................... Member (Assoc. Prof. Vech Vivek) .......................................................... Member (Asst. Prof. Sithiporn Kerdsum-ang)

Copyright of the Department of Electrical Engineering, Faculty of Engineering

King Mongkut’s University of Technology North Bangkok

Page 5: Build Automation Using Wireless Sensor Network

บทคดยอ

โครงงานนมวตถประสงคเพอสรางระบบเครอขายเซนเซอรไรสายภายในอาคาร ใชในการตรวจสอบอณหภมและแสงสวาง โดยทาการประยกตอปกรณ TmoteSky ทมอยเดมเพอใหเหมาะสมกบระบบทสรางขน โดยระบบอาคารอจฉรยะจะใชอปกรณเซนเซอรไรสาย TmoteSky ซงสามารถสรางเปนเครอขายแบบ Ad-hoc ภายใตการควบคมการทางานบนโปรโตคอล IEEE 802.15.4 (Zigbee) และระบบปฏบตการ TinyOS เมอเซนเซอรตรวจจบคาแสงและอณหภมไดแลวจะสงคาไปบนทกไวทฐานขอมลบนเซรฟเวอร (Server) ซงจดนเองทาใหผใชงานสามารถรบทราบสถานะของตวอาคารโดยใชคอมพวเตอรหรอโทรศพทมอถอผานทางเครอขายอนเตอรเนตได เนองจากระบบถกออกแบบใหแสดงผลบนเวบไซดและโทรศพทมอถอ

Page 6: Build Automation Using Wireless Sensor Network

Abstract

This project has an objective to create the building’s monitoring system and display status on website or mobile phone. To accomplish a goal must apply TmoteSky to be the best suitable device for system which have the quality to build Ad-hoc network under control of IEEE 802.15.4 (Zigbee Protocol) and TinyOS. When sensors verify temperature and light’s values are sent to record at database on server that make user can know the building’s status by using the computer or mobile phone connected through an internet network.

Page 7: Build Automation Using Wireless Sensor Network

กตตกรรมประกาศ

คณะผจดทาโครงงานขอขอบพระคณ รองศาสตราจารยเวช วเวก อาจารยปรชา ทองดษฐ ทใหคาปรกษาในการคนควาหาขอมลตาง ๆ อนเปนประโยชนตอโครงงานน ขอขอบพระคณ อาจารยรสล สทธวรกล ทใหคาแนะนาเทคนคดานซอฟตแวร ขอขอบพระคณ ผชวยศาสตราจารย ดร.มารอง ผดงสทธ ดร.เรวต ศรโภคาภรมย และคณกฤษณะศกด พวงจนทร ทเออเฟอและใหความสะดวกสถานทตดตงอปกรณในการทาโครงงาน ขอขอบพระคณ ดร.พงษศกด กรตวนทกร ทใหคาปรกษาดานการออกแบบ และเทคนคการสรางเครอขายเซนเซอรไรสาย ขอบพระคณ คณรฤก รกษความสข สาหรบทก ๆ เครองมอและอปกรณ ขอขอบพระคณ คณสราวฒ สบแยม สาหรบทกการประชาสมพนธทชวยใหรบรขาวสารตาง ๆ ขอบคณเพอน ๆ ในภาควศวกรรมไฟฟาสอสารและคอมพวเตอรทกคน ทคอยใหความชวยเหลอในทกดาน ขอบคณทก ๆ กาลงใจทมใหกน ขอบคณงานทมมากกวาเวลา ขอบคณทกอปสรรคทเปนแรงผลกดนใหผจดทากาวไปสจดมงหมาย ทสาคญทสดในชวตขอกราบขอบพระคณ คณพอ และคณแมของคณะผจดทาทกทานทเปนแรงบนดาลใจ และคอยใหกาลงใจทกครงทเกดปญหา ทาใหทก ๆ เรองผานพนอปสรรคไปไดดวยด

เอกชย ยอดตาคา กญญณฐ มนตประเสรฐ ชรนรตน วงศธนะรกษ สถาพร สงาศร

Page 8: Build Automation Using Wireless Sensor Network

สารบญ

หนา บทคดยอภาษาไทย จ บทคดยอภาษาองกฤษ ฉ กตตกรรมประกาศ ช สารบญตาราง ฎ สารบญภาพ ฏ บทท1. บทนา 1 1.1 วตถประสงค 1 1.2 ทฤษฏทเกยวของ ลกษณะของงานทมมากอน 1 1.3 วธการของโครงการ 2 1.4 ขอบเขตของโครงงาน 3 1.5 ประโยชนทคาดวาจะไดรบ 3 บทท 2. ทฤษฎทเกยวของ 4 2.1 เทคโนโลยไรสาย 4 2.1.1 ความหมายของเทคโนโลยไรสาย 4 2.2 IEEE 802.15.4 (Zigbee) 6 2.3 TinyOS 7 2.4 NesC 8 2.4.1 Component 8 2.4.2 Interface 8 2.4.3 Application 9 2.5 JAVA 9 2.5.1 J2SE (Java 2 Standard Edition) 10 2.5.2 J2ME (Java 2 Micro Edition) 10 2.5.3 JDBC (JAVA Database Connectivity) 12 2.6 Web Application 13 2.6.1 HTML (Hyper Text Makeup Language) 13

Page 9: Build Automation Using Wireless Sensor Network

สารบญ (ตอ)

หนา 2.6.2 Java Script 16 2.6.3 SQL (Structured Query Language) 18 2.6.4 PHP (Hypertext Preprocessor) 19 บทท 3. ศกษาและทดสอบประสทธภาพของเซนเซอรโหนด 22 3.1 อปกรณพนฐานทใชในการทาโครงงาน 22 3.1.1 TmoteSky 22 3.1.2 TmoteInvent 25 3.2 โปรแกรมทใชในการพฒนาโครงงาน 27 3.2.1 Cygwin 27 3.2.2 Xampp 27 3.2.3 Eclipse 27 3.3 การทดสอบประสทธภาพของอปกรณ 28 3.3.1 การวาง TmoteSky ในรปแบบตาง ๆ 28 3.3.2 การทดสอบความสามารถในการสงสญญาณของ TmoteSky ทระดบ ทระดบความสงตางกนของสายอากาศ 29 3.3.3 การทดสอบความสามารถในการสงสญญาณของ TmoteSky ผานวสด ผานวสดตาง ๆ 30 3.3.4 การทดสอบความสามารถในการสงสญญาณของ TmoteSky ภายใน ภายในและภายนอกอาคาร 31 3.4 การออกแบบและสรางโปรแกรมทใชในการวดคา RSSI สาหรบ Tmote 34 3.4.1 OscopeRssi_M.nc 34 3.4.2 OscopeRssi.nc 34 3.4.3 Makefile 34 3.4.4 OscopeRssi.h 34 3.5 สรปผลการทดลองโดยใชโปรแกรม OscopeRssi 34

Page 10: Build Automation Using Wireless Sensor Network

สารบญ (ตอ)

หนา บทท 4. ออกแบบและตดตงเครอขายเซนเซอรไรสาย 35 4.1 ออกแบบเครอขายเซนเซอรไรสาย 35 4.2 การตดตงเครอขายเซนเซอรไรสาย 36 4.2.1 การออกแบบบรรจภณฑ 36 4.2.2 แหลงจายพลงงาน 37 4.2.3 อปกรณทใชในการตดตงเครอขายเซนเซอรไรสาย 37 บทท 5. การออกแบบและพฒนาซอฟตแวรสาหรบโครงงาน 46 5.1 พฒนาซอฟตแวรสาหรบอปกรณ 46 5.1.1 การกาหนดพลงงาน 46 5.1.2 การสงแพคเกจขอมล 46 5.1.3 การอานคาจากเซนเซอร 46 5.1.4 การสงแพคเกจขอมลไปยงเซรฟเวอร 46 5.1.5 สวนประกอบตาง ๆ ของโปรแกรม DTSR 46 5.2 พฒนาซอฟตแวรบนคอมพวเตอร 47 5.3 พฒนาซอฟตแวรเพอแสดงผลบนเวบไซด 47 5.4 พฒนาซอฟตแวรบนโทรศพทมอถอ 47 5.5 การแสดงผลบนเวบเบราเซอร 48 5.6 การแสดงผลบนโทรศพทมอถอ 57 บทท 6. สรปผลการทดลอง 62 6.1 สรปผลการทาโครงงาน 62 6.2 ปญหาทพบระหวางทาโครงงาน 62 เอกสารอางอง 64 ภาคผนวก ก การตดตงโปรแกรมทใชในการทาโครงงาน 65 ภาคผนวก ข การทดลองการทางานของโปรแกรมทใชในการทาโครงงาน 96 ประวตผแตง 111

Page 11: Build Automation Using Wireless Sensor Network

สารบญตาราง

ตารางท หนา 2-1 เปรยบเทยบระหวาง Zigbee Wi-Fi และ Bluetooth 7 3-1 รายละเอยดอปกรณ 22 3-2 รปแบบตาง ๆ ของการจดการระบบพลงงาน 23 3-3 ความสามารถในการวดสญญาณของ Sensor no. SHT11 (Sensirion) 24 3-4 ความสามารถในการสงสญญาณของ TmoteSky ทระดบความสงตาง ๆ กน 30 3-5 ความสามารถในการสงสญญาณของ TmoteSky เมอผานวสดตาง ๆ 31 3-6 ความสามารถในการสงสญญาณของ TmoteSky ทระยะตาง ๆ ภายในอาคาร 32 3-7 ความสามารถในการสงสญญาณของ TmoteSky ทระยะตาง ๆ ภายนอกอาคาร 33

Page 12: Build Automation Using Wireless Sensor Network

สารบญภาพ

ภาพท หนา 2-1 การแบงชวงความถตงแตระดบวทยจนถงระดบแสง 4 2-2 โครงสรางของภาษา NesC 9 2-3 การเชอมตอระหวาง Component 9 2-4 ตวอยางการพมพคาสงใน Notepad 15 2-5 ตวอยางการบนทกไฟล HTML 15 2-6 ตวอยางเวบทเขยนจากโคดตวอยาง 16 2-7 กลไกการทางานทวไปของเวบเพจ 20 2-8 กลไกการทางานของไฟล PHP 20 3-1 รายละเอยดอปกรณตาง ๆ ทตดตงบน TmoteSky 26 3-2 รายละเอยดอปกรณตาง ๆ ทตดตงบน TmoteInvent 26 3-3 การวาง TmoteSky ในรปแบบตาง ๆ 28 3-4 กราฟความแรงของสญญาณในการวาง TmoteSky ในรปแบบตาง 29 3-5 การวาง TmoteSky ทความสงตาง ๆ กน 29 3-6 รปแบบการวดคา RSSI เมอผานวสดตาง ๆ 31 3-7 รปแบบการวดคา RSSI ทระยะตาง ๆ 33 3-8 ภาพจาลองการสงสญญาณเชอมตอของ Tmote 34 4-1 กลองตนแบบ 36 4-2 บรรจภณฑสาหรบ TmoteSky 36 4-3 TmoteSky พรอมบรรจภณฑ 36 4-4 แหลงจายพลงงานทเลอกใช 37 4-5 อปกรณทใชในการตดตงเครอขายไรสาย 38 4-6 แผนผงการตดตงเซนเซอร 38 4-7 ตาแหนงการตดตงเซนเซอรหมายเลข 1 39 4-8 ตาแหนงการตดตงเซนเซอรหมายเลข 2 39 4-9 ตาแหนงการตดตงเซนเซอรหมายเลข 3 40 4-10 ตาแหนงการตดตงเซนเซอรหมายเลข 4 40

Page 13: Build Automation Using Wireless Sensor Network

สารบญภาพ (ตอ)

ภาพท หนา 4-11 ตาแหนงการตดตงเซนเซอรหมายเลข 5 41 4-12 ตาแหนงการตดตงเซนเซอรหมายเลข 6 41 4-13 ตาแหนงการตดตงเซนเซอรหมายเลข 7 และ 8 42

4-14 ตาแหนงการตดตงเซนเซอรหมายเลข 9 และ 10 42 4-15 ตาแหนงการตดตงเซนเซอรหมายเลข 11 43 4-16 ตาแหนงการตดตงเซนเซอรหมายเลข 12 43 4-17 ตาแหนงการตดตงเซนเซอรหมายเลข 13 44 4-18 ตาแหนงการตดตงเซนเซอรหมายเลข 14 44 4-19 ตาแหนงการตดตงเซนเซอรหมายเลข 15, 16 และ 17 45 5 5-1 Homepage http://mobile.ee.kmitnb.ac.th/ 48 5-2 หนาเมนหลก 49 5-3 เมน Admin 50 5-4 การเพมจานวนผใช 50 5-5 รายละเอยดของสมาชกทงหมด 51 5-6 การแกไขขอมลสมาชก 51 5-7 การลบขอมลสมาชก 52 5-8 การลอคอนเขาสฐานขอมล 52 5-9 เมน Realtime 53 5-10 เมน Static 54 5-11 การแสดงกราฟ 54 5-12 การแสดงผลแบบสถต 55 5-13 เมน Floor 3 55 5-14 เมน Floor 4 56 5-15 หนา contact_us.php 56 5-16 การจาลองการทางานของโปรแกรม J2ME บนโทรศพทมอถอ 57 5-17 การเชอมตอกบเซรฟเวอรบนโทรศพทมอถอ 57 5-18 การแสดงคาของแสงสวางและอณหภมของหองทเลอกไว 58

Page 14: Build Automation Using Wireless Sensor Network

สารบญภาพ (ตอ)

ภาพท หนา 5-19 การแสดงคาของเมน Allmote 58 5-20 การแสดงคาของเมน moteDisconnect 59 5-21 การแสดงคาของเมน WSNMAP 59 5-22 แสดงแผนทหอง Computer 2 60 5-23 การแสดงคาของเมน Manual 60 5-24 การแสดงคาของเมน Mote status 61 5.25 การแสดงคาของเมน Credit 61 ก-1 เรมตดตงโปรแกรม Cygwin 66 ก-2 ตดตงโปรแกรม Cygwin 66 ก-3 เลอกประเภทของโปรแกรมทตองการใชงาน 67 ก-4 เรมการ Install โปรแกรม Cygwin 67 ก-5 รอการตดตงโปรแกรม Cygwin 68 ก-6 ตดตงโปรแกรม J2SE Development Kit 5.0 68 ก-7 เลอกโฟลเดอรทตองการตดตงโปรแกรม J2SE Development Kit 5.0 69 ก-8 รอการตดตงโปรแกรม J2SE Development Kit 5.0 69 ก-9 เลอกโฟลเดอรทตองการตดตงโปรแกรม J2SE Runtime Environment 5.0 70 ก-10 เลอกเบราเซอรทตองการใชในการลงทะเบยนโปรแกรม 70 ก-11 รอการตดตงโปรแกรม J2SE Runtime Environment 5.0 71 ก-12 เสรจสนการตดตงโปรแกรม J2SE Runtime Environment 5.0 71 ก-13 รอการตดตงโปรแกรม 72 ก-14 เสรจสนการตดตงโปรแกรม Cygwin 72 ก-15 เรมตดตงโปรแกรม 73 ก-16 เลอกตาแหนงทจะตดตงโปรแกรม 73 ก-17 เลอก Service 74 ก-18 ระหวางการตดตง 74 ก-19 การตดตงเสรจ 75 ก-20 สแกนหา Ports ทจาเปน 75

Page 15: Build Automation Using Wireless Sensor Network

สารบญภาพ (ตอ)

ภาพท หนา ก-21 ตดตงสาเรจเขาส Control Panel 76 ก-22 XAMPP Control Panel 76 ก-23 ไฟล config.inc.php 77 ก-24 MySql Admin 77 ก-25 การเขาส phpMyAdmin 78 ก-26 Authentication Required 78 ก-27 phpMyAdmin 79 ก-28 สรางฐานขอมล 79 ก-29 สรางตาราง 80 ก-30 ตวอยางการกาหนดคาตาราง 80 ก-31 ตารางทงหมดในฐานขอมล tmote 81 ก-32 โครงสรางของตาราง tmote 81 ก-33 ขอมลในตาราง tmote 82 ก-34 การกาหนดสทธของ User 82 ก-35 Add a new User 83 ก-36 การกรอก Username และ Password 83 ก-37 กาหนดตารางท User สามารถใชงานได 84 ก-38 กาหนดการกระทาของ User ตอตารางนน 84 ก-39 เสรจสนการกาหนดสทธ 85 ก-40 ตวอยางการ Export ไฟล 85 ก-41 ตวอยางการ Import ไฟล 86 ก-42 ตวอยางโฟลเดอร xampp 86 ก-43 ตวอยางโฟลเดอร htdocs 87 ก-44 หนาแรกของการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1 88 ก-45 หนาแสดงขอตกลงอนญาตใชโปรแกรม easyeclipse-mobile-java-1.3.1.1 88 ก-46 โฟลเดอรทตองการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1 89 ก-47 รอการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1 89

Page 16: Build Automation Using Wireless Sensor Network

สารบญภาพ (ตอ)

ภาพท หนา ก-48 เสรจสนการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1 90 ก-49 หนาแรกของการตดตงโปรแกรม sun_java_wireless_toolkit-2_5_1 91 ก-50 หนาแสดงขอตกลงอนญาตใชโปรแกรม sun_java_wireless_toolkit-2_5_1 91 ก-51 เลอกตาแหนงทตองการตดตงโปรแกรม J2SE Development Kit 92 ก-52 เลอกตาแหนงทตองการตดตงโปรแกรม Sun Java Wireless Toolkit 92 ก-53 ทาการสรางชอโฟลเดอรโปรแกรมทจะทาการแสดงใน Start Menu Program 93 ก-54 หนาแจงเตอนการอพเดตเมอมโปรแกรมเวอรชนใหม 93 ก-55 เรมทาการตดตงโปรแกรม 94 ก-56 รอการตดตงโปรแกรม Sun Java Wireless Toolkit 94 ก-57 เสรจสนการตดตงโปรแกรม Sun Java Wireless Toolkit 95 ข-1 การตดตงโปรแกรม OscopeRssi 97 ข-2 การตดตงโปรแกรม OscopeRssi (ตอ) 98 ข-3 การตดตงโปรแกรม OscopeRssi (ตอ) 98 ข-4 การใชคาสง motelist 99 ข-5 การใชคาสง java net.tinyos.sf.SerialForwarder 99 ข-6 โปรแกรม SerialForwarder 99 ข-7 การใชคาสง java net.tinyos.oscope.oscilloscope 100 ข-8 รปตวอยางการวดสญญาณ 100 ข-9 ตวอยางคาทบนทกไดจากโปรแกรม OscopeRssi 101 ข-10 โฟลเดอรโปรแกรม DTSR 102 ข-11 แสดงไฟลตาง ๆ ในโปรแกรม DTSR 102 ข-12 เรมรนโปรแกรม 103 ข-13 เขาไปทโฟลเดอร DTSR 103 ข-14 คอมไพลโปรแกรม DTSR 103 ข-15 รายละเอยดการคอมไพล 104 ข-16 motelist 104 ข-17 การลงโปรแกรม DTSR บน Tmote 105

Page 17: Build Automation Using Wireless Sensor Network

สารบญภาพ (ตอ)

ภาพท หนา ข-18 เรมรนโปรแกรม Cygwin 106 ข-19 การทางานของโปรแกรม DCDB 106 ข-20 การทางานของโปรแกรม DCDB 106 ข-21 ไฟล Log Data ทไดจากโปรแกรม DCDB 107 ข-22 โปรแกรม Wireless Toolkit 108 ข-23 การสราง Project ใน Wireless Toolkit 108 ข-24 โปรแกรมเมอทาการสราง Project เสรจ 108 ข-25 เขาไปทโฟลเดอร C:\WTK2.5.1\apps\mobileWSN\src 109 ข-26 การ Buildโปรแกรม mobileWSN 109 ข-27 การจาลองการทางานของโปรแกรม mobileWSN 110

Page 18: Build Automation Using Wireless Sensor Network

บทท 1 บทนา

ในสภาวะทพลงงานเปนทรพยากรทจาเปนในการดารงชวตและกาลงขาดแคลนโดยเฉพาะในประเทศไทยทรฐบาลตองเสยงบประมาณหลายพนลานเพอซอพลงงานมาจากประเทศเพอนบาน ทาใหแนวความคดทจะผสมผสานระหวางเทคโนโลยททนสมยกบความตองการจะใชพลงงานภายใตพนฐานของความพอเพยงไดถอกาเนดขนภายใตชอระบบอาคารอจฉรยะโดยใชเครอขายเซนเซอรไรสาย (Building Automation System Using Wireless Sensor Network) โดยอาศยความสามารถของ TmoteSky มาใชเปนอปกรณในการสรางเครอขายทมเสถยรภาพ 1.1 วตถประสงค

1.1.1 เพอศกษาเทคโนโลยการสอสารแบบไรสายและนาไปประยกตใชใหเกดประสทธภาพสงสด 1.1.2 เพอศกษาและพฒนาโปรแกรมทใชสอสารระหวางเซนเซอรไรสาย (Wireless Sensor) โดยผานเครอขายไรสายและเครอขายอนเตอรเนต (Internet) 1.1.3 เพอออกแบบและสรางระบบอาคารอจฉรยะทสามารถรายงานสถานะและบนทกคาลงฐานขอมล โดยผานระบบเครอขายไรสายอนนาไปสการประหยดพลงงาน 1.2 ทฤษฏทเกยวของ ลกษณะของงานทมมากอน การสอสาร เปนปจจยสาคญอยางหนงในการพฒนาและสรางสรรคความเจรญกาวหนาใหกบประเทศ ยงในปจจบนซงเปนยคสมยทขาวสารเขามามบทบาทในการดาเนนชวต การใชงานอนเตอรเนต จงไดรบความนยมจากบคคลทกเพศทกวย ทาใหประสทธภาพของตวเทคโนโลยเปนสงสาคญทจะตองพฒนาใหสามารถรองรบและตอบสนองตอความตองการของผใชงานไดอยางเหมาะสม ระบบเครอขายไรสาย (Wireless Network) เปนอกหนงรปแบบของการสอสารทกาลงถกนามาใชอยางแพรหลายเพราะนอกจากจะสามารถลดปญหาเกยวกบการเดนสายสญญาณ และยงประหยดเวลาในการตดตงแลวผใชงานยงสามารถเขาถงไดโดยไมตองใชสายตออกดวย จงนบไดวาระบบเครอขายไรสายเปนการพฒนาไปอกระดบของการสอสารทเขามาทาทายระบบเครอขายท

Page 19: Build Automation Using Wireless Sensor Network

2

ใชสาย (Wired Network) ไดอยางนาจบตามอง ทงนเทคโนโลยชนดนไดถกนาเขามาประยกตใชงานในดานตาง ๆ ไมวาจะเปนทางดานการแพทยทนาเอาระบบไรสาย มาพฒนาใชรวมกบเซนเซอร ในการตดตามตวผปวยและแสดงสถานะอาการ เชน อตราการเตนของหวใจ เปนตน เพอใหเจาหนาทสามารถนาขอมลมาประกอบการรกษาไดมประสทธภาพมากขน ทางดานการวจยคนควา เชน การนาเซนเซอรแบบไรสาย มาใชในการศกษาการประทของภเขาไฟ ซงเปนความรวมมอกนระหวางนกวชาการดานธรณฟสกสและวทยาการคอมพวเตอร นอกจากจะประหยดงบประมาณแลว ยงสามารถเกบขอมลไดตลอด 24 ชวโมงไดโดยไมสนเปลองบคลากรอกดวย จากโครงการดงกลาวจะเหนไดวาเทคโนโลยระบบเครอขายไรสาย กาลงแทรกซมเขามามบทบาทตอการใชชวตประจาวนในรปแบบตาง ๆ จงเปนแรงบนดาลใจใหโครงการระบบอาคารอจฉรยะโดยใชเครอขายเซนเซอรไรสาย ถอกาเนดขนโดยใชหลกการของเครอขายไรสายแบบ Ad-hoc มาเปนสวนหนงของทฤษฏทใชประกอบการทาโครงการ ทงนทางนกศกษาไดนา TmoteSky ซงเปนเซนเซอรไรสายขนาดเลกชนดหนงเขามาใชเปนโหนดในการวจยโครงการ เพอเปนตวตรวจจบคาของแสง อณหภม จากนนจงนาไปแสดงผลบนเครองคอมพวเตอรหรอโทรศพทมอถอโดยใชการตดตอแบบไรสาย การทางานของ TmoteSky จะใช TinyOS ซงเปนระบบปฏบตการขนาดเลกทใชในเครอขายเซนเซอรไรสาย และระบบนสามารถพฒนาตวซอฟตแวร ไดโดยใชภาษา NesC ในสวนของการตดตอระหวาง TmoteSky โดยใชโปรโตคอลแบบ Zigbee ซงถกออกแบบมาเพอใชเปนเครอขายไรสายทใชพลงงานตาและมการสอสารแบบ Ad-hoc ทาใหสามารถเชอมตอโหนดไดมากสดถง 65,000 โหนดตอเครอขาย เปนการขยายพนทใชงานในอาคารใหครอบคลมยงขน โดยในสวนของการแสดงผลไดนาเอาเวบแอปพลเคชนมาใชเพอแสดงคาแบบเวลาจรง และแบบสถต นอกจากนยงไดมการนา GPRS หรอ EDGE เขามาใชในการรบ-สงขอมลระหวางโทรศพทมอถอกบฐานขอมล และแสดงผลผานหนาจอของโทรศพทมอถอโดยใช J2ME ซงเปนรปแบบหนงของจาวาททามาเพอใชงานบนอปกรณขนาดเลก ซงมทรพยากรจากดและมอปกรณภายในบางอยางทมความสามารถตา

1.3 วธการของโครงการ

1.3.1 ศกษาเทคโนโลยเครอขายไรสาย IEEE 802.15.4 (Zigbee) 1.3.2 ศกษาภาษาทางคอมพวเตอรทนามาใชในโครงงาน ไดแก NesC, J2ME, SQL และ Web

Application (HTML, PHP, Java Scrip) 1.3.3 ทดสอบหาประสทธภาพของเซนเซอร TmoteSky และประสทธภาพของเครอขาย

Page 20: Build Automation Using Wireless Sensor Network

3

1.3.4 สรางการเชอมตอระหวางเครอขายเซนเซอรกบฐานขอมลบนอนเตอรเนต และฐานขอมล กบโทรศพทมอถอเพอการแสดงผลบนเวบไซดและโทรศพทมอถอ 1.3.5 วเคราะหและแกไขขอผดพลาดทพบในการดาเนนโครงงาน 1.3.6 ทารายงานสรปผลการทาโครงงาน 1.4 ขอบเขตของโครงงาน

1.4.1 สามารถสรางระบบตรวจจบแบบไรสายโดยเชอมผานอนเตอรเนตและโทรศพทมอถอได 1.4.2 สามารถดคาทไดรบจากเซนเซอรไรสาย ไดทกท ทกเวลาผานเวบไซดและโทรศพทมอถอ 1.4.3 มความรความเขาใจในการสอสารแบบไรสาย รโครงสรางทางภาษาทนามาใชในการ ควบคมเซนเซอร และสามารถนาไปใชพฒนาเทคโนโลยใหม ๆ 1.4.4 ใชเซนเซอรในการตรวจจบ แสงและอณหภม 1.5 ประโยชนทคาดวาจะไดรบ 1.5.1 มความรความเขาใจในเทคโนโลยการสอสารแบบไรสาย 1.5.2 ไดเรยนรวธการออกแบบระบบอาคารอจฉรยะ (Building Automation System Using Wireless Sensor Network) 1.5.3 ไดศกษาและพฒนาโปรแกรมทใชในการตดตอกนระหวางเครอขาย 1.5.4 สามารถสรางฐานขอมลเพอเกบคาไปแสดงผลทงแบบเปนสถตและสถานะในปจจบน 1.5.5 มความสามารถในการสรางเวบไซดเพอการแสดงผลทงบนคอมพวเตอรและ โทรศพทมอถอ 1.5.6 ชวยในการประหยดพลงงานภายในตวอาคาร

Page 21: Build Automation Using Wireless Sensor Network

บทท 2 ทฤษฎทเกยวของ

2.1 เทคโนโลยไรสาย ในป 1857-1894 นกฟสกสชาวเยอรมน Heinrich Rudolph Hertz เปนผคนพบวา เสยง

ของมนษยอยระหวาง 20 เฮรต ถง 20 กโลเฮรต ทาใหคาวา เฮรต (Hertz) ถกนามาใชเปนหนวยใน มาตรวดของคลนวทยทมรอบในการสงตอวนาททตางกน โดยความถ (Frequency) ถกนยาม

วาเปนจานวนครงของคลนตอหนงหนวยเวลา และเราจะเรยกชวงของความถตาง ๆ วาแถบคลนแมเหลก ไฟฟา (Electromagnetic spectrum) โดยแบงเปนชวงทใชตงแตระดบวทยจนถงระดบแสง ดงแสดงในภาพท 2-1

ภาพท 2-1 การแบงชวงความถตงแตระดบวทยจนถงระดบแสง

ชวงของความถวทย หรอสงกวาเรยกวาความถแสง โดยเปน Ultraviolet, X-ray, และ

Gamma rays หรอสงกวา ขอมลแบบไรสายนนจะใชเปนสวนของชวงคลนความถวทย ซงอยระหวาง 800 กโลเฮรต ถง 5 กกะเฮรต แมวาขอมลจะถกระบความถไว ในแตละประเทศจะมการควบคมการใชความถ และมองคกรทดแลคอ FCC (Federal Communications Commission) ซงอยทอเมรกาทาหนาทควบคมระบบการสอสารแบบไรสายใหสามารถใชระหวางประเทศไดโดยมการจองความถให จงหมดปญหาเรองการใชความถทแตกตางกน

2.1.1 ความหมายของเทคโนโลยไรสาย เทคโนโลยไรสาย (Wireless) หมายถง การตดตอสอสารโดยไมใชสายและอปกรณ

สอสาร เครอขายแบบไรสาย (Wireless LAN) ถกพฒนาขนมาครงแรกในป 1980 โดยใชความถยาน

Page 22: Build Automation Using Wireless Sensor Network

5

900 เมกกะเฮรต (ISM Band) และดวยความทระบบนใชความถเดยวกบระบบโทรศพทแบบเซลลลาร ทาใหสามารถใชงานอปกรณเครองรบเครองสงไดพรอมกนทาใหสะดวกและประหยดใน

การพฒนาระบบเครอขาย แตกเปนทนาเสยดายเพราะเครอขายทใชความถนไมสามารถวางจาหนายได เนองจากบางประเทศสงวนยานความถไปใชกบระบบโทรศพทมอถอมนจงไมเปนทนยม ในป 1990 เครอขายไรสายยาน 2.4 กกะเฮรต ไดถกพฒนาขน เพราะความถยานนเปนความถทสงมาก พฒนาระบบเครองรบสงไดยาก ทาใหไมคอยมผนยมใช ประเทศตาง ๆ กยงไมไดจดสรรความถนไปใชงาน ทาใหอปกรณแบบไรสาย ทใชความถนมโอกาสเตบโตไดมากกวาระบบอน แตนนยงไมจบ เพราะมผผลตอปกรณไรสายหลายราย ตางพฒนาอปกรณของตนทาใหใชรวมกนไมไดจนเกดปญหาขนมาในป 1992 องคกรทชอวา IEEE (Institute of Electrical and Electronics Engineers) จงเขามาทาหนาทกาหนดมาตรฐานเครอขายแลนแบบไรสาย (Wireless LAN) แลวตงมาตรฐาน 802.11 เพอระบมาตรฐานอปกรณรนอน ๆ ออกมา มาตรฐานของเครอขายไรสายนนแบงไดเปน 3 กลมหลก ๆ ตามคลนความถทใชกน กลมแรก ยานความถ 2.4 กกะเฮรต (ไดรบความนยมสงทสด) กลมทสอง ยานความถ 5 กกะเฮรต กลมทสาม ใชแสงอนฟาเรดเพอการตดตอ ซงแตละประเภทมขอดและขอเสยตางกน ตามท IEEE LAN/MAN Standards Committee (IEEE 802) ไดกาหนดมาตรฐานการสอสารไวดงน

• IEEE 802.1 Higher layer LAN protocols • IEEE 802.2 Logical link control • IEEE 802.3 Ethernet • IEEE 802.4 Token bus (disbanded) • IEEE 802.5 Token Ring • IEEE 802.6 Metropolitan Area Networks (disbanded) • IEEE 802.7 Broadband LAN using Coaxial Cable (disbanded) • IEEE 802.8 Fiber Optic TAG (disbanded) • IEEE 802.9 Integrated Services LAN (disbanded) • IEEE 802.10 Interoperable LAN Security (disbanded) • IEEE 802.11 Wireless LAN (Wi-Fi certification) • IEEE 802.12 demand priority • IEEE 802.13 (not used)

Page 23: Build Automation Using Wireless Sensor Network

6

• IEEE 802.14 Cable modems (disbanded) • IEEE 802.15 Wireless PAN

o IEEE 802.15.1 (Bluetooth certification) o IEEE 802.15.4 (Zigbee certification)

• IEEE 802.16 Broadband Wireless Access (WiMAX certification) o IEEE 802.16e (Mobile) Broadband Wireless Access

• IEEE 802.17 Resilient packet ring • IEEE 802.18 Radio Regulatory TAG • IEEE 802.19 Coexistence TAG • IEEE 802.20 Mobile Broadband Wireless Access • IEEE 802.21 Media Independent Handoff • IEEE 802.22 Wireless Regional Area Network

2.2 IEEE 802.15.4 (Zigbee) Zigbee อยในกลมโปรโตคอลทเรยกวา PAN (Personal area network) ซงเปนการสอสารแบบไรสายในระยะสน เปนเทคโนโลยใหมทยงไมเปนทรจกในปจจบน แตเปนเทคโนโลยทมความนาสนใจและมอนาคตทสดใสซงจะเปนอปกรณไรสายยคตอไปทจะใชในงานอตสาหกรรม ชอ Zigbee มาจากรปแบบการบนทไมแนนอนของผงทบนระหวางผสมเกสรดอกไม ซงแสดงใหเหนถงโครงขายใยแมงมมมากมายทมองไมเหนของระบบไรสายทมอยจรง โดยมาตรฐานนถกจดระเบยบโดยกลมทเรยกวา Zigbee Alliance ซงมสมาชกวา 150 องคกรทวโลกและมาตรฐานแรกทออกมาคอ Zigbee 1.0 เมอ 14 ธนวาคม 2004 เรยกวา "Zigbee 2004" โดยรนปจจบนไดมการพฒนาเปน Zigbee 2007 ซงเรยกวา “PRO” แตรน 2004/2006 กยงจะสามารถใชในเครอขาย 2007 ได Zigbee ถกออกแบบมาเพอใชเปนเครอขายไรสายทใชพลงงานตา เชน เครอขายไรสายในการเฝาระวง ควบคมแสงสวาง แจงเตอนความปลอดภย ตรวจจบความเคลอนไหว ตรวจจบควนและตดไฟ เปนตน โดยใชความถยานวทยาศาสตรและการแพทย (ISM) โดยในยโรปจะใช 868 เมกกะเฮรต ในอเมรกาใช 915 เมกกะเฮรต และทอน 2.4 กกะเฮรต โดยเปนเทคโนโลยทออกแบบมาใหใชงานไดงาย และราคาถกกวาเทคโนโลยอนในกลม WPANs เชน Bluetooth โดย Zigbee ออกแบบมาเปน Low-speed Ad-hoc Network ซงจะสอสารแบบ Ac-hoc สามารถเชอมตอระบบไดทง Static, Dynamic, Star และ Mesh มโหนดไดมากถง 65,000 โหนดตอเครอขาย โดยมความเรวในการสงขอมลตาเนองจากตองการประหยดพลงงาน และใชโคด DSSS (Direct Sequence Spread Spectrum)

Page 24: Build Automation Using Wireless Sensor Network

7

มการหลกเลยงการชนกนของขอมลแบบ CSMA/CA มอดดเลตแบบ BPSK ใน 868 (868.0–868.6 เมกกะเฮรต) และ 915 เมกกะเฮรต (902-928 เมกกะเฮรต) และใช QPSK 2 บตตอสญลกษณ สาหรบ 2.4 กกะเฮรต (2.400–2.484 กกะเฮรต) ความเรวในการสงขอมล 250 กโลบตตอวนาท ตอชองสญญาณสาหรบ 2.4 กกะเฮรต 40 กโลบตตอวนาท ตอชองสญญาณสาหรบ 915 เมกกะเฮรต และ 20 กโลบตตอวนาท ตอชองสญญาณสาหรบ 868 เมกกะเฮรต ระยะในการสอสารขอมล 10-75 เมตร ขนอยกบสภาพแวดลอม โดยมกาลงสงสงสด 0 dBm (1 มลลวตต) การเขารหส 128-bit Advanced Encryption Standard (AES) encryption ทาใหมความปลอดภยในการเชอมตอ

ตารางท 2-1 เปรยบเทยบระหวาง Zigbee (802.15.4), Wi-Fi (802.11b), Bluetooth (802.15.1)

Standard Zigbee Wi-Fi Bluetooth Transmission Range

(meters) 1-100 1-100 1-10

Battery Life (days) 100-1000 0.5-5.0 1-7 Network Size (# of nodes)

> 64000 32 7

Application Monitoring & Control

Web, Email, Video Cable Replacement

Stack Size (KB) 4-32 1000 250 Throughput (kb/s) 20-250 11000 720

ทมา: [11], [13] ในระบบอาคารอจฉรยะนไดมการนา TmoteSky, TmoteInvent ซงใชเทคโนโลย Zigbee ในการสอสารเพอนามาสรางเครอขายแบบ Ad-hoc โดย Zigbee ทาใหเซนเซอรสามารถใชงานไดนานโดยทประหยดพลงงานและความเรวในการสอสารตา

2.3 TinyOS TinyOS เปนระบบปฏบตการขนาดเลกทใชในเครอขายเซนเซอรไรสาย โดยมตนกาเนดมาจากการพฒนาของนกวจยท University of California (UC) at Berkeley ระบบ TinyOS มความสามารถในการจดการงาน (Task management) ดวยการจดลาดบแบบ FIFO (First In First Out) การสอสารแบบไรสายแบบ Ad-hoc และรองรบการทางานแบบพรอมกน มระบบตอบสนองตอเหตการณ

Page 25: Build Automation Using Wireless Sensor Network

8

(Event-Based Execution) จงรองรบการทางานหลายแอปพลเคชนโดยไมจาเปนตองใชหนวยความจาขนาดใหญ ขอดอกอยางหนงของระบบ TinyOS คอเปนลกษณะของซอฟตแวรแบบ Open source นอกจากนยงใชหนวยความจานอยและใชหนวยประมวลผลกลาง ทไมตองมคณภาพสงมากนก ในเครอขายไวเลสไรสายระบบ TinyOS จะทางานอยบนเซนเซอรขนาดเลก (Mote) โดยจะคอยควบคมการใชพลงงาน การรบสงขอมลและจดการกบขอมลท Mote รบมา ในการสงขอมลของแตละ Mote จะเปนลกษณะ Multi-Hop คอจะสงขอมลแบบแพคเกตจาก Mote หนงไปสอก Mote หนง ซงการสงขอมลในลกษณะนทาใหประหยดพลงงานและไดขอมลทมประสทธภาพ

2.4 NesC NesC ซงมลกษณะแบบ OOP (Object Oriented Programming) รองรบการเขยนโปรแกรมแบบ Event Driven คอทางานเมอมเหตการณเกดขน และ Component-based Model ซงจะชวยใหสามารถพฒนาโปรแกรมแบบทางานพรอมกน และมการประมวลผลในตวเอง โดยการทางานแบบนชวยใหแอปพลเคชนลดจานวนการสงขอมล ทาใหประหยดพลงงานเนองจากจะมการประมวลผลทตวของ Mote กอน แลวจงจะทาการสงขอมลไปให Mote ถดไป แทนทจะให Mote แตละตวสงขอมลไปใหคอมพวเตอรทาการประมวลผลทเดยวซงทาใหเสยเวลา ในภาษา NesC จะแบงออกเปน 2.4.1 Component Configuration เหมอนกบเปนโครงสรางของโปรแกรม โดยในสวนนบอกวา ตองใช Component อะไรบาง และ Component แตละตวเชอมตอกนอยางไร Module เปนสวนของโคดสาหรบการทางาน 2.4.2 Interface การเชอมตอ จะม 2 หนาท 2.4.2.1 Uses คอ การขอเชอมตอ 2.4.2.2 Provider คอ การให Component อนมาเชอมตอได Command เปนการใหบรการ Component อน ๆ Event การรองขอแจงเตอนเหตการณ

Page 26: Build Automation Using Wireless Sensor Network

9

ภาพท 2-2 โครงสรางของภาษา NesC

2.4.3 Application จะเกดจากการนา Component ตาง ๆ มาเชอมตอกนผาน Interface ดงภาพ

ภาพท 2-3 การเชอมตอระหวาง Component

2.5 จาวา

ภาษาจาวาถกคดคนโดยบรษท Sun Microsystems ในป 1991 โดยมวตถประสงคเพอสรางผลตภณฑอเลกทรอนกสสาหรบผบรโภคใหใชงานงายและมคาใชจายตา ไมมขอผดพลาด และสามารถใชกบเครองใด ๆ กได โดยจดเดนของภาษานคอการเขยนโคดเพยงครงเดยวแลวสามารถนาไปใชไดบนทกระบบปฏบตการ ทาใหภาษาจาวาไดรบความนยมอยางแพรหลาย และมความ

Page 27: Build Automation Using Wireless Sensor Network

10

หลากหลายของรปแบบในการเลอกใชงาน เชน J2SE ทถกพฒนามาใชงานในคอมพวเตอรทวไป J2EE ทมเปาหมายสาหรบใชงานในระบบใหญ ๆ ซงในการเลอกใชชนดของจาวาควรเลอกโดยพจารณาจากความเหมาะสมกบทรพยากรของอปกรณ การพฒนาการในชวงเวลาตาง ๆ ป 1991 ทาการวจยเพอพฒนาซอฟตแวรทใชควบคมอปกรณอเลกทรอนกสขนาดเลก ซงไดผลลพธทสาคญคอ ภาษาโอค (Oak) ป 1993 ภาษาโอคไดถกปรบปรงใหมเพอใชในการสรางเวบแอปพลเคชน พรอมกบสราง เวบเบราเซอร ป 1995 บรษทซนไดเปดตวภาษาจาวา (ภาษาโอคเดม) พรอมกบเบราเซอรทรองรบภาษาน ชอวา Hot Java และไดรบการสนบสนนจากบรษทใหญทง Netscape, Microsoft และ IBM จากนนบรษทจงเรมแจกจาย JDK (Java Development Kit) ซงเปนชดพฒนาโปรแกรมภาษาจาวาในอนเตอรเนต ในปรญญานพนธฉบบนจะนาเสนอเฉพาะจาวาสวนทเกยวของกบการทาโครงงานอนไดแก J2SE, J2ME และ JDBC 2.5.1 J2SE (Java 2 Standard Edition) มเปาหมายสาหรบการใชพฒนาแอปพลเคชน บนเครองคอมพวเตอรทวไปซงเปนแบบ Standalone หรอสราง Applet โดยสมยกอนมชอเรยกวา JDK 1.1 ซงกคอ J2SE ใน Java 2 นนเอง โดยจะถอวา J2SE เปนแกนของจาวาในปจจบนซงมความเปนมาตรฐานสงกได คณสมบตสาคญของ Java 2 Standard Edition คอ สามารถทางานครอบคลมตงแตระดบผใชจนถงระดบเซรฟเวอร กลาวคอจากคอมพวเตอรสวนบคคล ถงคอมพวเตอรระดบสง ผพฒนาหรอโปรแกรมเมอรใชเวลาในการพฒนานอยลง สนบสนน XML, COM, SSL, Kerberos, LDAP และ Corba อกดวย 2.5.2 J2ME (Java 2 Micro Edition) เปาหมายสาหรบใชงานบนอปกรณขนาดเลกเชน PDAs, Mobile Phone โดยตดฟงกชนทไมจาเปนออกไปเพอใหสามารถทางานไดในสภาวะทมทรพยากรจากด โดยในแตละรนของจาวา นนกจะม Virtual Machine เปนของตวเองซงทตองแตกตางกนกเพราะเพอรองรบงานคนละแบบคนละขนาดนนเอง

Page 28: Build Automation Using Wireless Sensor Network

11

ในแตละรนของจาวาจะกาหนดสวนประกอบหลก ๆ ซงม 3 สวนคอ - Java Virtual Machine ซงจะอยในตวอปกรณ - Libraries และ APIs สาหรบอปกรณแตละชนด - Development tools และ Device Configurations โดยใน J2ME ไดแบงกลมเปาหมายของอปกรณทจะสามารถใชเทคโนโลยของ J2ME ออกเปน 2 กลมคอ

- Personal, mobile, connected information devices ไดแกพวก Cell phone, pager หรอ Organizer ซงเปนอปกรณทมรปแบบของ user interface งาย ๆ มหนวยความจา (Memory) ประมาณ 128 - 512 กโลไบต และใชแบนดวธ ในการเชอมตอเครอขายตา โดยการเชอมตอเครอขายสวนใหญของอปกรณในกลมนมกไมไดอยใน TCP/IP protocol suite - Shared, fixed, connected information devices ไดแกพวก Set-top boxes, Internet TVs, Internet-enabled screenphones, High-end communicators and carentertainment/navigation systems ซงอปกรณพวกนมกม User interface ขนาดใหญ หนวยความจาประมาณ 2 - 16 เมกกะบต และมแบนดวธสงในการเชอมตอกบเครอขาย TCP/IP เทคโนโลยอน ๆ ทเกยวของกบ J2ME - Personal Java เปนสวนหนงของ J2SE ใชสาหรบโนตบคหรอพดเอ โดยปจจบนกาลงจะถกเปลยนใหเปน Personal Profile อยใน J2ME - Embedded Java คอจาวาสาหรบ Real time application - Java Card คอ จาวาสาหรบ Smart Card โครงสรางของ J2ME จะแบงออกเปน 3 Layers ซงถกสรางบนระบบของแตละอปกรณ Layer 1 : Java Virtual Machine Layer เปน Layer สาหรบการสราง Java Virtual machine ซงตองปรบไปตามระบบปฏบตการของอปกรณแตละชนดและ support แตละ J2ME configuration จะเหนวา Virtual Machine สาหรบ J2ME กคอ CVM และ KVM Layer 2 : Configuration Layer J2ME Configuration จะระบตว class libraries ตามกลมของชนดอปกรณ ภายใตพนฐานความตองการของหนวยความจา และ Processing Power Configuration ของ J2ME ม 2 แบบคอ CDC (Connected Device Configuration) และ CLDC (Connected Limited Device Configuration)

Page 29: Build Automation Using Wireless Sensor Network

12

Layer 3 : Profile Layer เปน Layer ทถกสรางไวเหนอ Configuration โดยไดนยาม Class Libraries ตาง ๆ เอาไวเพอสาหรบ Market Segment แตละแบบตาง ๆ กน ตวอยางของ Profile ใน Layer นกเชน PDAP, MIDP, Foundation Profile และ Personal Profile เปนตน การนามาใชงานรวมกบโครงงานจดประสงคหลกของโครงงาน คอการพฒนาอปกรณไวเลสเซนเซอรใหมการใชงานทงายและสะดวกสบายมากขนโดยการนาอปกรณไวเลสเซนเซอร มาใชงานรวมกบโทรศพทมอถอ ซงเปนอปกรณทในปจจบนเรยกไดวาเปนอปกรณขนพนฐานของชวตประจาวนเลยทเดยว ซงการพฒนานทาใหเกดความสะดวกในการใชงานมากขน โดยในการสงงานหรอการอานคาสถานะของไวเลสเซนเซอรในปจจบนตองทาการเชอมตอเครองคอมพวเตอรหรอโนตบค แตกมขนาดใหญหรอขาดความสะดวกในการพกพา แตถาเราพฒนาใหมการตดตอผานอปกรณมอถอบนแอปพลเคชน J2ME จะทาใหสะดวกและงายตอการใชงานในรปแบบตาง ๆ ทเราตองการได

2.5.3 JDBC (JAVA Database Connectivity) JAVA Database Connectivity เปนโปรแกรมประยกตแบบอนเตอรเฟซซงมขอกาหนดสาหรบการตดตอกบโปรแกรมทเขยนดวยภาษา JAVA ไปยงขอมลในฐานขอมลทาใหสามารถใชคาสงดวยภาษา SQL (Structure Query Language) แลวสงไปยงโปรแกรมเพอจดการฐานขอมล จากนนจงสงผลลพธผานตวอนเตอรเฟซ JDBC มอนเตอรเฟซ 2 ระดบคอ อนเตอรเฟซหลกใช API ซงใชการตดตอกบฐานขอมลแตละประเภทดวย Driver และ JDBC network driver เมอโปรแกรมจาวาทางานบนเครอขาย JDBC Driver เปนขอกาหนดของ API (Application Programming Interface) สรางขนเพอใหนกพฒนาโปรแกรม สามารถเขยนโปรแกรมตดตอกบระบบจดการฐานขอมลชนดตาง ๆ ได โดย JDBC 1.0 ซงเปนเวอรชนแรกจะเปนชดคาสงในแพคเกจของ java.sql สวน JDBC 2.0 และ JDBC 3.0 เปนเวอรชนใหมทพฒนาขนเพอใชรวมไวใน JDK 1.4

JDBC API เปนขอกาหนดรปแบบของคาสงทใหนกพฒนาโปรแกรมสามารถตดตอกบระบบจดการฐานขอมล (DBMS) ไดโดยมรปแบบคาสงเดยวกน จงเปนเสมอนเครองมอในการพฒนา Database Application ในการเขยนโคดโปรแกรมภาษาจาวา ซง JDBC สามารถตดตอกบฐานขอมลไดเกอบทกประเภท เชน Sysbase, Oracle, MS SQL ,Informix, Access, MySQL

Page 30: Build Automation Using Wireless Sensor Network

13

2.5.3.1 ขอดของ JDBC - มความหลากหลายในการใชงานกบระบบปฏบตการ

- ใชงานงาย การตงคาไมยงยาก - สามารถทางานรวมกบภาษาจาวาไดเปนอยางด เพราะ Driver ทเขยนขนนนสวนมากจะพฒนาจากภาษาจาวาและมการคอมไพลเปน class file ทาใหใชงานงาย - สามารถตดตอฐานขอมลไดเกอบทกประเภท - ไฟล Driver มขนาดเลกและ Driver แตละตวมมาตรฐานใกลเคยงกน - สามารถใชงานไดทงสถาปตยกรรม แบบ Two-Tier และ Three-Tier - เปน Low-level Interface และสามารถใช High-level interface ดวยถาตองการ

- การใชงานจะเปนเชง Object-Oriented 2.5.3.2 การทางานทสาคญของ JDBC - ทาการตดตอกบฐานขอมล - สงคาสง SQL ไปยงฐานขอมล - รบผลลพธจากการใชคาสง SQL แลวทาการประมวลผล 2.5.3.3 ลกษณะทสาคญของ JDBC JDBC เปน Low-level Interface สามารถเรยกใชคาสง SQL ไดโดยตรงและมประสทธภาพ มขนาดเลก และงายตอการใชกวาตวตดตอฐานขอมลชนดอน ๆ ซงไดมออกแบบสาหรบใชงานแบบ High-Level Interface ดวย โดย High-level API ของ JDBC ทถกพฒนาซงมขอแตกตาง ดงน

- JDBC ตองการคาสง SQL ทจะทาการสงเปน String ไปยง Method ของภาษาจาวาทาใหโปรแกรมเมอรสามารถใชตวแปรในการรบสงคาสง SQL ได

- มการแปลง Relational Database Table ไปเปน Java Class ซงเรยกวา Object/Relational ซงแตละแถวของ Table จะถกแปลงไปเปน Instant ของ Class และแตละ Column จะเปนเหมอน Attribute ของ Class ซงโปรแกรมเมอร สามารถดาเนนการตาง ๆ คลายวา Table เปน Class หนง ในจาวา

Page 31: Build Automation Using Wireless Sensor Network

14

2.6 Web Application 2.6.1 HTML (Hyper Text Makeup Language) HTML ถกพฒนาขนโดยองคกรชอ World Wide Web Consortium หรอ W3C ซงใชแมแบบมาจากภาษา SGML (Standard Generalized Markup Language) แตตดความสามารถบางสวนออกไปเพอใหงายตอการทาความเขาใจ 2.6.1.1 ประโยชนของ HTML - ชวยใหสามารถเผยแพรเอกสารขอมลตาง ๆ ไดอยางไมจากดในระบบของเครองหรอระบบของ OS แคเพยงมเบราเซอรทสามารถอาน File format HTML ไดกจะสามารถเปดไฟลเอกสารทตองการเผยแพรอานไดทนท - สามารถทางานไดแมแตในระบบปฏบตการ Unix ท Run ใน Text Mode กสามารถอานได 2.6.1.2 โครงสรางภาษาของ HTML <HTML> //Tag เปดของภาษา HTML <HEAD> <TITLE> :: Building Automation Using WSN</TITLE> </HEAD> //สวนหวของ HTML <BODY> //สามารถใสรายละเอยดตางๆหรอนา code PHP มาแทรกได </BODY> </HTML> //Tag ปดของ HTML 2.6.1.3 การสรางไฟล HTML การสรางไฟล HTML สามารถใชโปรแกรมประเภท Text editor ใด ๆ กได เชน Notepad หรอโปรแกรม Edit ใน DOS ซงสามารถจดเกบไฟลเปนตวอกษรลวน ๆ เมอพมพ Source code ของไฟลลงใน Text editor เรยบรอยแลวใหสงบนทกไฟลแลวกาหนดนามสกลเปน .html หรอ .htm (สาหรบบางระบบปฏบตการ) 2.6.1.4 ขนตอนการสรางเวบโดยใช HTML ขนตอนท 1: พมพโคดลงในโปรแกรม Text editor

Page 32: Build Automation Using Wireless Sensor Network

15

ภาพท 2-4 ตวอยางการพมพคาสงใน Note Pad ขนตอนท 2: บนทกงานทสรางโดยกาหนดนามสกลไฟลเปน .html หรอ .htm

ภาพท 2-5 ตวอยางการบนทกไฟล HTML

ขนตอนท 3: การดเวบใหเขาไปสถานท ๆ เกบไฟลนนแลวเปดด

Page 33: Build Automation Using Wireless Sensor Network

16

ภาพท 2-6 ตวอยางเวบทเขยนจากโคดตวอยาง

2.6.2 Java Script ถกพฒนาขนเพอตอบสนองความตองการในการสรางเวบเพจ (Webpage) ในระดบทสงขนไป เนองจากความสามารถของ HTML มอยในขอบเขตทจากด จงไมสามารถใชงานในขนทสงกวาได ซงนอกจาก Java Script จะชวยเพมความนาสนใจใหเวบแลวยงสามารถสงงานเบราเซอรไดตามตองการอกดวย โดยตวอยางการใชงานของ Java Script เชน การทาอกษรวง การสรางเครองคดเลข เกมสหรอปฏทน เปนตน 2.6.2.1 การใชงาน Java Script การใชงาน Java Script จะตองใสโคดลงไประหวางคาสง <SCRIPT> และ </SCRIPT> ซงเปนคาสงภาษา HTML ทใชในการแนบสครปตภาษาตาง ๆ ไมวาจะเปน ภาษาจาวา Script, VB Script เปนตน โดยในการระบชอของภาษาทใชนน จะกาหนดผาน Attribute Language เชน <SCRIPT LANGUAGE="javascript"> โคดคาสง ภาษา Java Script .... </SCRIPT> นอกจากนสามารถกาหนดเวอรชนของ Java Script ลงไปเพอใหเบราเซอรทราบวาใชคาสง Java Script เวอรชนอะไร เชน <SCRIPT LANGUAGE="javascript1.1">

Page 34: Build Automation Using Wireless Sensor Network

17

ในกรณทเบราเซอรไมสนบสนน Java Script อาจทาใหเบราเซอรเขาใจวาคาสงทอยภายในคาสง <SCRIPT> และ </SCRIPT> เปนคาสงภาษา HTML จงควรจะใส หมายเหต (Comment) ของภาษา HTML ลงไประหวางคาสงภาษา Java Script เพอใหสามารถแสดงผลไดถกตอง ดงน <SCRIPT LANGUAGE="javascript"> <!-- โคดคาสง ภาษา Java Script .... --> </SCRIPT> เนองจาก Java Script นนเปนภาษาทสามารถใสลงไปในสวนใดของ HTML กได แตโดยปกตจะนยมใสไวระหวางคาสง <HEAD> ...... </HEAD> เพอทคาสงถกเรยกขนมากอนเปนอนดบแรกตวอยางเชน <HEAD> <script language="javascript"> คาสงภาษา Java Script ... </script> </HEAD> หรอสามารถแทรก Java Script ลงไปใน HTML TAG ผานทาง Event ทสนบสนน TAG นน ๆ กได เชน <IMG src="ชอไฟลรปภาพ.gif" OnMouseOver="คาสง Java Script;"> นอกจากน Java Script ทงหมด (ตงแตคาสง <script> ...ถง </script>) ยงนา ไปสรางเปนไฟลใหมโดยบนทกเปนนามสกล .js แลวใชคาสงผนวกไฟล .js นนขนมาใชงาน โดยใชคาสง <SCRIPT LANGUAGE="javascript1.1" src="ชอไฟล.js"></SCRIPT> ซงการใชวธนทาใหสามารถนาเอา Java Script ไปใชงานในเวบเพจตาง ๆ ได โดยทไมตองเขยนใหมทกครง 2.6.2.2 ขอดของ Java Script - ชดเชยขอจากดในสวนท HTML ทาไมได

Page 35: Build Automation Using Wireless Sensor Network

18

- ทาใหเวบเพจมลกเลนไมนาเบอ - สงงานเบราเซอรไดตามตองการ 2.6.3 SQL (Structured Query Language) จากเอกสารของ ดร.เอดการ เอฟ. คอดด (Dr. Edgar Frank Codd) ซงเผยแพรใน นตยสาร Association for Computing Machinery: ACM ป1970 ไดออกแบบ Relational Model โดยอางองทฤษฏ Set ทางคณตศาสตรซงสามารถแกไขปญหา Data Redundancy และ Data Inconsistency ไดทาใหกลายเปนผลงานทยอมรบทวโลกสาหรบระบบการจดการฐานขอมลในปจจบน ตอมาในป ค.ศ. 1970 ณ ศนยพฒนาคอมพวเตอรซานโฮเซของไอบเอมไดวจยและพฒนาระบบฐานขอมลทเรยกวา System R ขนตามแบบจาลองของคอดด โดยใหระบบภายในใชชอวาภาษาสอบถามเชงโครงสรางภาษาองกฤษ หรอ ซเควล (Structured English Query Language: SEQUEL) ซงภายหลงถกเปลยนชอมาเปน SQL เนองจากชอซเควล (SEQUEL) ซากบชอเครองหมายการคาของบรษทผลตเครองบนฮอกเกอร-ซดเดลย (Hawker-Siddeley) ของสหราชอาณาจกร ถงแมวา SQL พฒนามาจากแนวความคดของ ดร.คอดด แตการพฒนาทงหมดไมไดมาจาก ดร.คอดด แตพฒนาจาก โดนลด ด. แชมเบอรลน (Donald D. Chamberlin) และ เรยมอนด เอฟ. บอยซ (Raymond F. Boyce) จากไอบเอม ซงเปนผททาให SQL เปนทนยมมากขน 2.6.3.1 วตถประสงคของการใชงาน SQL - สรางฐานขอมลและโครงสราง Relation - สนบสนนงานจดการฐานขอมลพนฐาน - สนบสนนการคนหาขอมลและการแปลงขอมล 2.6.3.2 การแบงกลมคาสงของ SQL SQL สามารถแบงคาสงออกเปน 4 กลม คอ - Data Manipulate (DML) เปนคาสงจดการขอมล ไดแก INSERT, UPDATE, DELETE, ROLLBACK, COMMIT - Data Definition (DDL) เปนคาสงจดการกบไฟลในฐานขอมล ไดแก CREATE, ALTER, DROP - Query เปนคาสงการเรยกดขอมล คอ SELECT - Data Control เปนคาสงจดการความปลอดภย 2.6.3.3 ขอดของการใชฐานขอมล - แอปพลเคชนไมขนกบขอมล คอฐานขอมลจะถกออกแบบใหมโครงสรางแบบระดบชน ซงทาใหการเปลยนแปลงทเกดขนกบระดบหนงจะไมสงผลกระทบตอระดบอน ๆ

Page 36: Build Automation Using Wireless Sensor Network

19

- ขอมลทเหนคอขอมลทถกตองแล ว - ใชขอมลรวมกนได เพราะขอมลทงหมดจะถกรวบรวมมาเกบไวดวยกนอยางเปนระบบ - มกลไกการดแลขอมลพรอมกนทดกวา - มความปลอดภยสง สามารถควบคมสทธในการเขาถงขอมลได - เรยกดขอมลไดงายและเปนมาตรฐาน - โอกาสทจะสญเสยขอมลมนอยมาก หากฐานขอมลหยดทางานจะมกลไกทสามารถชวยกขอมลคนมาไดอยางรวดเรวซงมชอวา Recovery System (แตจะมในฐานขอมลบางตวเทานน) 2.6.3.4 การนามาใชงานรวมกบโครงงาน ระบบจดการฐานขอมลเปนระบบทใชจดเกบขอมลตาง ๆ ทเราตองการ ซงในโครงงานนในการเกบคาและแสดงผลจะมการเกบคาและการแสดงผลแบบเวลาจรง (Real Time) ทาใหการอานขอมลและการจดเกบขอมลทาไดลาบาก เราจงใช SQL เขามาชวยในการจดการขอมลตาง ๆ ทรบคาเขามาทาใหสามารถเลอกและจดการขอมลตางไดอยางสะดวกและยงสามารถนาฐานขอมลมาเปนหลกฐานอางองในการใชงานตาง ๆ หรอนามาวเคราะหความเปนไปไดหรอความนาจะเปนในระบบทเรากาลงศกษาอยไดอกดวย 2.6.4 PHP (PHP Hypertext Preprocessor หรอ Personal Home Page) ภาษา PHP ถกพฒนาขนในป 1994 โดย Rasmus Lerdorf โดยมจดเรมตนจากความตองการทจะบนทกขอมลของผทเขามาเยยมชมโฮมเพจสวนตวของเขาซง PHP ไดแนวคดมาจากการเขยนโปรแกรมดวยภาษา C, Java และ Pearl หลงจากนน Lerdorf ไดเรมแจกโคดออกไป ตอมาในป 1995 เขาไดเพมความสามารถในการรบขอมลจาก HTML และตดตอกบฐานขอมล MySQL จนกระทงในป 1997 จงเปดใหผสนใจเขารวมในการพฒนาเพมอกสองคนคอ Zeev Suraski และ Andi Gutmans ซงไดพฒนาโคดใหมใหดขนในหลาย ๆ ดานและแกไขขอบกพรองรวมทงเพมประสทธภาพและเพมเครองมอตาง ๆ ใหมากขนอกดวย 2.6.4.1 การทางานของเวบเพจและ PHP การทางานของเวบเพจทวไปทเปน HTML เมอมการเปดโปรแกรมเวบเบราเซอร โปรแกรมจะรองขอไปยงเวบเซรฟเวอรซงจะสงไฟลเวบเพจ HTML กลบมาแสดงผลเวบเบราเซอร ของผใชงาน แตสาหรบไฟลเวบเพจทใชภาษา PHP รวมอยดวย โปรแกรมเวบเบราเซอรจะรองขอไฟล PHP ไปยงเวบเซรฟเวอรซงจะเรยก PHP Engine ขนมาแปลไฟล PHP และตดตอกบ

Page 37: Build Automation Using Wireless Sensor Network

20

ฐานขอมล แลวจงสงผลลพธทไดจากการประมวลผลและแปลเปนภาษา HTML กลบไปยงเวบ เบราเซอรเพอใหสามารถนาไปใชงานตอไป

ภาพท 2-7 กลไกการทางานของเวบเพจทวไป

ภาพท 2-8 กลไกการทางานของไฟล PHP 2.6.4.2 ความสามารถของ PHP - สรางการโตตอบหรอรบสงขอมลกบผใชได - สามารถแทรกโคดลงไปใน HTML ไดงายและทาใหมความสามารถเพมขน

Page 38: Build Automation Using Wireless Sensor Network

21

- มความสามารถในการจดการกบตวแปรหลายประเภท - สนบสนนการตดตอกบโปรโตคอล (Protocol) ไดหลากหลาย และโตตอบแบบ Inter Active ผานโปรโตคอลอน ๆ ได - ทางานกบฮารดแวรไดทกระดบ - มความสามารถในการตดตอและจดการกบฐานขอมล 2.6.4.3 ขอดของ PHP - ดาวนโหลดมาใชงานไดฟรจากอนเตอรเนต - ใชงานไดทกระบบปฏบตการ เชน UNIX, Windows, Linux - ใชรวมกบคาสง XML ได - จดการกบตวอกษรและรปภาพไดอยางมประสทธภาพ - เขาใจงายหากมพนฐานภาษา Pearl หรอ ภาษา C

Page 39: Build Automation Using Wireless Sensor Network

บทท 3 ศกษาและทดสอบประสทธภาพของเซนเซอรโหนด

3.1 อปกรณพนฐานทใชในการทาโครงงาน 3.1.1 TmoteSky คอ อปกรณไรสายขนาดเลกรนลาสดทถกพฒนาโดยใชพลงงานตา ผลตมาเพอใชในระบบเซนเซอรเนตเวรค ระบบเฝาระวง และเปนตนแบบอปกรณทมความรวดเรวในการทางานในขณะทใชพลงงานตา โดยจดเดนของ TmoteSky คอ - เปนอปกรณทใชมาตรฐาน IEEE 802.15.4 (Zigbee certification) - ทางานท 2.4 GHz โดยมอตราการรบ-สงขอมลท 250 kbps - ใชไมโครคอนโทรลเลอร (Microcontroller) รน MSP430 ซงเปนไมโครคอนโทรลเลอร 16 บต พลงงานตาจากบรษท Texas - มการใสเสาอากาศไวในแผงวงจรโดยมระยะการรบสญญาณสงสดท 125 เมตร - มเซนเซอรภายในแผงวงจร 3 ชนด คอ ความชน อณหภม และแสง - มการใชพลงงานตามากเมอเทยบกบอปกรณประเภทเดยวกน - ในขณะทไมมการทางานตวอปกรณจะเขาสสภาวะ sleep และเมอมการเรมทางานจะกลบสสภาวะปรกตไดทเวลานอยกวา 6 Sμ ทาใหทางานไดรวดเรวและประหยดพลงงาน - มการเขารหสเพอความปลอดภยในการสงขอมลผาน Link Layer - สามารถทาการโปรแกรมหรอสงขอมลผาน USB port ทาใหสะดวกในการใชงาน 3.1.1.1รายละเอยดอปกรณ (Device Specification) ตารางท 3-1 รายละเอยดอปกรณ

BUS 8 MHz RAM 10 kB Program Space 48 kB External Flash 1024 kB Serial Communications DIO, SP1, I2C, UART

CPU

Current (active w/radio on) 19 mA

Page 40: Build Automation Using Wireless Sensor Network

23

ตารางท 3-1 (ตอ) รายละเอยดอปกรณ

Current (sleep) 5.1 uA Startup Time 6 uS

Voltage 1.8-3.6 V Frequency 2400-2483 MHz Data Rate 250 kbps Output Power -25 to 0 dB Startup Time 580 uS

Radio

Antenna Type Inverted-F or SMA Coax Humidity Accuracy 3.5% RH Temperature Accuracy 0.5 C

Humidity Sensor

Sampling Rate 90 Hz ทมา: [13] 3.1.1.2 การใชพลงงาน (Power) TmoteSky ใชพลงงานจากพลงงานแบตเตอร ขนาด AA จานวนสองกอนโดยมการออกแบบใหรองรบแรงดนไดตงแต 2.1-3.6 V ตารางท 3-2 รปแบบตาง ๆ ของการจดการระบบพลงงาน

MIN NOM MAX UNIT Supply Voltage 2.1 3.6 V Supply Voltage During Flash memory Programming 2.7 3.6 V Operation Free air temperature -40 58 Celsius Current Consumption:MCU on, Radio RX 21.8 23 mA Current Consumption:MCU on, Radio TX 19.5 21 mA Current Consumption:MCU on, Radio off 1800 2400 uA Current Consumption:MCU idle, Radio off 54.5 1200 uA Current Consumption:MCU standby 5.1 21.0 uA

ทมา: [13]

Page 41: Build Automation Using Wireless Sensor Network

24

3.1.1.3 ชนด Sensor ภายในของ TmoteSky ใน TmoteSky จะมเซนเซอรสองชนดคอ Humidity/Temperature Sensor และ Light Sensor โดยในการตรวจจบแสงใน TmoteSky นนจะใช Photodiode สองตวในการทางาน 3.1.1.3.1 Humidity/Temperature Sensor ซงใน TmoteSky จะใช Sensor no. SHT11 (Sensirion) ใชในการตรวจจบความชนและอณหภม 3.1.1.3.2 Photo synthetically Active Radiation Sensor (P.A.R sensor) เปนเซนเซอรทถกพฒนามาจากเซนเซอรแสง และถกออกแบบมาเพอการวดการเปลยนแปลงทางเคมโดยอาศยการแผออกของแสงเปนตวกระตน โดยเซนเซอรประเภทนจะใชงานในการวดไดดในชวง 400-700 นาโนเมตรของความยาวคลนแสง 3.1.1.3.3 Total Solar Radiation Sensor (T.S.R sensor) เปนเซนเซอรทใชในการวดความเขมของพลงงานแสง โดยเซนเซอรตวนจะทางานคกบ P.A.R sensor เพอวดคาแลวนามาคานวณเพอใหไดคาทใกลเคยงมากทสด ตารางท 3-3 ความสามารถในการวดสญญาณของ Sensor no. SHT11 (Sensirion)

Parameter MIN TYP MAX Units Humidity Resolution 0.5 0.03 0.03 %RH 8 12 12 bit Repeatability ± 0.1 %RH Range 0 100 %RH Temperature Resolution 0.04 0.01 0.01 C° 0.07 0.02 0.02 F°

12 14 14 bit Repeatability 1.0± C°

2.0± F° Range -40 123.8 C° -40 254.9 F°

ทมา: [13]

Page 42: Build Automation Using Wireless Sensor Network

25

3.1.2 TmoteInvent เปนอปกรณรนทมความสามารถสงกวา TmoteSky แตมความคลายคลงกนและถกพฒนามาบน TinyOS และใชภาษา NesC เหมอนกนจงทาใหสามารถใชงานรวมกนได โดยในโครงงานนเราไดใช TmoteInvent เปนอปกรณในการเชอมตอกบคอมพวเตอรเพออานคาท รบไดจาก Sensor Node ตวอน ๆ ในเครอขายไวเลสเซนเซอรทเราไดทาการตดตงไว ใน TmoteInvent นนไดทาการเพมความสามารถของอปกรณใหมความสามารถเหนอกวา TmoteSky โดยมรายละเอยดดงน เพมชดคาสงใหงายตอการใชงาน และมโปรแกรมสาเรจรปเพออานคาและวดผลตาง ๆ ทอานไดมาใหพรอมใชงาน แบตเตอร Lithium ion ภายในทาใหสะดวกในการใชงานและสามารถบรรจกระแสใหมได มการเพมประเภทของเซนเซอรทาใหสามารถนาไปประยกตใชกบงานไดหลากหลายชนดของ Sensor ภายในของ TmoteInvent (ทเพมขนมาเมอเทยบกบ TmoteSky) Accelerometer Sensor คอ เซนเซอรทใชจบความเคลอนไหวโดยเซนเซอรจะถกตดตงไวภายในของตวอปกรณและสามารถจบความเคลอนไหวของตวอปกรณไดสองแกน (x,y) Microphone Sensor เปนเซนเซอรทใชวดคาตาง ๆ ทไมโครโฟนของ TmoteInvent รบคามาได เชน อานคาระดบสญญาณทไมโครโฟน อานคาบฟเฟอรของไมโครโฟน และยงสามารถกาหนดคาของไมโครโฟนได เชน กาหนดคา Amplitude สาหรบการ Interrupt Speaker Sensor เปนเซนเซอรทใชอานคาระดบสญญาณทออกมาจากลาโพงภายใน และยงสามารถเกบคาตาง ๆ ของลาโพงโดยใชคาสงผานทางเซนเซอรไดอกดวย Voltage Sensor คอ เซนเซอรทใชอานคาปรมาณการใชพลงงานของ TmoteInvent (mV)

Page 43: Build Automation Using Wireless Sensor Network

26

ภาพท 3-1 รายละเอยดอปกรณตาง ๆ ทตดตงบน TmoteSky

ภาพท 3-2 รายละเอยดอปกรณตาง ๆ ทตดตงบน TmoteInvent

Page 44: Build Automation Using Wireless Sensor Network

27

3.2 โปรแกรมทใชในการพฒนาโครงงาน

3.2.1 Cygwin (Unix Simulator) Cygwin เปนชดเครองมอซอฟตแวรเสร ทเรมพฒนาโดย Cygnus Solutions เพอทาใหระบบปฏบตการไมโครซอฟทวนโดวสสามารถปฏบตงานไดคลายระบบยนกซ จดประสงคหลกของชดเครองมอนคอ เพอการเชอมตอหรอโอนยายซอฟตแวรทใชงานบนระบบ POSIX (เชน ลนกซ บเอสด และยนกซ) ใหมาใชงานบนวนโดวสไดโดยงาย เชน อาจจะแคคอมไพลใหม หรอแกไขเพยงเลกนอย โปรแกรมทพอรตโดย Cygwin น ทางานไดดทสดบนวนโดวสเอนท วนโดวส 2000 วนโดวสเอกซพ และวนโดวสเซรฟเวอร 2003 ปจจบน Cygwin ดแลโดยพนกงานของเรดแฮท ในการพฒนาการใชงาน Cygwin นนยงมขอจากดอยในการ make native หรอการเรยกการใชงานในระดบ native OS ได เนองจาก Cygwin เปนโปรแกรมจาลอง UNIX มาใชงานเทานน โดยการนามาใชในโครงงานนเราไดทาการตดตง Cygwin เพอใชในการเขยน และคอมไพลไฟลตาง ๆ ทไดทาการแกไขหรอสรางใหมขนมา และใชคาสงผาน Cygwin ในการเขยนไฟลทผานการคอมไพลเขาไปใน TmoteInvent และ TmoteSky

3.2.2 Xampp ออกแบบและตดตงเซรฟเวอร (server) เพอทาเปนเซรฟเวอรในการเชอมตอเพอเกบคาทไดรบจากเซนเซอรมาทาเปนฐานขอมล

3.2.3 Eclipse โปรแกรมสาเรจรปทใชในการออกแบบและเขยนโปรแกรมดวยภาษาจาวาโดยสนบสนน J2ME

Page 45: Build Automation Using Wireless Sensor Network

28

3.3 การทดสอบประสทธภาพของอปกรณ การวดประสทธภาพของ TmoteSky นน เราไดยดคา RSSI (Received Signal Strength Indication) ซงเปนคาทวดไดจากระดบสญญาณทรบไดในแตละ Tmote ซงถามคา RSSI สงจะทาใหสญญาณทรบไดมประสทธภาพมาก และมโอกาสทจะเกดความผดพลาดในการสงสญญาณนอยลงตามลาดบในการทดสอบประสทธภาพของ Tmote แตละตวจะตองคาถงสภาพแวดลอมทใชในการทางานจรง เพอสามารถนาขอมลทไดไปใชประกอบในการตดตงและออกแบบระบบ WSN ทตองการในอาคารทกาหนด โดยรปแบบตาง ๆในการทดสอบมดงน 3.3.1 การวาง TmoteSky ในรปแบบตาง ๆ แลววดคา RSSI เพอเปรยบเทยบคาทวดไดกบรปแบบการวางทแตกตางกน

ภาพท 3-3 การวาง TmoteSky ในรปแบบตาง ๆ

Page 46: Build Automation Using Wireless Sensor Network

29

ภาพท 3-4 กราฟความแรงของสญญาณในการวาง TmoteSky ในรปแบบตาง ๆ

แบบท 1 อานคาได ประมาณ -6 dB (จากกราฟได 100 dB) แบบท 2 อานคาได ประมาณ -12 dB (จากกราฟได 94 dB) แบบท 3 อานคาได ประมาณ -7 dB (จากกราฟได 99 dB) แบบท 4 อานคาได ประมาณ -16 dB (จากกราฟได 90 dB) แบบท 5 อานคาได ประมาณ -12 dB (จากกราฟได 94 dB) แบบท 6 อานคาได ประมาณ -12 dB (จากกราฟได 94 dB)

ในการวาง Tmote ใหวางแบบ แบบท 1 คอ mote1 และ mote2 หนสวนทเปนสายอากาศ(Antenna) เขาหากนจะทาใหไดสญญาณดทสดคอประมาณ -6 dB และการวางแบบท 4 หนสวนทเปนสายอากาศออกจากกนจะไดสญญาณแยทสด วดสญญาณได -16 dB 3.3.2 การทดสอบความสามารถในการสงสญญาณของ TmoteSky ทระดบความสงตาง ๆ กนของสายอากาศ

ภาพท 3-5 การวาง TmoteSky ทความสงตางๆกน

Page 47: Build Automation Using Wireless Sensor Network

30

การวาง TmoteSky แนวเดยวกนแลวปรบระยะในแนวแกนความสง แลววดคาความแรงของสญญาณทรบไดในระยะทแตกตางกนเพอหาความสมพนธของระยะทางและความแรงของสญญาณ ตารางท 3-4 ความสามารถในการสงสญญาณของ TmoteSky ทระดบความสงตาง ๆ กน

การหาคา RSSI ทความสงตาง ๆ (1200 Samples) ท 4 Sampling/s RSSI Height (cm)

Tx-Rx คาเฉลย (dB) SD 1 ---> 2 -27.9692 0.2039 10 2 ---> 1 -26.0000 0.0000 1 ---> 2 -34.9258 1.2349 20 2 ---> 1 -37.3217 1.1244 1 ---> 2 -44.3542 1.2768 50 2 ---> 1 -44.9150 1.4530 1 ---> 2 -54.0983 3.8982 100 2 ---> 1 -53.7700 3.5514

จากการทาการทดสอบแสดงใหเหนวาในการวาง TmoteSky ทระดบตางกนในการใชงานนน คาระดบความแรงสญญาณทรบไดนนจะแปรผนแบบผกผนตามระยะทาง ดงนนในการใชงาน TmoteSky เพอออกแบบตดตงระบบทตองการนนควรจะตองพยายามรกษาระดบความสงของตวอปกรณใหอยในระดบเดยวกน เพอเพมความสามารถในการสงสญญาณและประสทธภาพโดยรวมของระบบ 3.3.3 การทดสอบความสามารถในการสงสญญาณของ TmoteSky ผานวสดตาง ๆ โดยนา TmoteSky มาวดคาสญญาณโดยวาง TmoteSky ผานตวกลางตาง ๆ กนเพอเปรยบเทยบและใชคาทวดไดนามาวเคราะหเพอชวยออกแบบ และกาหนดจดทเปนไปไดในการตดตง TmoteSky ในอาคาร โดยมวสดพนฐาน 3 ชนดทมความเปนไปไดทกดขวางการสงสญญาณของ TmoteSky ภายในอาคาร ไดแก ไม กระจก และผนงปน โดยมการทดสอบดงน

3.3.3.1 นา TmoteSky 2 ตวมาวางในลกษณะใหเสาสญญาณเขาหากนโดยมวสดทตองการทดสอบคนกลาง

3.3.3.2 เปดเครองและวดคาตามเวลาทกาหนด (5 นาท)

Page 48: Build Automation Using Wireless Sensor Network

31

3.3.3.3 บนทกคาและหาคาเฉลยของขอมลเพอใหไดคาทใกลเคยงและถกตองทสด

ภาพท 3-6 รปแบบการวดคา RSSI เมอผานวสดตาง ๆ

ตารางท 3-5 ความสามารถในการสงสญญาณของ TmoteSky เมอผานวสดตาง ๆ การหาคา RSSI เมอผานวสดตาง ๆ (1200 Samples) ท 4 Sampling/s

RSSI Material Tx-Rx คาเฉลย (dB) SD

2 ---> 1 -25.79 0.413 Wood test 1 ---> 2 -24.48 0.587 2 ---> 1 -14.01 0.071 Glass Test 1 ---> 2 -12.01 0.099 2 ---> 1 -32.00 0.004 Cement Test 1 ---> 2 -30.00 0.002

ความเขมของสญญาณผานวสดตาง ๆ ของ TmoteSky นน กระจกเปนวสดทมคาลดทอนตาทสด เนองจากเปนวสดทบางและยอมใหคลนผานเปนเสนตรงไดงาย จงทาใหคาสญญาณทรบไดสญเสยไปนอยกวาวสดอน ๆ สวนในไมและปนนนมความหนาและมชนดของสสารภายในมาก กวา จงทาใหเกดการลดทอนและการเบยงเบนของสญญาณมากขนตามลาดบ 3.3.4 การทดสอบความสามารถในการสงสญญาณของ TmoteSky ภายในและภายนอกอาคารการทดสอบนทาในเรารคณลกษณะของการสงสญญาณเมอใชงานจรงโดยในการทดสอบแบบ

Page 49: Build Automation Using Wireless Sensor Network

32

ภายในอาคาร (Indoor Test) ลกษณะอาคาร การเคลอนไหวของสงของและคน มผลมาก มการสะทอนมาก คาไมคงท เกดการเปลยนแปลง 10-15 dB สวนในการทดสอบแบบภายนอกอาคารนนสภาพอากาศ ความชนพนดน มผลมาก สงของเคลอนไหว คน รถยนต หรอสงตาง ๆ ทเขามาในระบบลวนทาใหเกดการลดทอนของสญญาณไดโดยทาใหคาสญญาณเกดการเปลยนแปลงได ประมาณ 15-20 dB ขนอยกบวสดและขนาดของสงทเขามาภายในระบบ Indoor: Lp = -15.75log(d) - 47.52 โดยท d มหนวยเปนเมตร ทระยะไมเกน 50 เมตร Outdoor: Lp = -19.71log(d) - 55.77 โดยท d มหนวยเปนเมตร ทระยะไมเกน 100 เมตร ตารางท 3-6 ความสามารถในการสงสญญาณของ TmoteSky ทระยะตาง ๆ ภายในอาคาร

RSSI

คาเฉลย (dB) SD ระยะหาง(m) 1 ---> 2 2 ---> 1 1 ---> 2 2 ---> 1

0.1 -35.2008 -37.1900 1.2083 1.2296

0.5 -41.3633 -42.0400 0.8890 0.7027

1 -46.8008 -47.7033 1.7152 1.8832

1.5 -49.1925 -49.6567 2.6947 2.1682

2 -47.5075 -48.3333 1.8044 1.8060

3 -58.7542 -59.9467 2.9376 2.5188

5 -56.6933 -56.4500 1.3494 1.1834

10 -60.0625 -60.8750 2.2240 1.6613

15 -64.8983 -65.2408 1.1864 1.2203

20 -73.0000 -73.5067 2.2674 2.2299

25 -78.0533 -78.3408 2.8476 2.9235

30 -67.9133 -68.3808 0.9992 1.1031

35 -68.4892 -68.9208 0.9393 0.5830

Page 50: Build Automation Using Wireless Sensor Network

33

ตารางท 3-7 ความสามารถในการสงสญญาณของ TmoteSky ทระยะตาง ๆ ภายนอกอาคาร

RSSI

คาเฉลย (dB) SD

ระยะหาง (m) 1 ---> 2 2 ---> 1 1 ---> 2 2 ---> 1

0.1 -27.8050 -28.8433 0.6060 0.7523

0.5 -50.2675 -49.4525 0.9363 1.5668

1 -58.7542 -57.7575 0.9641 1.0100

1.5 -60.7483 -60.8667 0.5230 0.3545

2 -65.4342 -65.8083 0.8697 0.8127

3 -70.8725 -71.3533 1.7451 1.8096

5 -76.0867 -76.2775 1.1395 1.1445

10 -74.1192 -74.8500 2.4762 2.2106

15 -73.9767 -75.1983 2.9340 2.4881

25 -80.0300 -81.3092 2.3676 2.6732

50 -86.3767 -86.6475 2.9192 3.4380

ภาพท 3-7 รปแบบการวดคา RSSI ทระยะตาง ๆ

Page 51: Build Automation Using Wireless Sensor Network

34

3.4 การออกแบบและสรางโปรแกรมทใชในการวดคา RSSI สาหรบ TmoteSky และ TmoteInvent ในการหา RSSI เราจะตองสรางไฟลขนมาเอง คอ OscopeRssi โดยจะใช Tmote อยางตา 3 ตว

ในการหาคาของ RSSI โดยใหตวท 1 ทาการรนโปรแกรม TOSBase เพอคอยอานคา RSSI และใหตวท 2 และ 3 ทาการรนโปรแกรม OscopeRssi เพอใหมการสงและรบคาสญญาณระหวางตวท 2 และ 3 OscopeRssi จะประกอบดวย 4 ไฟล ดงน

3.4.1 OscopeRssi M.nc โปรแกรมภาษา NesC 3.4.2 OscopeRssi.nc ภาษา NesC สาหรบการเชอมตอ component ตาง ๆ 3.4.3 Makefile ควบคมการคอมไพลและการลงโปรแกรมบนอปกรณ 3.4.4 OscopeRssi.h เปนเฮดเดอรไฟลภาษา NesC

3.5 สรปผลการทดลองโดยใชโปรแกรม OscopeRssi 3.5.1 ในการหา RSSI จะตองสรางไฟลขนมาเองคอ OscopeRssi 3.5.2 ใช Tmote อยางตา 3 ตว โดยให ตวท 1 เปน TOSBase (opt/tinyos-1.x/apps/TOSBase) ตวท 2 และ 3 เปน OscopeRssi (opt/tinyos-1.x/apps/OscopeRssi) 3.5.3 กาหนดความถท channel 26 (2.48 GHz) โดยกาหนดไวท Makelocal สตร Frequency = 2405 + 5 ( k – 11 ) MHz โดย k มคาตงแต 11 ถง 26 3.5.4 กาหนดระดบพลงงานทใชมคา 31= 0 dBm คานกาหนดไวท OscopeRssiM.nc โดยคาของระดบพลงงานมคาตงแต 0 ถง -25 dBm 3.5.5 คา RSSI ทไดตองลบดวย 106 ( จากตวอยางใน moteiv.com)

ภาพท 3-8 ภาพจาลองการสงสญญาณเชอมตอของ Tmote

Page 52: Build Automation Using Wireless Sensor Network

บทท 4 ออกแบบและตดตงเครอขายเซนเซอรไรสาย

4.1 การออกแบบเครอขายเซนเซอรไรสาย 4.1.1 สารวจพนทในบรเวณชน 3 ของตก 84 เพอกาหนดสถานทและตาแหนงทเหมาะสมในการตดตงเครอขายเซนเซอรไรสาย 4.1.2 ทาการทดสอบโดยใชโปรแกรม OscopeRssi เพอทาการหาคา Signal Strength สรปไดวาในภาคปฏบตแลว TmoteSky สามารถสงสญญาณไดในระยะประมาณ 50 เมตร และสามารถสงสญญาณผานกาแพงไดหนาไมเกน 2 ชน 4.1.3 พนททใชทดสอบมทงหมด 8 หอง พนทโดยรวมทงหมดประมาณ 544 ตารางเมตร ใช TmoteSky จานวน 14 ตว เพอทาการตรวจจบและสงคา สวนอก 3 ตวเพอทาการเชอมสญญาณในกรณทเชอมตอโดยตรงไมได 4.1.4 ในการกาหนดจานวนเซนเซอรในแตละหอง เนองจากหองมขนาดใหญจงใช TmoteSky หองละ 2 ตว เพอใหครอบคลมบรเวณหองทงหมด และในกรณท TmoteSky เกดการเสยหาย สามารถใช TmoteSky ตวทเหลออยทาการสงคาตอไปได 4.1.5 รปแบบการวาง TmoteSky 4.1.5.1 ในการวดคาแสงสวางและอณหภม ตองคานงถงตาแหนงของเซนเซอรบน TmoteSky โดยใหสามารถตรวจจบแสง อณหภมไดเตมประสทธภาพ หรอมากทสดเทาทจะตรวจจบได เราจงทาการตดตง TmoteSky บรเวณประตและหนาตาง เนองจากประตอยบรเวณ กลางหอง และหนาตางในบางครงอาจมการเปดรบแสงจากภายนอกทาใหสามารถอานคาแสงโดยรวมภายในหองได 4.1.5.2 ในการทาใหสายอากาศสงสญญาณไดมประสทธภาพสงสด เราจงกาหนดทศทางของสายอากาศใหไปในทศทางเดยวกนเพอใหเกดโพลาไรเซชนรวม (Co-Polarization) 4.1.5.3 จากการทดสอบทาใหทราบวา ในการสงสญญาณทระดบความสงเดยวกนจะเกดการสญเสยนอยทสด ดงนนจากการสารวจสถานทในการตดตงจงไดหาคาเฉลยทเหมาะสมสาหรบทกหองเพอไมใหเกดการลดทอนและการสะทอนในการสงและรบสญญาณ นอกจากนยงเพมรศมไดไกลมากขน

Page 53: Build Automation Using Wireless Sensor Network

36

4.2 การตดตงเครอขายเซนเซอรไรสาย 4.2.1 การออกแบบบรรจภณฑ เนองจาก TmoteSky เปนอปกรณสาหรบพฒนาเพอตอยอดนวตกรรมใหม ๆ ตวอปกรณจงไมมการออกแบบกลองหรอบรรจภณฑ ดงนนผพฒนาจงตองออกแบบใหเขากบงานหรอ สภาพแวดลอมและ สอดคลองกบการนาไปใชงานจรง

ภาพท 4-1 กลองตนแบบทนามาใชในการออกแบบบรรจภณฑสาหรบ TmoteSky ใน

โครงงานวจยเครอขายเซนเซอรไรสาย

ภาพท 4-2 บรรจภณฑสาหรบ TmoteSky ในโครงงานวจยเครอขายเซนเซอรไรสาย

ภาพท 4-3 TmoteSky พรอมบรรจภณฑ

Page 54: Build Automation Using Wireless Sensor Network

37

4.2.2 แหลงจายพลงงาน TmoteSky ไดรบการออกแบบมาเพอใชพลงงานทชวงระดบแรงดน ไฟฟาระหวาง 2.4 ถง 3.6 โวลต หรอจากถานไฟฉายขนาด AA จานวน 2 กอน ระยะเวลาใชงานขนอยกบการใชพลงงาน ในการทาโครงงานเครอขายเซนเซอรไรสายน จาเปนทจะตองใชแหลงจายพลงงานมความเสถยรเพอปองกนปญหาในการทดสอบระบบฯ เราใชสาย USB 2.0 ในการเชอมตอกบหมอแปลง และในกรณทระยะทางไมเพยงพอเราจะใชสาย USB 1.0 เพอเพมระยะทางระหวางจดจายพลงงานกบจดทตดตง TmoteSky

ภาพท 4-4 แหลงจายพลงงานทเลอกใช 4.2.3 อปกรณทใชในการตดตงเครอขายเซนเซอรไรสาย 4.2.3.1 TmoteSky 4.2.3.2 สายเชอมตอ USB 2.0 4.2.3.3 สายเชอมตอ USB 1.0 4.2.3.4 หมอแปลง (แปลงไฟ 220 V เปน DC 5 V) 4.2.3.5 คตเตอร 4.2.3.6 ไขควง 4.2.3.7 กรรไกร 4.2.3.8 Nylon Fastening Tape (เทปตนตกแก) 4.2.3.9 กลองพลาสตก 4.2.3.10 สวานมอ

Page 55: Build Automation Using Wireless Sensor Network

38

ภาพท 4-5 อปกรณในการตดตงเครอขายเซนเซอรไรสาย 4.2.4 การตดตงเครอขายเซนเซอรไรสาย จากการสารวจสถานทและทดสอบความสามารถในการสงสญญาณของอปกรณทาใหสามารถทราบถงจดทเหมาะสมในการตดตงไวเลสเซนเซอร โดยไดมการตดตงดงน

ภาพท 4-6 แผนผงการตดตงเซนเซอร

สถานทตดตง สถานท: คณะวศวกรรมศาสตร มหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ อาคาร : 84 บรเวณ : ชน3 หองคอมพวเตอร หองโปรเจคคอมพวเตอร หองแลปสอสาร และหอง แลปคอมพวเตอร หอง Embedded และพนทใกลเคยง จานวน mote : 17 motes หมายเลข mote : mote 1 ถง mote 17

Page 56: Build Automation Using Wireless Sensor Network

39

หองแลปสอสาร Mote 1

ภาพท 4-7 ตาแหนงการตดตงเซนเซอรหมายเลข 1

เนองจากเปนหองขนาดเลกและอยใกลเครองเซรฟเวอรจงตดตงเพยงหนงตวบรเวณกระจกขางประตเขาหอง Mote 2, 3

ภาพท 4-8 ตาแหนงการตดตงเซนเซอรหมายเลข 2

Page 57: Build Automation Using Wireless Sensor Network

40

ภาพท 4-9 ตาแหนงการตดตงเซนเซอรหมายเลข 3 การตดตงเซนเซอรหมายเลขสองและสามเปนเซนเซอรทตดตงในหองแลปสอสารและเปนหองขนาดใหญจงตดตงทประตและกลางหองอยางละตว หองแลปคอมพวเตอร Mote 4

ภาพท 4-10 ตาแหนงการตดตงเซนเซอรหมายเลข 4

เปนหองขนาดเลกและเปนหองโลงเซนเซอรไรสายเพยงตวเดยว

Page 58: Build Automation Using Wireless Sensor Network

41

Mote 5

ภาพท 4-11 ตาแหนงการตดตงเซนเซอรหมายเลข 5

Mote 6

ภาพท 4-12 ตาแหนงการตดตงเซนเซอรหมายเลข 6

การตดตงเซนเซอรหมายเลขหาและหกเปนเซนเซอรทตดตงในหองแลปคอมพวเตอรและเปนหองขนาดใหญจงตดตงทประตและกลางหองอยางละตวดงทแสดงดงภาพท 4-11 และ ภาพท 4-12

Page 59: Build Automation Using Wireless Sensor Network

42

หองคอมพวเตอร Mote 7, 8

ภาพท 4-13 ตาแหนงการตดตงเซนเซอรหมายเลข 7 และ 8

Mote 9, 10

ภาพท 4-14 ตาแหนงการตดตงเซนเซอรหมายเลข 9 และ 10

ในการตดตงเซนเซอรไรสายในหองคอมพวเตอรนนเปนหองขนาดใหญและมสงกดขวางทสงผลตอการลดทอนของสญญาณสง ดงนนการตดตงจงตองคานงถงสภาพเปนจรงในหองเปนหลกและในจดทตดตงตองสามารถวดคาไดอยางผดเพยนจากความเปนจรงนอยทสด

Page 60: Build Automation Using Wireless Sensor Network

43

หอง Embedded Mote 11

ภาพท 4-15 ตาแหนงการตดตงเซนเซอรหมายเลข 11

Mote 12

ภาพท 4-16 ตาแหนงการตดตงเซนเซอรหมายเลข 12

การตดตงเซนเซอรในหอง Embedded สามารถเลอกจดตดตงไดงาย เพราะเปนหองขนาดใหญและมผทางานภายในหองนอยทาใหสามารถตดตงไดตามทออกแบบไว จงทาใหเซนเซอรทตดตงทางานไดอยางมประสทธภาพและผดพลาดนอยทสด

Page 61: Build Automation Using Wireless Sensor Network

44

หองโปรเจคคอมพวเตอร Mote 13

ภาพท 4-17 ตาแหนงการตดตงเซนเซอรหมายเลข 13

Mote 14

ภาพท 4-18 ตาแหนงการตดตงเซนเซอรหมายเลข 14

การตดตงเซนเซอรในหองโปรเจคคอมพวเตอรไดตดตงเซนเซอรไรสายจานวนสองตวบรเวณหนาตางและประตอยางละตวเพอใหครอบคลมบรเวณทงหอง

Page 62: Build Automation Using Wireless Sensor Network

45

Mote 15, 16, 17

ภาพท 4-19 ตาแหนงการตดตงเซนเซอรหมายเลข 15, 16 และ 17 เปนเซนเซอรไรสายทตดตงไวบรเวณทางเดนเพอคอยตรวจจบคาและเปนชองทางไวคอยรบคาจากเซนเซอรไรสายตวอน ๆ ในกรณทตวใกลเคยงอน ๆ เสยหาย

Page 63: Build Automation Using Wireless Sensor Network

บทท 5 การออกแบบและพฒนาซอฟตแวรสาหรบโครงงาน

5.1 พฒนาซอฟตแวรบนอปกรณ อปกรณทใชในทาโครงงานนคอ TmoteSky และ TmoteInvent การพฒนาซอฟตแวรบน Tmote เปนการพฒนาโปรแกรมโดยใชภาษา NesC และใชโปรแกรม Text Editor ในการเขยนโคด ของภาษา NesC ใชโปรแกรม Cygwin ในการคอมไพลโปรแกรมและทาการตดตงโปรแกรมบน Tmote โปรแกรม DTSR พฒนามาจากโปรแกรม Delta เพอให Tmote สามารถสอสารแบบ Ad-hoc ได โดยจะกาหนดใหแตละตวมรหสประจาตวทแตกตางกน Tmote ทเชอมตอกบคอมพวเตอรจะเปน รหส 0 (mote0) และเรยงตามลาดบตาง ๆ ของหองตามทออกแบบไว และกาหนดรหสกลมเพอใหตดตอกน โดยกาหนดรหสกลมไวท 125 จะมเพยงเฉพาะ Tmote ทอยในกลมเดยวกนเทานนทจะตดตอกนได

5.1.1 การกาหนดพลงงาน ใหสงสญญาณดวยความเขมสญญาณไวทระดบ 31 เพราะกาแพงของอาคารมความหนา และในดานการใชพลงงานจะใชไฟฟากระแสสลบทระดบแรงดน 220 V แปลงเปนไฟกระแสตรงทระดบแรงดน 5 V

5.1.2 การสงแพคเกจขอมล เมอไดรบแพคเกจทสงมาจาก Tmote ในกลมเดยวกน Tmote จะสงตอแพคเกจขอมลไปเรอย ๆ จนถงตวทตดตอกบเซรฟเวอร เพอทาใหตวทอยไกลจากจดรบขอมลสามารถสงขอมลไปยงฐานขอมลได

5.1.3 การอานคาจากเซนเซอร โดยจะอานคา Internal temperature ซงเปนตววดอณหภม, PAR และ TSR ซงใชวดความเขมแสง

5.1.4 การสงแพคเกจขอมลไปยงเซรฟเวอร จะใช mote0 ทตดตอกบคอมพวเตอร เปนจดในการรบแพคเกจจาก Tmote ตวอน ๆ

5.1.5 สวนประกอบตาง ๆ ของโปรแกรม DTSR 5.1.5.1 Delta.h เปนเฮดเดอรไฟลภาษา NesC 5.1.5.2 Delta.nc ภาษา NesC สาหรบการเชอมตอ component ตาง ๆ 5.1.5.3 DeltaM.nc โปรแกรมภาษา NesC 5.1.5.4 Makefile ควบคมการคอมไพลและการลงโปรแกรมบนอปกรณ

Page 64: Build Automation Using Wireless Sensor Network

47

5.2 พฒนาซอฟตแวรบนคอมพวเตอร การพฒนาซอฟตแวรบนคอมพวเตอร เปนการพฒนาโปรแกรมโดยใชภาษาจาวาและโปรแกรม Text Editor ในการเขยนโคดของภาษาจาวา โปรแกรม DCDB จะรบคาจาก Tmote ตวทเชอมตอกบคอมพวเตอรผานทาง USB พอรต โดยจะแปลงคาขอมลจากฐาน 16 เปนฐาน 10 และนามาคานวณใหออกมาเปนคาและหนวยของขอมลทเปนสากล โดยคานวณออกมาใหหนวยของอณหภมออกมาเปนองศาเซลเซยส แสงเปนหนวย Lux และแสดงคาคณภาพของสญญาณของ Tmote ทใชเชอมตออย และตดตอฐานขอมลโดยใช JDBC นาไปเกบในฐานขอมลของเวบแอปพลเคชน ซงจะอยในเครองเดยวกนหรอเครองอนกได โดยเชอมตอผานเครอขายอนเตอรเนตโดยกาหนด IP และการเชอมตอในโปรแกรมไดโดยตรง 5.3 พฒนาซอฟตแวรเพอแสดงผลบนเวบไซด การพฒนาซอฟตแวรบนเวบแอปพลเคชน จะใช Open Source โดยการสรางฐานขอมลจะใช MySQL ในการสรางฐานขอมล และใชภาษา PHP, HTML, JavaScript ในการเขยนหนาเวบไซด ม Apache เปนตวบรการเวบไซด โดยใชโปรแกรม XAMPP ซงรวม Apache MySQL และ FileZilla ไว และ XAMPP ยงตอบสนองการสรางกราฟ jpgraph ไดด

5.4 พฒนาซอฟตแวรบนโทรศพทมอถอ การพฒนาซอฟตแวรบนโทรศพทมอถอ จะใชภาษา J2ME ในการเขยนโปรแกรม โดยใชโปรแกรม Eclipse เขยนภาษาจาวา และใชโปรแกรม Sun JAVA Wireless Toolkit ในการจาลองการทางานของโปรแกรมบนโทรศพทมอถอ เขยนโปรแกรมเพอสรางการเชอมตอระหวางโทรศพทมอถอกบเซรฟเวอร เพอนาคาทตองการ มาแสดงผลบนหนาจอโทรศพทมอถอ โดยโปรแกรมททาการสรางขนมสวนประกอบตางๆ ดงน 5.4.1 mobileWSN.java แสดงคาอณหภมและแสงสวางของหอง Lab Communication 5.4.2 LabComputer.java แสดงคาอณหภมและแสงสวางของหอง Lab Computer 5.4.3 Computer2.java แสดงคาอณหภมและแสงสวางของหอง Computer 2 5.4.4 Computer1.java แสดงคาอณหภมและแสงสวางของหอง Computer 1 5.4.5 Embeded.java แสดงคาอณหภมและแสงสวางของหอง Embedded 5.4.6 ComputerProject.java แสดงคาอณหภมและแสงสวางของหอง Computer Project 5.4.7 Allmote.java แสดงคาอณหภมและแสงสวางของทกหอง

Page 65: Build Automation Using Wireless Sensor Network

48

5.4.8 moteDisconnect.java แสดง Tmote ทขาดการตดตอกบฐานขอมลเปนเวลา 5 นาท 5.4.9 WSNMAP.java แสดงตาแหนงของการตดตง Tmote ทหองตาง ๆ 5.4.10 gui.java แสดงรายละเอยดตาง ๆ ของ Tmote

5.5 การแสดงผลบนเวบเบราเซอร 5.5.1 เขาไปท http://mobile.ee.kmitnb.ac.th/ เพอทาการสมครสมาชกหรอ Login เพอเขาระบบ

ภาพท 5-1 Homepage http:// mobile.ee.kmitnb.ac.th/

Page 66: Build Automation Using Wireless Sensor Network

49

5.5.2 หนาเมนหลก แสดงภาพรวมของโครงงาน

ภาพท 5-2 หนาเมนหลก

5.5.3 เมน Admin จะมเฉพาะผทลอคอนเปนสถานะ Admin เทานน สามารถเพมจานวนผใชไดโดยเลอกท Add User สามารถดรายละเอยดของสมาชกทงหมด ไดโดยเลอกท Show members และสามารถเขาไปในฐานขอมลไดโดยเลอกท Database Maneger (PHP Myadmin)

ภาพท 5-3 เมน Admin

Page 67: Build Automation Using Wireless Sensor Network

50

5.5.4 แสดงการเพมจานวนผใช โดย Admin สามารถกาหนดสถานะของผใชได 2 แบบ คอ Admin และ User

ภาพท 5-4 การเพมจานวนผใช

5.5.5 แสดงรายละเอยดของสมาชกทงหมด โดยสามารถแกไขรายละเอยดตาง ๆ ไดโดยเลอกท Edit และสามารถลบชอผใชไดโดยเลอก Delete

Page 68: Build Automation Using Wireless Sensor Network

51

ภาพท 5-5 รายละเอยดของสมาชกทงหมด

5.5.6 แสดงหนาเวบทใชแกไขขอมลของสมาชก

ภาพท 5-6 การแกไขขอมลสมาชก

5.5.7 แสดงหนาเวบทใชในการลบขอมลของสมาชก

Page 69: Build Automation Using Wireless Sensor Network

52

ภาพท 5-7 การลบขอมลสมาชก

5.5.8 เมอคลกท Database Maneger (PHP Myadmin) ใหใส User Name และ Password เพอทาการเขาสฐานขอมล

ภาพท 5-8 การลอคอนเขาสฐานขอมล

Page 70: Build Automation Using Wireless Sensor Network

53

5.5.9 เมน Realtime แสดงขอมลของ Tmote ทหองตาง ๆ สามารถเลอกหองทตองการแสดงผลไดทเมน Select Room และสามารถดคาของแบบ Statistic ไดโดยกดปม Statistic และจะทาการโหลดหนานใหมทก ๆ 20 วนาท โดยจะแสดงคาตาง ๆ ดงน Room: การบอกตาแหนงทตดตง Tmote Time: เวลาททาการเกบคาลงฐานขอมล Mote: แสดงหมายเลขของ Tmote ทมการตดตอกบเซรฟเวอร TSR: การวดคาของแสงสวาง มหนวยเปน Lux PAR: การวดคาของแสงสวาง Temperature: การวดคาของอณหภม มหนวยเปนองศาเซลเซยส Quality: การวดคณภาพของสญญาณ ถามคามากแสดงสญญาณมคณภาพตา Comment: แสดงสถานะของ Tmote โดยจะม 2 คา คอ OK เมอ Tmote มการรบและสงคาปกต และ Packet Error เมอ Tmote มคาของอณหภมมากกวา 100 องศาเซลเซยส และนอยกวา -50 องศาเซลเซยส และเมอ Tmote มคาของการวดแสง มากกวา 2000 Lux และนอยกวา -100 Lux

ภาพท 5-9 เมน Realtime

นอกจากนในกรณท Tmote ขาดการตดตอกบฐานขอมลเกน 3 นาทหรอในกรณทอณหภมมากกวา 70 องศาเซลเซยส หรอตากวา 22 องศาเซลเซยสจะแสดง WARNING และมเสยงสญญาณเตอน

Page 71: Build Automation Using Wireless Sensor Network

54

5.5.10 เมน Static แสดงคาแบบสถต สามารถแสดงคาได 2 แบบ คอ แบบกราฟ และแบบสถตโดยเลอกรปแบบการแสดงผล จากนนเลอก mote ทตองการแสดงผล เลอกวนเวลาเวลาทตองการแสดงผล และเลอกขอมลทตองการจะแสดงผล

ภาพท 5-10 เมน Static

5.5.11 การแสดงผลแบบกราฟ

ภาพท 5-11 การแสดงกราฟ 5.5.12 การแสดงผลแบบสถต สามารถเปลยนไปแสดงผลแบบกราฟไดโดยการกดท ShowGraph

Page 72: Build Automation Using Wireless Sensor Network

55

ภาพท 5-12 การแสดงผลแบบสถต 5.5.13 เมน Floor 3 แสดงตาแหนงทตงของ Tmote แตละตว เมอนาเมาสไปวางไวบน Tmote (วงกลมสแดง) จะแสดงตาแหนงทนา Tmote ไปตดตง และเมอ Click ท Tmote จะสามารถดคาของ Tmote แบบ Realtime ได

ภาพท 5-13 เมน Floor 3

5.5.14 เมน Floor 4 จะแสดงแผนทของ Floor 4

Page 73: Build Automation Using Wireless Sensor Network

56

ภาพท 5-14 เมน Floor 4

5.5.15 เมน Contact Us แสดงหนารายชอของสมาชกททาโครงงาน กรณทเปน User จะสามารถเขามาไดทางเมน Contact Us ในกรณของ Admin สามารถเขามาหนานไดจากลงคดานลางทเขยนวา Smart Building Group

ภาพท 5-15 หนา contact_us.php 5.6 การแสดงผลบนโทรศพทมอถอ

Page 74: Build Automation Using Wireless Sensor Network

57

5.6.1 ทาการจาลองการทางานของโปรแกรม J2ME บนโทรศพทมอถอ โดยใชโปรแกรม Sun JAVA Wireless Toolkit เมอทาการรนโปรแกรมจะมเมนใหเลอก 10 เมน ดงภาพท 5-16

ภาพท 5-16 จาลองการทางานของโปรแกรม J2ME บนโทรศพทมอถอ 5.6.2 เมอกดเมนเลอกหองตาง ๆ โปรแกรมจะทาการเชอมตอกบเซรฟเวอร ดงภาพท 5-17

ภาพท 5-17 การเชอมตอกบเซรฟเวอรบนโทรศพทมอถอ

Page 75: Build Automation Using Wireless Sensor Network

58

5.6.3 จากนนจะแสดงคาของแสงสวาง และอณหภมของหองทเลอกไว พรอมทงตาแหนงทตงของ Tmote ดวย

ภาพท 5-18 การแสดงคาของแสงสวาง และอณหภมของหองทเลอกไว 5.6.4 เมอกดเมน Allmote จะแสดงตาแหนงทตงของ Tmote ทกตว พรอมทงแสดงคาของแสงสวาง อณหภม และเวลาททาการเกบคาลงฐานขอมล

ภาพท 5-19 การแสดงคาของเมน Allmote

Page 76: Build Automation Using Wireless Sensor Network

59

5.6.5 เมอกดเมน moteDisconnect จะแสดง Tmote ทขาดการตดตอกบฐานขอมล

ภาพท 5-20 การแสดงคาของเมน moteDisconnect 5.6.6 เมอกดเมน WSNMAP จะแสดงตาแหนงทตงของ Tmote ทงหมด สามารถกดหมายเลข 1 ถง 6 เพอเลอกดหองตาง ๆ ได ดงภาพท 5-21

ภาพท 5-21 การแสดงคาของเมน WSNMAP

Page 77: Build Automation Using Wireless Sensor Network

60

5.6.7 จากเมน WSNMAP เมอกด 3 จะแสดงภาพแผนทของตาแหนงท Tmote ตดตง ณ หอง Computer 2

ภาพท 5-22 แสดงแผนทหอง Computer 2 5.6.8 เมอกดเมน Manual จะแสดงเมนใหเลอก 2 เมน คอ Mote Status ซงจะบอกตาแหนงทตงของ Tmote ทงหมด และ Credit ซงจะบอกชอของโครงงานทพฒนาโปรแกรมน

ภาพท 5-23 การแสดงคาของเมน Manual 5.6.9 จากเมน Manual เมอเลอก Mote status จะแสดงดงภาพท 5-24

Page 78: Build Automation Using Wireless Sensor Network

61

ภาพท 5-24 การแสดงคาของเมน Mote status 5.6.10 จากเมน Manual เมอเลอก Credit จะแสดงดงภาพท 5-25

ภาพท 5-25 การแสดงคาของเมน Credit

Page 79: Build Automation Using Wireless Sensor Network

บทท 6 สรปผลการทดลอง

6.1 สรปผลการทดลอง ในการสรางระบบอาคารอจฉรยะโดยใชเครอขายเซนเซอรไรสาย ไดทาการทดสอบอปกรณวาสามารถใชไดอยางมประสทธภาพตามทตองการ จากนนจงไดพฒนาซอฟตแวรใหสามารถอานคาจากเซนเซอรและสรางเครอขายแบบ Ad-hoc ตลอดจนนาคาทไดบนทกลงฐานขอมล และแสดงผลบนเวบไซด และโทรศพทมอถอ ซงสามารถใชงานไดจรงอยางมประสทธภาพ 6.2 ปญหาทพบระหวางทาโครงงาน 6.2.1 สญญาณไวเลสจะถกลดทอนไดงายเนองจากสภาพแวดลอม เชน ในกรณทมคนอยในหองมากทาใหสญญาณถกรบกวนจนไมสามารถสงขอมลทตองการมายงฐานขอมลได การแกไข เพมระดบพลงงานในการสงใหมคาสงสด 6.2.2 สภาพแวดลอมของแตละหองไมเหมอนกนทาใหไมสามารถใชเงอนไขการตดตงทเหมอนกนได การแกไข ปรบแตงการตดตงหรอเลอกจดวางใหมทเหมาะสมกวาเพอใหไวเลสเซนเซอรสามารถทางานไดเตมประสทธภาพ 6.2.3 หาจดจายพลงงานทเหมาะสมใหกบไวเลสเซนเซอรไมไดเนองจากในการเกบขอมลหรอการใชงานในประเภทอน ๆ ตองการความตอเนองในการทางานซงพลงงานจากแบตเตอรอาจทาใหเกดความไมสะดวกในการใชงานจรงได

การแกไข ใชสาย USB เพอเพมระยะทางระหวางไวเลสเซนเซอรกบจดจายพลงงาน 6.2.4 การจายพลงงานของไวเลสเซนเซอร ในบางจดจะเปนไปอยางไมสมาเสมอเพราะบางหองจะมการตดไฟตามเวลา ทาใหไมสามารถเกบคาขอมลได 24 ชวโมง การแกไข ใชถานเปนพลงงานเสรมให ไวเลสเซนเซอร ทางานไดอยางตอเนอง 6.2.5 พนผวของวสดในจดทจะทาการตดตงในแตละจดแตกตางกน

การแกไข หาวสดทสามารถตดไดทกพนผว (ในทนใช Nylon Fastening Tape) 6.2.6 ความเสยงในการเสยหายของอปกรณ เนองจากตดตงในทสาธารณะ

Page 80: Build Automation Using Wireless Sensor Network

63

การแกไข ประชาสมพนธใหทราบวาเปนอปกรณทใชในการทาปรญญานพนธ และเขยนชออาจารยและผรบผดชอบไวพรอมทงเบอรโทรตดตอในกรณทมปญหา 6.2.7 อปกรณบางตวตดตงอยในพนทสวนตวทาใหเมอเกดปญหาไมสามารถแกไขไดทนท การแกไข ตดตอขอเบอรไวในกรณฉกเฉนเพอใหสามารถแกไขปญหาทเกดไดเรวทสด 6.2.8 ขาดอปกรณสารองในกรณทเกดปญหา การแกไข พยายามรกษาอปกรณทมอยใหอยในสภาพทดพรอมใชงานอยเสมอ หรอในกรณทอปกรณบางตวไดถกตดตงไปแลวควรไปตรวจสอบสภาพอปกรณอยางสมาเสมอเพอใหอปกรณสามารถทางานไดอยางปกต 6.2.9 คาทอานไดจากเซนเซอรแตละตวมคาไมเทากน เนองจากอปกรณทใชผลตมาจากหลายบรษท ทาใหมมาตรฐานในการอานคาทแตกตางกน การแกไข อางองคาทอานไดจากเซนเซอรสวนใหญเปนหลก

Page 81: Build Automation Using Wireless Sensor Network

เอกสารอางอง

1. กาญจนา ตนวสทธ. เขยนเกมและโปรแกรมบนมอถอ J2ME. นนทบร : ไอดซฯ, 2547. 2. ณฐภชร ณ เขาวงกต. เทคนคการสรางกราฟสวยใน PHP ดวย JPGRAPH. สานกพมพวตตกรป ปทพมพ 2550. 3. http://en.wikipedia.org/wiki/IEEE_802.15.4 4. http://en.wikipedia.org/wiki/Main_Page 5. http://java.sun.com/javame/index.jsp 6. http://plex.coe.psu.ac.th/java/jdbc.html 7. http://standards.ieee.org/getieee802/download/802.15.4-2006.pdf 8. http://vitaly.ediew.com/?p=12 9. http://www.apachefriends.org/en/faq-xampp-windows.html 10. http://www.hospital- os.com/th/modules.php?name=Forums&file=posting&mode =topicreview&t=552&popup=1 11. http://www.ieee.org 12. http://www.java2s.com/ 13. http://www.moteiv.com 14. http://www.robfatland.net/seamonster/index.php?title=TinyOS_Programming_4 15. http://www.roseindia.net/jdbc/index.shtml 16. http://www.thai-programmer.com/?DPage=90700100 17. http://www.tinyos.net/ 18. http://www.w3schools.com/media/media_playerref.asp 19. http://www.zigbee.org/en/index.asp

Page 82: Build Automation Using Wireless Sensor Network

ภาคผนวก ก

การตดตงโปรแกรมทใชในการทาโครงงาน

Page 83: Build Automation Using Wireless Sensor Network

66

การตดตงโปรแกรม Cygwin 1. เขามาทโฟลเดอร Boomerang 2.0.4 จากนนดบเบลคลกทไฟล setup.msi จากนนคลกปม Next

ภาพท ก-1 เรมตดตงโปรแกรม Cygwin 2. คลกเลอก I accept the terms in the License Agreement จากนนคลกปม Next

ภาพท ก-2 ตดตงโปรแกรม Cygwin

Page 84: Build Automation Using Wireless Sensor Network

67

3. เลอกประเภทของโปรแกรมทตองการใชงาน จากนนคลกปม Next

ภาพท ก-3 เลอกประเภทของโปรแกรมทตองการใชงาน 4. จากนนคลกปม Install เพอทาการตดตงโปรแกรม

ภาพท ก-4 เรมการ Install โปรแกรม Cygwin

Page 85: Build Automation Using Wireless Sensor Network

68

5. รอการตดตงโปรแกรม Cygwin

ภาพท ก-5 รอการตดตงโปรแกรม Cygwin 6. ตดตงโปรแกรม J2SE Development Kit 5.0 คลกเลอก I accept the terms in the license agreement จากนนคลกปม Next

ภาพท ก-6 ตดตงโปรแกรม J2SE Development Kit 5.0

Page 86: Build Automation Using Wireless Sensor Network

69

7. เลอกโฟลเดอรทตองการตดตงโปรแกรม J2SE Development Kit 5.0 จากนนคลกปม Next

ภาพท ก-7 เลอกโฟลเดอรทตองการตดตงโปรแกรม J2SE Development Kit 5.0 8. รอการตดตงโปรแกรม J2SE Development Kit 5.0

ภาพท ก-8 รอการตดตงโปรแกรม J2SE Development Kit 5.0

Page 87: Build Automation Using Wireless Sensor Network

70

9. เลอกโฟลเดอรทตองการตดตงโปรแกรม J2SE Runtime Environment 5.0 จากนนคลกปม Next

ภาพท ก-9 เลอกโฟลเดอรทตองการตดตงโปรแกรม J2SE Runtime Environment 5.0

10. เลอกเบราเซอรทตองการใชในการลงทะเบยนโปรแกรม จากนนคลกปม Next

ภาพท ก-10 เลอกเบราเซอรทตองการใชในการลงทะเบยนโปรแกรม

Page 88: Build Automation Using Wireless Sensor Network

71

11. รอการตดตงโปรแกรม J2SE Runtime Environment 5.0

ภาพท ก-11 รอการตดตงโปรแกรม J2SE Runtime Environment 5.0

12. เสรจสนการตดตงโปรแกรม J2SE Runtime Environment 5.0 คลกปม Finish

ภาพท ก-12 เสรจสนการตดตงโปรแกรม J2SE Runtime Environment 5.0

Page 89: Build Automation Using Wireless Sensor Network

72

13. รอการตดตงโปรแกรม

ภาพท ก-13 รอการตดตงโปรแกรม

14. เสรจสนการตดตงโปรแกรม Cygwin คลกปม Finish

ภาพท ก-14 เสรจสนการตดตงโปรแกรม Cygwin

Page 90: Build Automation Using Wireless Sensor Network

73

การตดตงโปรแกรม Server (XAMPP 1.6.6a) 1. เรมตดตงโปรแกรมดบเบลคลกทไฟล xampp-win32-1.66a-installer.exe จากนนคลก Next

ภาพท ก-15 เรมตดตงโปรแกรม 2. เลอกตาแหนงทจะตดตงโปรแกรม ในทนตดตงไวทไดรฟ C

ภาพท ก-16 เลอกตาแหนงทจะตดตงโปรแกรม

Page 91: Build Automation Using Wireless Sensor Network

74

3. คลกเลอก Install Filezilla as service จากนนคลกท Install

ภาพท ก-17 เลอก Service

4. รอการตดตงโปรแกรม XAMPP 1.6.6a

ภาพท ก-18 ระหวางการตดตง

Page 92: Build Automation Using Wireless Sensor Network

75

5. เสรจสนการตดตงโปรแกรม XAMPP 1.6.6a ใหคลกปม Finish

ภาพท ก-19 การตดตงเสรจ

6. หลงจากคลกปม Finish โปรแกรมจะสแกนหา Ports ทจาเปนคอ 80 และ 3306

ภาพท ก-20 สแกนหา Ports ทจาเปน

Page 93: Build Automation Using Wireless Sensor Network

76

7. หลงจากโปรแกรมทาการตงคาเสรจ ใหคลกปม Yes เพอเขาส Control Panel

ภาพท ก-21 ตดตงสาเรจเขาส Control Panel

8. ท XAMPP Control Panel สามารถคลกปม Stop หรอ Start เพอเรมหรอหยดบรการของ Apache, MySql, FileZilla FTP Server และสามารถคลกปม Admin… เพอเขาสการจดการบรการของ Apache, MySql, FileZilla FTP Server

ภาพท ก-22 XAMPP Control Panel

Page 94: Build Automation Using Wireless Sensor Network

77

9. คดลอกไฟล config.inc.php ทไดแกไขไวแลวไปไวท C:\xampp\phpMyAdmin

ภาพท ก-23 ไฟล config.inc.php

10. เขาส MySql Admin ใหเอาเครองหมาย # ตรงขางหนา port = 3306 ออก เพอใชฐานขอมล MySql จากเครองอนผานเครอขายอนเตอรเนตได

ภาพท ก-24 MySql Admin

Page 95: Build Automation Using Wireless Sensor Network

78

11. การเขาส phpMyAdmin สามารถคลกท Apache Admin… หรอพมพ 127.0.0.1 ท Address ของ เบราเซอรไดเลย หลงจากนนใหเลอกเปนภาษาองกฤษ จากนนใหคลกท phpMyAdmin

ภาพท ก-25 การเขาส phpMyAdmin

12. ใส User Name และ Password จากนนคลกปม OK

ภาพท ก-26 Authentication Required

Page 96: Build Automation Using Wireless Sensor Network

79

13. เขาสหนา phpMyAdmin

ภาพท ก-27 phpMyAdmin

14. สรางฐานขอมล ชอวา tmote

ภาพท ก-28 สรางฐานขอมล

Page 97: Build Automation Using Wireless Sensor Network

80

15. ตวอยางการสรางตาราง tmote

ภาพท ก-29 สรางตาราง

16. ตวอยางการกาหนดคาตาราง tmote

ภาพท ก-30 ตวอยางการกาหนดคาตาราง

Page 98: Build Automation Using Wireless Sensor Network

81

17. แสดงตารางทงหมดในฐานขอมล tmote สามารถคลกชอตารางเพอเขาไปดโครงสรางของตาราง

ภาพท ก-31 ตารางทงหมดในฐานขอมล tmote

18. จากนนคลกทเบราเซอรเพอเขาไปดคาภายในตาราง

ภาพท ก-32 โครงสรางของตาราง tmote

Page 99: Build Automation Using Wireless Sensor Network

82

19. แสดงคาขอมลในตาราง tmote

ภาพท ก-33 ขอมลในตาราง tmote

20. การกาหนดสทธของ User ใหคลกท Privileges

ภาพท ก-34 การกาหนดสทธของ User

Page 100: Build Automation Using Wireless Sensor Network

83

21. คลกท Add a new User เพอสราง User ใหม

ภาพท ก-35 Add a new User 22. จากนนใสชอ User และ Password คลกท Check All จากนนคลกทปม Go เพอสราง User

ภาพท ก-36 การกรอก Username และ Password

Page 101: Build Automation Using Wireless Sensor Network

84

23. ท Add privileges on the following database เลอกชอตารางทจะให User tmote เขาไปใชงานได แลวคลกทปม Go

ภาพท ก-37 กาหนดตารางท User สามารถใชงานได

24. ใหคลกท Check All แลวคลกทปม Go

ภาพท ก-38 กาหนดการกระทาของ User ตอตารางนน

Page 102: Build Automation Using Wireless Sensor Network

85

25. เสรจสนการกาหนดสทธ

ภาพท ก-39 เสรจสนการกาหนดสทธ 26. ตวอยางการ Export ไฟล โดยคลกท Export ดานบน จากนนใหคลกเลอก Save as file และตง ชอไฟลโดยเลอกเปนชนด SQL จากนนคลกปม Go

ภาพท ก-40 ตวอยางการ Export ไฟล

Page 103: Build Automation Using Wireless Sensor Network

86

27. ตวอยางการ Import ไฟล โดยคลกท Import ดานบนเพอเลอกไฟลทจะ Import

ภาพท ก-41 ตวอยางการ Import ไฟล 28. ตวอยางโฟลเดอร xampp

ภาพท ก-42 ตวอยางโฟลเดอร xampp

Page 104: Build Automation Using Wireless Sensor Network

87

29. ตวอยางโฟลเดอร htdocs เอาไวใสไฟลเวบแอปพลเคชน

ภาพท ก-43 ตวอยางโฟลเดอร htdocs

Page 105: Build Automation Using Wireless Sensor Network

88

การตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1 1. ดบเบลคลกทไฟล easyeclipse-mobile-java-1.3.1.1.exe จากนนคลกปม Next

ภาพท ก-44 หนาแรกของการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1 2. คลกทปม I Agree

ภาพท ก-45 หนาแสดงขอตกลงอนญาตใชโปรแกรม easyeclipse-mobile-java-1.3.1.1

Page 106: Build Automation Using Wireless Sensor Network

89

3. เลอกโฟลเดอรทตองการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1 จากนนคลกปม Install

ภาพท ก-46 เลอกโฟลเดอรทตองการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1 4. รอการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1

ภาพท ก-47 รอการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1

Page 107: Build Automation Using Wireless Sensor Network

90

5. เสรจสนการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1 คลกปม Close

ภาพท ก-48 เสรจสนการตดตงโปรแกรม easyeclipse-mobile-java-1.3.1.1

Page 108: Build Automation Using Wireless Sensor Network

91

การตดตงโปรแกรม Sun Java Wireless Toolkit 1. ดบเบลคลกทไฟล sun_java_wireless_toolkit-2_5_1-windows.exe จากนนคลกปม Next

ภาพท ก-49 หนาแรกของการตดตงโปรแกรม sun_java_wireless_toolkit-2_5_1 2. คลกทปม Accept

ภาพท ก-50 หนาแสดงขอตกลงอนญาตใชโปรแกรม sun_java_wireless_toolkit-2_5_1

Page 109: Build Automation Using Wireless Sensor Network

92

3. เลอกตาแหนงทตองการตดตงโปรแกรม J2SE Development Kit จากนนคลกปม Next

ภาพท ก-51 เลอกตาแหนงทตองการตดตงโปรแกรม J2SE Development Kit 4. เลอกตาแหนงทตองการตดตงโปรแกรม Sun Java Wireless Toolkit จากนนคลกปม Next

ภาพท ก-52 เลอกตาแหนงทตองการตดตงโปรแกรม Sun Java Wireless Toolkit

Page 110: Build Automation Using Wireless Sensor Network

93

5. ทาการสรางชอโฟลเดอรโปรแกรมทจะทาการแสดงใน Start Menu Program จากนนคลกปม Next

ภาพท ก-53 ทาการสรางชอโฟลเดอรโปรแกรมทจะทาการแสดงใน Start Menu Program 6. หนาแจงเตอนการอพเดตเมอมโปรแกรมเวอรชนใหม ในกรณทตองการใหมการแจงเตอนให คลกเลอกท Check for Product Updates จากนนคลกปม Next

ภาพท ก-54 หนาแจงเตอนการอพเดตเมอมโปรแกรมเวอรชนใหม

Page 111: Build Automation Using Wireless Sensor Network

94

7. คลกปม Next เพอเรมทาการตดตงโปรแกรม

ภาพท ก-55 เรมทาการตดตงโปรแกรม 8. รอการตดตงโปรแกรม Sun Java Wireless Toolkit

ภาพท ก-56 รอการตดตงโปรแกรม Sun Java Wireless Toolkit

Page 112: Build Automation Using Wireless Sensor Network

95

9. เสรจสนการตดตงโปรแกรม Sun Java Wireless Toolkit คลกปม Finish

ภาพท ก-57 เสรจสนการตดตงโปรแกรม Sun Java Wireless Toolkit

Page 113: Build Automation Using Wireless Sensor Network

ภาคผนวก ข

การทดลองการทางานของโปรแกรมทใชในการทาโครงงาน

Page 114: Build Automation Using Wireless Sensor Network

97

การรนโปรแกรม OscopeRSSI 1. การตดตงโปรแกรม OscopeRssi ลงไปบน TmoteSky โดยพมพ ท opt/tinyos-1.x/apps/OscopeRssi (ใช TmoteSky 2 ตว)

make telosb make telosb reinstall,2 make telosb reinstall,3 ท opt/tinyos-1.x/apps/TOSBase (ใช TmoteInvent 1 ตว) make telosb

make telosb reinstall,1

ภาพท ข-1 การตดตงโปรแกรม OscopeRssi

Page 115: Build Automation Using Wireless Sensor Network

98

ภาพท ข-2 การตดตงโปรแกรม OscopeRssi (ตอ)

ภาพท ข-3 การตดตงโปรแกรม OscopeRssi (ตอ)

Page 116: Build Automation Using Wireless Sensor Network

99

2. ใชคาสง motelist เพอดวา Tmote อยพอรตใด

ภาพท ข-4 การใชคาสง motelist

3. จากนน ใชคาสง java net.tinyos.sf.SerialForwarder -comm serial@COM3:tmote เพอรนหนา แสดงผล

ภาพท ข-5 การใชคาสง java net.tinyos.sf.SerialForwarder

4. จากนนจะปรากฏหนาตางน

ภาพท ข-6 โปรแกรม SerialForwarder

Page 117: Build Automation Using Wireless Sensor Network

100

5. ทาการเปดหนาตาง Cygwin ขนมาใหม พมพ java net.tinyos.oscope.oscilloscope เพอทาการ ตดตอกบ oscilloscope

ภาพท ข-7 การใชคาสง java net.tinyos.oscope.oscilloscope

6. วธแสดงผล ใหกด Reset คาง 2 ตว จากนนกด Clear Dataset แลวกด reset จากนนปลอยมอ พรอมกน หรอ กด Clear Dataset ตวเดยวกได

ภาพท ข-8 รปตวอยางการวดสญญาณ

Page 118: Build Automation Using Wireless Sensor Network

101

ภาพท ข-9 ตวอยางคาทบนทกไดจากโปรแกรม OscopeRssi

Page 119: Build Automation Using Wireless Sensor Network

102

การรนโปรแกรม DTSR 1. โฟลเดอรโปรแกรม DTSR ททาการเขยนโคดไวอยท C:\cygwin\opt\moteiv\apps

ภาพท ข-10 โฟลเดอรโปรแกรม DTSR

2. แสดงไฟลตาง ๆ ในโปรแกรม DTSR

ภาพท ข-11 แสดงไฟลตาง ๆ ในโปรแกรม DTSR

Page 120: Build Automation Using Wireless Sensor Network

103

3. เรมรนโปรแกรม โดยเปดโปรแกรม Cygwin จากนนพมพ cd .. 2 ครง

ภาพท ข-12 เรมรนโปรแกรม

4. จากนนเขาไปทโฟลเดอร DTSR โดยพมพ cd opt/moteiv/apps/DTSR/

ภาพท ข-13 เขาไปทโฟลเดอร DTSR

5. จากนนคอมไพลโปรแกรม DTSR โดยพมพ make tmote

ภาพท ข-14 คอมไพลโปรแกรม DTSR

Page 121: Build Automation Using Wireless Sensor Network

104

6. ขณะคอมไพลจะขนรายละเอยดทงหมด โดยใชเวลาประมาณ 2-3 นาท

ภาพท ข-15 รายละเอยดการคอมไพล 8. พมพ motelist เพอดวาม Tmote ตออยหรอไม

ภาพท ข-16 motelist

Page 122: Build Automation Using Wireless Sensor Network

105

9. การลงโปรแกรม DTSR บน Tmote โดยพมพ make tmote reinstall, ตามดวยลาดบของ Tmote โดย 0 คอตวทตอกบเซรฟเวอร

ภาพท ข-17 การลงโปรแกรม DTSR บน Tmote

Page 123: Build Automation Using Wireless Sensor Network

106

การรนโปรแกรม DCDB 1. เรมรนโปรแกรม โดยเปดโปรแกรม Cygwin จากนนพมพ cd .. 2 ครง

ภาพท ข-18 เรมรนโปรแกรม Cygwin 2. พมพ motelist เพอดวาม Tmote ตออยหรอไม

ภาพท ข-19 motelist 3. จากนนเรมคอมไพลโปรแกรม DCDB โดยพมพ java net.tinyos.tools.DCDB tmote COM3

ภาพท ข-20 การทางานของโปรแกรม DCDB

Page 124: Build Automation Using Wireless Sensor Network

107

3. จะไดไฟลทไดรบการอานคาจากเซนเซอรมาเกบไวเปนไฟล Log Data

ภาพท ข-21 ไฟล Log Data ทไดจากโปรแกรม DCDB

Page 125: Build Automation Using Wireless Sensor Network

108

การรนโปรแกรม Sun Java Wireless Toolkit 2.5.1 for CLDC 1. เปดโปรแกรม Wireless Toolkit

ภาพท ข-22 โปรแกรม Wireless Toolkit

2. คลกท New Project เพอทาการสราง Project ทตองการ

ภาพท ข-23 การสราง Project ใน Wireless Toolkit

3. โปรแกรมเมอทาการสราง Project เสรจเรยบรอย

ภาพท ข-24 โปรแกรมเมอทาการสราง Project เสรจ

Page 126: Build Automation Using Wireless Sensor Network

109

4. จากนนเขาไปท C:\WTK2.5.1\apps\mobileWSN\src แลวทาการใสไฟลจาวาทตองการจาลอง การทางานลงไป

ภาพท ข-25 เขาไปทโฟลเดอร C:\WTK2.5.1\apps\mobileWSN\src

5. จากนนทาการ Build โปรแกรม mobileWSN โดยคลกทปม Build

ภาพท ข-26 การ Buildโปรแกรม mobileWSN

Page 127: Build Automation Using Wireless Sensor Network

110

6. คลกทปม Run เพอจาลองการทางานของโปรแกรม

ภาพท ข-27 การจาลองการทางานของโปรแกรม mobileWSN

Page 128: Build Automation Using Wireless Sensor Network

ภาคผนวก ค โคดโปรแกรมทใชในโครงงาน

Page 129: Build Automation Using Wireless Sensor Network

โคดโปรแกรม OscopeRssi ประกอบไปดวย 4 ไฟล ดงน 1. Makefile 2. OscopeRssi.h 3. OscopeRssi.nc 4. OscopeRssi M.nc 1. Makefile COMPONENT = OscopeRssiC PFLAGS += -I%T/../tos/lib/Oscope include $(MAKERULES) 2. OscopeRssi.h enum { AM_COUNTMSG = 4, RF_POWER = 31, }; typedef struct CountMsg { uint16_t n; uint16_t src; } CountMsg_t;

Page 130: Build Automation Using Wireless Sensor Network

3. OscopeRssi.nc includes OscopeRssi; configuration OscopeRssiC{ } implementation{ components Main, OscopeRssiM, TimerC, LedsC, GenericComm, OscopeC, CC2420RadioC; Main.StdControl -> GenericComm; Main.StdControl -> TimerC; Main.StdControl -> OscopeRssiM; Main.StdControl -> OscopeC; OscopeRssiM.Timer -> TimerC.Timer[unique("Timer")]; OscopeRssiM.Leds -> LedsC; OscopeRssiM.SendMsg -> GenericComm.SendMsg[AM_COUNTMSG]; OscopeRssiM.ReceiveMsg -> GenericComm.ReceiveMsg[AM_COUNTMSG]; OscopeRssiM.Oscope -> OscopeC.Oscope[0]; OscopeRssiM.CC2420Control -> CC2420RadioC; }

Page 131: Build Automation Using Wireless Sensor Network

4. OscopeRssi M.nc includes OscopeRssi; module OscopeRssiM{ provides interface StdControl; uses interface Timer; uses interface Leds; uses interface SendMsg; uses interface ReceiveMsg; uses interface Oscope; uses interface CC2420Control; } implementation{ uint16_t m_value; TOS_Msg m_msg; bool m_is_sending; command result_t StdControl.init() { m_value = 0; m_is_sending = FALSE; call Leds.init(); return SUCCESS; } command result_t StdControl.start() { call Timer.start( TIMER_REPEAT, 250 ); call CC2420Control.SetRFPower(RF_POWER); return SUCCESS;} command result_t StdControl.stop(){ return SUCCESS; }

Page 132: Build Automation Using Wireless Sensor Network

void sendValue( uint16_t value ){ if( m_is_sending == FALSE ) { CountMsg_t* body = (CountMsg_t*) m_msg.data; body->n = value; body->src = TOS_LOCAL_ADDRESS; if( call SendMsg.send (TOS_BCAST_ADDR,sizeof(CountMsg_t),&m_msg) == SUCCESS ) {m_is_sending = TRUE;} } } task void processStrength(){ uint16_t leds = m_value >> 4; call Leds.set( leds ); call Oscope.put(m_value); } event result_t Timer.fired(){ sendValue( m_value ); return SUCCESS; } event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t result){ m_is_sending = FALSE; return SUCCESS; } event TOS_MsgPtr ReceiveMsg.receive( TOS_MsgPtr msg ){ m_value = (msg->strength + 60) & 0xff; post processStrength(); return msg;} }

Page 133: Build Automation Using Wireless Sensor Network

โคดโปรแกรม DTSR ประกอบไปดวย ไฟล ดงน 1. Makelocal 2.Makefile 3. Delta.h 4. Delta.nc 5. DeltaM.nc 1. Makelocal DEFAULT_LOCAL_GROUP = 0x7D 2.Makefile COMPONENT = Delta MOTEIV_DIR ?= ../../ ifeq ($(filter lowpower,$(MAKECMDGOALS)),lowpower) IDENT_PROGRAM_NAME = DSMLowpower endif CFLAGS += -DTOSH_DATA_LENGTH=28+3*2+2 -DMHOP_DEFAULT_QUEUE_SIZE=50 include $(MAKERULES)

Page 134: Build Automation Using Wireless Sensor Network

3. Delta.h #ifndef H_Delta_h #define H_Delta_h #include "MultiHop.h" #define DELTA_QUEUE_SIZE

MHOP_DEFAULT_QUEUE_SIZE - MHOP_DEFAULT_QUEUE_SIZE >> 2) enum { DELTA_TIME = 1024 * 31,

RF_POWER = 31 }; enum { AM_DELTAMSG = 33 }; typedef struct DeltaMsg {

uint32_t seqno; uint16_t reading1; uint16_t reading2; uint16_t reading3; uint16_t parent; uint8_t neighborsize; uint8_t retransmissions; uint16_t neighbors[MHOP_PARENT_SIZE]; uint16_t quality[MHOP_PARENT_SIZE];

} DeltaMsg; #endif

Page 135: Build Automation Using Wireless Sensor Network

4. Delta.nc #include "Delta.h" configuration Delta { } implementation {

components Main; components MultiHop , DeltaM as Impl , TimerC , LedsC , InternalTempC,

HamamatsuC, ADCC, CC2420RadioC; Main.StdControl -> MultiHop; Main.StdControl -> TimerC; Main.StdControl -> InternalTempC; Main.StdControl -> Impl; Main.StdControl -> HamamatsuC; Impl.Timer -> TimerC.Timer[unique("Timer")]; Impl.TimerBlink -> TimerC.Timer[unique("Timer")]; Impl.TSRADC -> HamamatsuC.TSR; Impl.PARADC -> HamamatsuC.PAR; Impl.InternalTempADC -> InternalTempC; Impl.CC2420Control -> CC2420RadioC; // send data messages Impl.SendDeltaMsg -> MultiHop.Send[AM_DELTAMSG]; // monitor traffic being forwarded Impl.SnoopDeltaMsg -> MultiHop.Intercept[AM_DELTAMSG]; // get statistics about current operation Impl.RouteControl -> MultiHop; Impl.RouteStatistics -> MultiHop; // pretty LEDs Impl.Leds -> LedsC;

}

Page 136: Build Automation Using Wireless Sensor Network

5. DeltaM.nc #include "Delta.h" #include "circularQueue.h" module DeltaM { provides { interface StdControl; } uses {

interface Send as SendDeltaMsg; interface Intercept as SnoopDeltaMsg; interface RouteControl; interface RouteStatistics; interface CC2420Control; interface ADC as TSRADC; interface ADC as PARADC; interface ADC as InternalTempADC; interface Timer; interface Timer as TimerBlink; interface Leds; }

} implementation { /************************* VARIABLES *******************************/

uint16_t m_adc_TSR; uint16_t m_adc_PAR; uint16_t m_adc_InternalTemp; uint32_t m_seqno; TOS_Msg msg[DELTA_QUEUE_SIZE]; CircularQueue_t queue;

/************************* HELPER FUNCTIONS ************************/ task void sendData() {

uint16_t _length;

Page 137: Build Automation Using Wireless Sensor Network

int i; uint16_t neighbors[MHOP_PARENT_SIZE]; uint16_t quality[MHOP_PARENT_SIZE]; if (cqueue_pushBack( &queue ) == SUCCESS) {

DeltaMsg* dmsg = (DeltaMsg*)call SendDeltaMsg.getBuffer(&msg[queue.back], &_length); atomic dmsg->reading1 = m_adc_TSR; atomic dmsg->reading2 = m_adc_PAR; atomic dmsg->reading3 = m_adc_InternalTemp; dmsg->parent = call RouteControl.getParent(); call RouteStatistics.getNeighbors(neighbors, MHOP_PARENT_SIZE); call RouteStatistics.getNeighborQuality(quality, MHOP_PARENT_SIZE); for (i = 0; i < MHOP_PARENT_SIZE; i++) {

dmsg->neighbors[i] = neighbors[i]; dmsg->quality[i] = quality[i]; }

dmsg->neighborsize = MHOP_PARENT_SIZE; dmsg->retransmissions = call RouteStatistics.getRetransmissions(); dmsg->seqno = m_seqno; if (call SendDeltaMsg.send( &msg[queue.back], sizeof(DeltaMsg) ) == SUCCESS) { call Leds.redOn();} else { cqueue_popBack( &queue ); }

} m_seqno++;

} void blinkBlue() {

call Leds.yellowOn(); call TimerBlink.start(TIMER_ONE_SHOT, 20); }

/************************* STD CONTROL *****************************/ command result_t StdControl.init() {

Page 138: Build Automation Using Wireless Sensor Network

cqueue_init( &queue, DELTA_QUEUE_SIZE ); return SUCCESS; }

command result_t StdControl.start() { call Timer.start( TIMER_REPEAT, DELTA_TIME ); call CC2420Control.SetRFPower(RF_POWER, RF_POWER); return SUCCESS; }

command result_t StdControl.stop() { return SUCCESS; } /************************* TIMER ***********************************/ event result_t Timer.fired() {

call TSRADC.getData(); return SUCCESS;

} event result_t TimerBlink.fired() {

call Leds.yellowOff(); return SUCCESS;

} /************************* ADC *************************************/ async event result_t TSRADC.dataReady(uint16_t data) {

m_adc_TSR = data; call PARADC.getData(); return SUCCESS;

} async event result_t PARADC.dataReady(uint16_t data) {

m_adc_PAR = data; call InternalTempADC.getData(); return SUCCESS;

} async event result_t InternalTempADC.dataReady(uint16_t data) {

m_adc_InternalTemp = data; post sendData();

Page 139: Build Automation Using Wireless Sensor Network

call Leds.greenOn(); return SUCCESS;

} /************************* SEND ************************************/ event result_t SendDeltaMsg.sendDone(TOS_MsgPtr _msg, result_t _success) {

cqueue_popFront( &queue ); if (cqueue_isEmpty( &queue )) { call Leds.redOff(); call Leds.greenOff(); } return SUCCESS;

} event result_t SnoopDeltaMsg.intercept(TOS_MsgPtr _msg, void* payload, uint16_t payloadLen) {

blinkBlue(); return SUCCESS; }

}

Page 140: Build Automation Using Wireless Sensor Network

โคดโปรแกรม DCDB ประกอบไปดวย 1 ไฟล ดงน DCDB.java package net.tinyos.tools; import java.util.*; import java.io.*; import javax.comm.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import net.tinyos.util.*; import net.tinyos.message.*; import java.sql.*; class StatArray { String startTime; int[] msgSentBegin = new int[1025]; int[] msgSentEnd = new int[1025]; int[] msgRecv = new int[1025]; void setMsgSentBegin(int index, int value) {msgSentBegin[index] = value;} void setMsgSentEnd(int index, int value) {msgSentEnd[index] = value;} void setMsgRecv(int index, int value) {msgRecv[index] = value;} int getMsgSentBegin(int index) {return msgSentBegin[index];} int getMsgSentEnd(int index) {return msgSentEnd[index];} int getMsgRecv(int index) {return msgRecv[index];} void setStartTime(String str) {startTime = str;} String getStartTime() {return startTime;} } public class DCDB { private static String FILE_NAME = "DCDB.txt"; private static String CLASS_NAME = "net.tinyos.tools.DCDB";

Page 141: Build Automation Using Wireless Sensor Network

private static final int MAX_MSG_SIZE = 36; private static final int PORT_SPEED_MICA2 = 57600; private static final int PORT_SPEED_MICA2DOT = 19200; private static final int PORT_SPEED_MICA = 19200; private static final int PORT_SPEED_RENE = 19200; private static final int LENGTH_OFFSET = 4; private int packetLength; private int portSpeed; private CommPortIdentifier portId; private SerialPort port; private String portName; private InputStream in; private OutputStream out; static StatArray statArray = new StatArray(); public DCDB(String portName, int portSpeed) { this.portName = portName; this.portSpeed = portSpeed; } public void open() throws NoSuchPortException, PortInUseException, IOException, UnsupportedCommOperationException { //Print Header of log file System.out.println("\r\n \r\n------- Building Automation Using Wireless Sensor network -------- \r\n \r\n"); System.out.println("------- King Mongkut University of Technology Notrh Bangkok ------- \r\n"); System.out.println("---------------- Electrical Engineering Department ---------------- \r\n \r\n"); System.out.println("----- DCDB Program Receive Data from DTSR and Connect Database ----- \r\n \r\n \r\n");

Page 142: Build Automation Using Wireless Sensor Network

System.out.println("Opening port " + portName); portId = CommPortIdentifier.getPortIdentifier(portName); port = (SerialPort)portId.open(CLASS_NAME, 0); in = port.getInputStream(); out = port.getOutputStream(); port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE); port.disableReceiveFraming(); //printPortStatus(); // These are the mote UART parameters port.setSerialPortParams(portSpeed, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); printPortStatus(); System.out.println(); } private void printPortStatus() { System.out.println(" baud rate: " + port.getBaudRate()); System.out.println(" data bits: " + port.getDataBits()); System.out.println(" stop bits: " + port.getStopBits()); System.out.println(" parity: " + port.getParity()); } private static void printAllPorts() { Enumeration ports = CommPortIdentifier.getPortIdentifiers(); if (ports == null) { System.out.println("No comm ports found!"); return; } // print out all ports System.out.println("printing all ports...");

Page 143: Build Automation Using Wireless Sensor Network

while (ports.hasMoreElements()) { System.out.println(" " + (CommPortIdentifier)ports.nextElement()).getName());} } //Function convert base16 to base10 private static int convHexToDec(Character input) { switch (input){ case '0' : return 0; case '1' : return 1; case '2' : return 2; case '3' : return 3; case '4' : return 4; case '5' : return 5; case '6' : return 6; case '7' : return 7; case '8' : return 8; case '9' : return 9; case 'A' : return 10; case 'B' : return 11; case 'C' : return 12; case 'D' : return 13; case 'E' : return 14; case 'F' : return 15; case 'a' : return 10; case 'b' : return 11; case 'c' : return 12; case 'd' : return 13; case 'e' : return 14; case 'f' : return 15; default : return 0; } }

Page 144: Build Automation Using Wireless Sensor Network

public void read() throws IOException { int i,j = 0; int id,recv,sent,Num_package,No_1,No_2,d1,d2,d3,er2=0,er1=0,Quality,Parent,t=0,s=0, r=0,v=0; double D1Double,D2Double,D3Double; float D1,D2,D3; byte[] packet = new byte[MAX_MSG_SIZE]; String strData = ""; strData = ""; while ((i = in.read()) != -1) { if (i == 0x7e) { if (strData.length()>142) { // Get Data And Parameter From Message id = (convHexToDec(strData.charAt(48))*16) + convHexToDec(strData.charAt(49)); Num_package = (convHexToDec(strData.charAt(75))*16*16*16) + (convHexToDec(strData.charAt(76))*16*16) + (convHexToDec(strData.charAt(72))*16) + convHexToDec(strData.charAt(73)); No_1=(convHexToDec(strData.charAt(60))*16*16*16) + (convHexToDec(strData.charAt(61))*16*16) + (convHexToDec(strData.charAt(57))*16) + convHexToDec(strData.charAt(58)); No_2=(convHexToDec(strData.charAt(16))*16*16*16) + (convHexToDec(strData.charAt(17))*16*16) + (convHexToDec(strData.charAt(54))*16) + convHexToDec(strData.charAt(55) d1=(convHexToDec(strData.charAt(87))*16*16*16) + (convHexToDec(strData.charAt(88))*16*16) + (convHexToDec(strData.charAt(84))*16) + convHexToDec(strData.charAt(85)); d2=(convHexToDec(strData.charAt(93))*16*16*16) + (convHexToDec(strData.charAt(94))*16*16) + (convHexToDec(strData.charAt(90))*16) + convHexToDec(strData.charAt(91));

Page 145: Build Automation Using Wireless Sensor Network

d3=(convHexToDec(strData.charAt(99))*16*16*16) + (convHexToDec(strData.charAt(100))*16*16) + (convHexToDec(strData.charAt(96))*16) + convHexToDec(strData.charAt(97)); //Calculate to normal unit D1Double=(d1*150000/65535); D2Double=(d2*150000/65535); D3Double=((((d3/4096.0)*1.5)-0.986)/0.00355)-5.0; D1 = (float) D1Double; D2 = (float) D2Double; D3 = (float) D3Double; Quality=(convHexToDec(strData.charAt(135))*16*16*16)+ (convHexToDec(strData.charAt(136))*16*16) + (convHexToDec(strData.charAt(133))*16) + convHexToDec(strData.charAt(134)); Parent=(convHexToDec(strData.charAt(120))*16)+convHexToDec(strData.charAt(121)); if (id>0){ sent = (convHexToDec(strData.charAt(75))*16*16*16) +

(convHexToDec(strData.charAt(76))*16*16) + convHexToDec(strData.charAt(72))*16) + convHexToDec(strData.charAt(73));

if (statArray.getMsgSentBegin(id)==-1){ statArray.setMsgSentBegin(id,sent);} if (sent != statArray.getMsgSentEnd(id)) { DateFormat dfm = new SimpleDateFormat("-MM-dd HH:mm:ss"); dfm.setTimeZone(TimeZone.getTimeZone("GMT+7")); SimpleDateFormat("YYYY:MM:DD:HH:mm:ss"); PrintWriter fileoutput = null; try { fileoutput = new PrintWriter(new BufferedWriter(new FileWriter(FILE_NAME,true))); //APPEND

Page 146: Build Automation Using Wireless Sensor Network

fileoutput = new PrintWriter(new BufferedWriter(new FileWriter(FILE_NAME,true))); //write next } catch (IOException ioe) { ioe.printStackTrace(); } System.out.print("2008"+dfm.format(System.currentTimeMillis())+" : "); if(j==0){fileoutput.write("Log Data From DCDB start at 2008" + dfm.format(System.currentTimeMillis())+"\r\n");} if (Num_package==5){ fileoutput.write("2008"+dfm.format(System.currentTimeMillis())+" : "+"Mote"+id+" Connect complete \r\n");} // Function JDBC Connect and Put Data to Database Connection connection = null; try { String driverName = "com.mysql.jdbc.Driver"; Class.forName(driverName); String serverName = "202.44.37.232"; if(j==0){fileoutput.write("Connect to "+serverName+ "\r\n"); System.out.print("Connect to "+serverName+"\r\n");} String mydatabase = "tmote";

String url = "jdbc:mysql://" + serverName + "/" + mydatabase; url += "?useUnicode=true&characterEncoding=utf-8"; String username = "tmote"; String password = "tmote"; String sqltimes =dfm.format(System.currentTimeMillis()); connection = DriverManager.getConnection(url, username, password); Statement stmt = connection.createStatement(); if (((D3<100)&&(D2<2000)&&(D1<2000))&&((D3>(-50))&&(D2> (-100))&&(D1>(-100)))){ int rset =stmt.executeUpdate("INSERT INTO

Page 147: Build Automation Using Wireless Sensor Network

`tmote` (`no`, `moteid`, `room`,`time`, `reading1`, `reading2`, `reading3`, `reading4`, `comment`) VALUES (NULL ,'"+"mote"+id+"' ,'Lab_Commu' , '"+"2008"+sqltimes+"' , '"+D1+"', '"+D2+"', '"+D3+"' , '"+Quality+"' , 'OK')");} else{ int rset =stmt.executeUpdate("INSERT INTO `tmote` (`no` ,`moteid` ,`room` ,`time` ,`reading1` ,`reading2` ,`reading3` ,`reading4` ,`comment`) VALUES (NULL ,'"+"mote"+id+"' ,'Lab_Commu' , '"+"2008"+sqltimes+"' , '"+D1+"', '"+D2+"', '"+D3+"' , '"+Quality+"' , 'Packet Error')"); } If (j==0){System.out.print("Connect to Database Success ... \r\n\r\n"); fileoutput.write("Connect to Database Success ... \r\n\r\n"); } stmt.close(); connection.close(); } catch (ClassNotFoundException e) { fileoutput.write("Can't Find JDBC Driver for connect Database : "+e+" \r\n"); System.out.print("Can't Find JDBC Driver for connect Database : "+e+" \r\n"); } catch (SQLException e) { fileoutput.write("Can't Connect Database : "+e+" \r\n"); System.out.print("Can't Connect Database : "+e+" \r\n");

} if (((D3>100)||(D2>2000)||(D1>2000))||((D3<(-50))||(D2<(-100))||(D1<(-100)))) { System.out.print("2008"+dfm.format(System.currentTimeMillis())+" : Data Packet Form mote"+id+" -- Error --!!!!! \r\n");

Page 148: Build Automation Using Wireless Sensor Network

fileoutput.write("2008"+dfm.format(System.currentTimeMillis())+" : Data Packet Form mote"+id+" -- Error --!!!!! \r\n "); //Data= +strData+"\r\n"); } j++; fileoutput.flush(); fileoutput.close(); System.out.println("Packet from mote"+id+" process Complete... Wating new packet...\r\n"); }

} } strData = ""; } if (i<16){strData += "0" + Integer.toHexString(i).toUpperCase() + "\t";} else {strData += Integer.toHexString(i).toUpperCase() + "\t";}

} } private static void printUsage() { System.err.println("usage: java net.tinyos.tools.DCDB [options] <port>"); System.err.println("options are:"); System.err.println(" -h, --help: usage help"); System.err.println(" -p: print available ports"); System.err.println(" -mica2: Mica2 ("+PORT_SPEED_MICA2+" bps) [default]"); System.err.println(" -mica2dot: Mica2Dot ("+PORT_SPEED_MICA2DOT+" bps)"); System.err.println(" -mica: Mica ("+PORT_SPEED_MICA+" bps)"); System.err.println(" -rene: Rene ("+PORT_SPEED_RENE+" bps)"); System.exit(-1); }

Page 149: Build Automation Using Wireless Sensor Network

static void saveToFile() {} public static void main(String args[]) { int speed = PORT_SPEED_MICA2; if ((args.length < 1) || (args.length > 3)) {printUsage();} for (int i = 0; i < args.length; i++) { if (args[i].equals("-h") || args[i].equals("--help")) {printUsage();} if (args[i].equals("-p")) {printAllPorts();} if (args[i].equals("-mica2")) {speed = PORT_SPEED_MICA2;} if (args[i].equals("-mica2dot")) {speed = PORT_SPEED_MICA2DOT;} if (args[i].equals("-mica")) {speed = PORT_SPEED_MICA;} if (args[i].equals("-rene")) {speed = PORT_SPEED_RENE;} } if (args[args.length - 1].charAt(0) == '-') {return; // No port specified} System.out.println("DCDB WSN"); for (int i = 1; i < 1025; i++){statArray.setMsgSentBegin(i,-1);} DCDB reader = new DCDB(args[args.length - 1], speed); try { reader.open();} catch (Exception e) {e.printStackTrace();} DateFormat dfm = new SimpleDateFormat("yyyy:MM:DD:HH:mm:ss"); statArray.setStartTime(dfm.format(System.currentTimeMillis())); try { reader.read();} catch (Exception e) {e.printStackTrace();} } }

Page 150: Build Automation Using Wireless Sensor Network

โคดโปรแกรม Web Application ประกอบไปดวย ไฟล ดงน 1. Add_mem.php 2. addRegister.php 3. Admin.php 4. checkLogin.php 5. Config.inc.php 6. Contact_us.php 7. Edit_mem.php 8. export_csv.php 9. Floor3.php 10. Floor4.php 11. Graph.php 12. home.php 13. index.php 14. Loguot.php 15. object.php 16. pictograph.php 17. Register.php 18. Remove_mem.php 19. Show_mem.php 20. tmoterealtime.php 21. tmotestatistic.php 22. My (C:\xampp\mysql\bin)

Page 151: Build Automation Using Wireless Sensor Network

1. Add_mem.php <? session_start(); ?> <?php if($_SESSION["status"]!="Admin") echo"<meta http-equiv=Refreshontent='1;URL=index.php'>";?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <title>Add</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript">

<!-- if (document.images)

{ image1 = new Image(131, 33); image1.src = "images/top_nav_small_tab_hover.gif"; }

//--> </script> <style type="text/css"> <!-- .style1 {color: #F4F4F4} .style2 {font-size: 14} .style3 {font-size: 14px}

Page 152: Build Automation Using Wireless Sensor Network

--> </style> <script language="Javascript">

<!-- Begin function resetform() { document.forms[0].elements[1]==""; } function submitForms() { if (isName() && isEmail() && isUser() && isPass() && isPicture() ) alert("Thank you for Register"); else return false; } function isName() { if (document.forms[0].Name.value == "") { alert ("\n The Name field is blank. \n\n Please enter your name.") document.forms[0].Name.focus(); return false; } return true; } function isEmail() { if (document.forms[0].Email.value == "") { alert ("\n The E-Mail field is blank. \n\n Please enter your E-Mail address.") document.forms[0].Email.focus(); return false; } if (document.forms[0].Email.value.indexOf ('@',0) == -1 || document.forms[0].Email.value.indexOf ('.',0) == -1) {

Page 153: Build Automation Using Wireless Sensor Network

alert ("\n The E-Mail field requires a \"@\" and a \".\"be used. \n\nPlease re-enter your E-Mail address.")

document.forms[0].Email.select(); document.forms[0].Email.focus(); return false; } return true; } function isUser() { if (document.forms[0].User.value == "") {

alert ("\n The Username Name field is blank. \n\nPlease enter your user name.")

document.forms[0].User.focus(); return false; } if (document.forms[0].User.value.length<6) {

alert ("\n The Username must be 6 character at least. \n\nPlease enter your password.")

document.forms[0].User.focus(); return false; } return true; } function isPass() { if (document.forms[0].Password.value.length<6) {

alert ("\n The Password must be 6 character at least. \n\nPlease enter your password.")

document.forms[0].Password.focus();

Page 154: Build Automation Using Wireless Sensor Network

return false; } if (document.forms[0].elements[4].value == "") { alert ("\n The Password field is blank. \n\nPlease enter your password.") document.forms[0].elements[4].focus(); return false; } if (document.forms[0].elements[5].value == "") { alert ("\n The Password field is blank. \n\nPlease enter your password.") document.forms[0].elements[5].focus(); return false; } if (document.forms[0].elements[4].value != document.forms[0].elements[5].value) { alert ("\n The password are unmatch. \n\nPlease insert password again.") document.forms[0].elements[4].focus(); return false; } return true; } function isPicture() { if (document.forms[0].elements[6].value == "") { alert ("\n The Picture field is blank. \n\nPlease select your picture.") document.forms[0].elements[6].focus(); return false; } if (document.forms[0].elements[6].value.indexOf ('.jpg',0) == -1 && document.forms[0].elements[6].value.indexOf ('.png',0) == -1 && document.forms[0].elements[6].value.indexOf ('.gif',0) == -1)

Page 155: Build Automation Using Wireless Sensor Network

{ alert ("\n The Picture is invalid. \n\nPlease select your picture type as jpg, gif, png.")

document.forms[0].elements[6].focus(); return false; } return true; }

--> </script> </head> <body> <ul id="topnav"> <li><a href="home.php" class="smalltab">Home</a></li> <li class="bigtab" ><a href="Admin.php">Admin</a></li> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li> <li><a href="tmotestatistic.php" class="smalltab">Statistic</a></li> <li><a href="floor3.php" class="smalltab">Floor 3</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li> </ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img s rc="images/main_content_header_900.gif" width=900 height=3> <div id="container"><br>

<form name=infoGuest action="addRegister.php" method="post" nctype="multipart/form-data" onSubmit="return submitForms()">

Page 156: Build Automation Using Wireless Sensor Network

<table align="center" > <th align="center" colspan="2"><font color=#800040> </font><font size="5"color="black">Please Enter Informations For Register</font></th> <tr>

<td align="right" ><font color="#fa6627" size="4">Name</font><font color="black" size="4">*<font color="#fa6627" size="4">

:</font> <td align="left"><input type="text" name="Name">

</tr> <tr> <td align="right" ><font color="#fa6627" size="4">Address : </font> <td align="left"><font color="#fa6627" size="4"> <input type="text" name="Address" ></font> </tr> <tr>

<td align="right" ><font color="#fa6627" size="4">Email</font><font color="black" size="4">*<font color="#fa6627" size="4"> :

</font> <td align="left"><font color="#fa6627" size="4">

<input type ="text" name="Email">/font><td> </tr> <tr> <td align="right" ><font color="#fa6627" size="4">Username</font><font

color="black" size="4">*<font color="#fa6627" size="4"> : </font> <td align="left"><font color="#fa6627" size="4"> <input type="text" name="User"><font color="#fa6627" size="3">

must be 6 character at least</font> </tr> <tr>

Page 157: Build Automation Using Wireless Sensor Network

<td align="right"><font color="#fa6627" size="4">Password</font><font color="black" size="4">*<font color="#fa6627" size="4"> :

</font> <td align="left"><font color="#fa6627" size="4"> <input type="password" name="Password" ><font color="#fa6627"

size="3"> must be 6 character at least</font> </tr> <tr> <td align="right" ><font color="#fa6627" size="4">Confirm

Password</font><font color="black" size="4">*<font color="#fa6627" size="4"> :

</font> <td align="left"><font color="#fa6627" size="4"> <input type="password" name="Confirm" ><td></font>

</tr> <tr> <td align="right"><font color="#fa6627" size="4">Picture</font><font

color="black" size="4">*<font color="#fa6627" size="4"> : </font> <td align="left"><font color="#fa6627" size="4"></font><td>

<input type="file" name="Picture"> </tr> <tr> <td align="right"> <font color="#fa6627" size="4"> status : <td align="left"><select name='status'> <option value='User'>Admin</option> <option value='User'>User</option> </select></font><td>

</tr>

Page 158: Build Automation Using Wireless Sensor Network

<tr> <td colspan="2" align="center"><br> <font color="#fa6627" size="4 <input type="submit" value="Submit"> <input type="reset" value="Clear"></font><br><br>

</tr> </table>

<p id="footer">By <a href="contact_us.php">Smart Building Group</a></p> </body> </html>

Page 159: Build Automation Using Wireless Sensor Network

2. addRegister.php <? session_start(); include('config.inc.php'); $Name = $_POST["Name"]; $Email = $_POST["Email"]; $User = $_POST["User"]; $Password = $_POST["Password"]; $Address = $_POST["Address"]; $Motename = $_POST["Motename"]; $Picture = $_POST["Picture"]; $status = $_POST["status"]; ?> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <? if(!$Name&&!$Email&&!$User&&!$Password&&!$Picture&&!$status)

{ echo "<center>error <p><a href=\"javascript:history.back(1)\">Back</a></center> ";

return false; }

$query = "SELECT * FROM member WHERE username='$User'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); if ( ($result) && (mysql_num_rows($result) > 0) ){ $row=mysql_fetch_array($result);

echo "<center>มคนใช username > $row[usenamer] แลว กรณาทาการลงทะเบยนใหม <p><a href=\"javascript:history.back(1)\">กลบไปหนาทแลว</a></center> ";

return false; }

Page 160: Build Automation Using Wireless Sensor Network

$filename=basename($_FILES['Picture']['name']);

if (preg_match("/jpg/i",$filename)){ $filetype=".jpg"; } else if (preg_match("/png/i",$filename)){ $filetype=".png"; } else if (preg_match("/gif/i",$filename)){ $filetype=".gif"; } $path = "Picture/"; $path = $path.$User.$filetype;

{?> <table align=center>

<th align=center colspan=2><font color="#fa6627" >สมครสมาชกเรยบรอยแลว โดยมขอมลดงน</font>

tr> <td>ชอ : <td> <? echo $Name ?> </tr> <tr> <td>อเมล : <td> <?echo $Email ?> </tr> <tr> <td> ชอลอกอน : <td> <?echo $User ?> </tr> <tr> <td> Picture : <td> <?echo $path ?> </tr> <tr> <td>status : <td> <? echo $status ?>

Page 161: Build Automation Using Wireless Sensor Network

</tr> <?} if (is_uploaded_file($_FILES['Picture']['tmp_name'])){ if(move_uploaded_file($_FILES['Picture']['tmp_name'],$path)){ print "<center><br>Upload Filename: ".$_FILES['Picture']['name']."

Success</center><br>"; } else print "<center>Upload not Success</center>"; } $sql="INSERT INTO `member` (`userid` ,`username` ,`password` ,`name` ,`address` ,`email` ,`path` ,`status` ,`motename`) VALUES(NULL,'$User', '$Password','$Name', '$Address', '$Email', '$path','$status','$Motename')"; mysql_query($sql) or die ("Error in query: $query. " . mysql_error()); echo"<p align=center>เพมขอมลผใชลงในฐานขอมลเรยบรอยแลว </p>"; echo "<p align=center><a href = Admin.php>กลบหนาหลก</a>” ; if($_SESSION["status"] == "Admin") echo "<meta http-equiv='Refresh' content='3; URL=Admin.php'>"; if($_SESSION["status"] == "User") echo "<meta http-equiv='Refresh' content='3; URL=home.php'>"; mysql_close(); ?>

Page 162: Build Automation Using Wireless Sensor Network

3. Admin.php <? session_start(); ?> <?php if($_SESSION["status"]!="Admin") echo"<meta http-equiv=Refresh

content='1;URL=index.php'>";?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <title>Administrator Sections</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!-- if (document.images) { image1 = new Image(131, 33); image1.src = "images/top_nav_small_tab_hover.gif";

} //--> </script> <style type="text/css"> <!-- .style1 {color: #F4F4F4} .style2 {font-size: 14} .style3 {font-size: 14px} --> </style> </head>

Page 163: Build Automation Using Wireless Sensor Network

<body> <ul id="topnav"> <li><a href="home.php" class="smalltab">Home</a></li> <li class="bigtab" ><a href="#">Admin</a></li> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li> <li><a href="tmotestatistic.php" class="smalltab">Statistic</a></li> <li><a href="floor3.php" class="smalltab">Floor 3</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li> </ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img src="images/main_content_header_900.gif" width=900 height=3> <div id="container"> <table align=center width=500>

<tr> <td><font size="6" color="black"><br>Administrator

Sections</font></p><hr><br> </tr> <tr>

<td align=left><a href="Add_mem.php"><font size=4 color="#fa6627"><u>- Add

User</u></a> </tr> <tr>

<td align=left><br><a href="Show_mem.php"><font size=4 color="#fa6627"><u>-

Page 164: Build Automation Using Wireless Sensor Network

Show members</u></a></tr> <tr>

<td align=left><br><a href="http://mobile.ee.kmitnb.ac.th/phpmyadmin/" target="_blank"><font size=4 color="blue"><u>- Database Maneger (PHP Myadmin)</u></a>

</tr> </table></font> <br><br> <img src="images/tmoteskygolf.jpg" width=400 height=260><br><br></center> <p id="footer">By <a href="contact_us.php">Smart Building Group</a></p> </body> </html>

Page 165: Build Automation Using Wireless Sensor Network

4. checkLogin.php <? session_start(); echo "<pre>"; $login = $_POST["login"]; $pw = $_POST["pw"]; include('config.inc.php'); // ตดตอกบฐานขอมล $sql = "select * from member where username='$login' and password='$pw' "; $dbquery = mysql_query($sql); $num_rows = mysql_num_rows($dbquery); if($num_rows==1){ print"<p align=center>username และ password ถกตอง</p>"; $row=mysql_fetch_array($dbquery); $_SESSION["userid"] = $row["userid"]; $_SESSION["status"] = $row["status"]; if($_SESSION["status"]=="Admin") { print "<p align=center><a href=Admin.php>Admin</a></p>"; print "<meta http-equiv='Refresh' content='0; URL=Admin.php'>"; } else { print "<p align=center><a href=home.php>Home</a></p>"; print "<meta http-equiv='Refresh' content='0; URL=home.php'>"; } } else { $code_error="<body bgcolor=black><font size=4 color=#fa6627>ขอมลไมถกตอง กรณา

Login ใหมอกครง</font>"; session_register("code_error"); print "<p align=center>".$code_error."</p>" ; print "<center><a href=index.php>Login</a></center>";

Page 166: Build Automation Using Wireless Sensor Network

print "<meta http-equiv='Refresh' content='5; URL=index.php'>"; } ?>

Page 167: Build Automation Using Wireless Sensor Network

5. Config.inc.php <?php ob_start(); $host = "127.0.0.1"; $user = "tmote"; $passwd = "tmote"; $dbname = "tmote"; $db = mysql_connect($host,$user,$passwd) or die("ตดตอ Host ไมได"); mysql_select_db($dbname,$db) or die("ตดตอฐานขอมลไมได"); $viewmempage = 20; ?>

Page 168: Build Automation Using Wireless Sensor Network

6. Contact_us.php <? session_start(); if($_SESSION["userid"]==""){ echo"<meta http-equiv=Refresh content='1;URL=index.php'>"; return fault; }?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <title>Contact us</title> <link href="style_page.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!-- if (document.images){ image1 = new Image(131, 33); image1.src = "images/top_nav_small_tab_hover.gif"; } //--> </script> </head> <body> <ul id="topnav"> <li><a href="home.php" class="smalltab">Home</a></li> <? if($_SESSION["status"] == "Admin") echo "<li><a href=admin.php class=smalltab>Admin</a></li>" ?> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li> <li><a href="tmotestatistic.php" class="smalltab">Statistic</a></li>

Page 169: Build Automation Using Wireless Sensor Network

<li><a href="floor3.php" class="smalltab">Floor3</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li class=bigtab><a href=contact_us.php >Contact Us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li> </ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img src="images/main_content_header_900.gif" width=900 height=3> <div id="container"> <div id="right"> <img src="images/contacusheader.jpg" alt="slogan" width="900" height="265" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="14,9,158,263" href="mailto:[email protected]" alt="Pump" /> <area shape="rect" coords="3,202,234,264" href="mailto:[email protected]" alt="Pump" /> <area shape="rect" coords="481,36,614,265" href="mailto:[email protected]" alt="Jaonaii" /> <area shape="rect" coords="720,0,852,257" href="mailto:[email protected]" alt="Han" /> <area shape="rect" coords="256,35,383,263" href="mailto:[email protected]" alt="Cherry" /> <area shape="rect" coords="242,218,436,263" href="mailto:[email protected]" alt="Cherry" /> <area shape="rect" coords="442,229,639,264" href="mailto:[email protected]" alt="Jaonaii" /> <area shape="rect" coords="646,143,897,261" href="mailto:[email protected]" alt="Han" /> </map>

Page 170: Build Automation Using Wireless Sensor Network

<h2>Welcome to WSN Project </h2> <div id="maincontent"> <h3>สมาชกโครงงาน</h3> <p>&nbsp;</p> <center> <table width="457" height="130" border="0"> <tr> <td width="75"><div align="left">เอกชย </div></td>

<td width="114"><div align="left">ยอดตาคา</div></td> <td width="254"><div align="left">e-mail: <a

href="mailto:[email protected] ">[email protected] </a></div></td> </tr> <tr>

<td><div align="left">ชรนรตน</div></td> <td><div align="left">วงศธนะรกษ</div></td>

<td><div align="left">e-mail: <a href="mailto:[email protected]"> [email protected]</a></div></td>

</tr> <tr> <td><div align="left">กญญณฐ</div></td> <td><div align="left">มนตประเสรฐ </div></td> <td><div align="left">e-mail: <a href="mailto:[email protected]">

[email protected]</a></div></td> </tr> <tr> <td><div align="left">สถาพร</div></td> <td><div align="left">สงาศร</div></td> <td><div align="left">e-mail: <a href="mailto:[email protected] ">

[email protected] </a></div></td>

Page 171: Build Automation Using Wireless Sensor Network

</tr> </table></center></div></div></div> <p id="footer">By<a href="contact_us.html"> Smart Building Group</a</p> </body> </html>

Page 172: Build Automation Using Wireless Sensor Network

7. Edit_mem.php <? session_start(); if($_GET[userid]=="" && $_SESSION[status]!="Admin") $_GET[userid]=$_SESSION[userid]; if($_SESSION["status"]!="Admin") echo"<meta http-equiv=Refresh content='1;URL=index.php'>";?> <!DOCTYPE html PUBLIC "-//W4C//DTD XHTML 1.0 Transitional//EN" "http://www.w4.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w4.org/1999/xhtml"> <head> <title>Edit</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <?php if($_SESSION["userid"]=="") echo"<meta http-equiv=Refresh content='1;URL=index.php'>";?> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!-- if (document.images){ image1 = new Image(141, 44); image1.src = "images/top_nav_small_tab_hover.gif"; } //--> </script> <style type="text/css"> <!-- .style1 {color: #F4F4F4} .style2 {font-size: 14} .style4 {font-size: 14px} --> </style>

Page 173: Build Automation Using Wireless Sensor Network

<script language="Javascript"> <!-- Begin function resetform() { document.forms[0].elements[1]==""; } function submitForms() { if (isName() && isEmail() && isUser() && isPass()) alert("Ok you Great!"); else return false; } function isName() { if (document.forms[0].Name.value == "") { alert ("\n The Name field is blank. \n\n Please enter your name.") document.forms[0].Name.focus(); return false; } return true; } function isEmail() { if (document.forms[0].Email.value == "") { alert ("\n The E-Mail field is blank. \n\n Please enter your E-Mail address.") document.forms[0].Email.focus(); return false; } if (document.forms[0].Email.value.indexOf ('@',0) == -1 || document.forms[0].Email.value.indexOf ('.',0) == -1) {

Page 174: Build Automation Using Wireless Sensor Network

alert ("\n The E-Mail field requires a \"@\" and a \".\"be used. \n\nPlease re-enter

your E-Mail address.") document.forms[0].Email.select(); document.forms[0].Email.focus(); return false; } return true; } function isUser() { if (document.forms[0].User.value == "") { alert ("\n The Username Name field is blank. \n\nPlease enter your user name.") document.forms[0].User.focus(); return false; } return true; } function isPass() { if (document.forms[0].elements[4].value == "") { alert ("\n The Password field is blank. \n\nPlease enter your password.") document.forms[0].elements[4].focus(); return false; } if (document.forms[0].elements[4].value == "") { alert ("\n The Password field is blank. \n\nPlease enter your password.") document.forms[0].elements[4].focus(); return false; } if (document.forms[0].elements[4].value != document.forms[0].elements[4].value) {

Page 175: Build Automation Using Wireless Sensor Network

alert ("\n The password are unmatch. \n\nPlease insert password again.") document.forms[0].elements[4].focus(); return false; } return true; } function isPicture() { if (document.forms[0].elements[5].value == "") { alert ("\n The Picture field is blank. \n\nPlease select your picture.") document.forms[0].elements[5].focus(); return false; } if (document.forms[0].elements[5].value.indexOf ('.jpg',0) == -1 && document.forms[0].elements[5].value.indexOf ('.png',0) == -1 && document.forms[0].elements[5].value.indexOf ('.gif',0) == -1) { alert ("\n The Picture is invalid. \n\nPlease select your picture type as jpg, gif,

png.") document.forms[0].elements[5].focus(); return false; } return true; } --> </script> </head> <body> <ul id="topnav"> <li><a href="home.php" class="smalltab">Home</a></li>

Page 176: Build Automation Using Wireless Sensor Network

<li class="bigtab" ><a href="Admin.php">Admin</a></li> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li> <li><a href="tmotestatistic.php" class="smalltab">Statistic</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li> </ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img src="images/main_content_header_900.gif" width=900 height=3> <div id="container"><br> <?php include('config.inc.php'); $result = mysql_query("SELECT * FROM member WHERE userid='$_GET[userid]'"); $row=mysql_fetch_array($result); ?> <form action="Edit_mem_sql.php?userid=<?echo $_GET[userid]?>" method="post" enctype="multipart/form-data" onSubmit="return submitForms() "> <table align="center"> <th align="center" colspan="2" ><font size="4" color=#800040> </font><font size="6"

color="black">Edit Members </font></th> <tr> <td align="right" ><font color="#FF6600" size="4">Edit UID: </font> <td ><font color="#FF6600" size="4"><? echo $_GET[userid];?></font></td> </tr> <tr> <td align="right" ><font color="#FF6600" size="4">Name : </font> <td ><font color="#FF6600" size="4"> <input type="text" name="Name" value=<?echo $row[name];?>> </font>

Page 177: Build Automation Using Wireless Sensor Network

</tr> <tr> <td align="right"><font color="#FF6600" size="4">Email : </font> <td><font color="#FF6600" size="4"> <input type ="text" name="Email" value=<?echo $row[email];?>> </font>

</tr> <tr>

<td align="right" ><font color="#FF6600" size="4">User : </font> <td ><font color="#FF6600" size="4">

<input type="text" name="User" value="<?echo $row[username];?>" <?if($_SESSION[status]!="Admin") echo "onFocus=\"blur();\""; ?>> </font>

</tr> <tr> <td align="right"><font color="#FF6600" size="4">Password : </font> <td><font color="#FF6600" size="4"> <input type="password" name="Password" value=<?echo $row[password];?>>

</font> </tr> <tr>

<td align="right" ><font color="#FF6600" size="4">Confirm Password : </font> <td ><font color="#FF6600" size="4"> <input type="password" name="Confirm" value=<?echo $row[password];?>> </font>

</tr> <tr> <td align="right"><font color="#FF6600" size="4">Picture : </font> <td><font color="#FF6600" size="4"><img src="<?echo $row[path];?>" height=200

width=200><br> <input type=file name="upfile"> </font>

Page 178: Build Automation Using Wireless Sensor Network

</tr> <tr> <td colspan=2 > <font color="#FF6600" size="4; status : <select name='status'><option value=<?echo $row[status];?>>*

<? echo $row[status]; ?></option> <? if($_SESSION["status"] == "Admin") echo "<option value='Admin'>Admin</option>" ?> <option value='User'>User</option> </select></font>

</tr> <tr> <td colspan="2" align="center"><font color="#FF6600" > <input type="submit" value="Submit"><input type="reset" value="Clear"></font>

</tr> </table></form> </body> </html> Edit_mem_sql.php <? session_start(); $Name = $_POST[Name]; $Email = $_POST[Email]; $User = $_POST[User]; $Password = $_POST[Password]; if($_GET[userid]=="") $_GET[userid]=$_SESSION[userid]; if( ($_SESSION["status"]!="Admin") ) { if( ($_SESSION[userid]!=$_GET[userid]) ) { echo "Access Denine"; return false; } }

Page 179: Build Automation Using Wireless Sensor Network

include("config.inc.php"); if (is_uploaded_file($_FILES['upfile']['tmp_name'])){ $filename=basename($_FILES['upfile']['name']); if (preg_match("/jpg/i",$filename)){ $filetype=".jpg"; } else if (preg_match("/png/i",$filename)){ $filetype=".png"; } else if (preg_match("/gif/i",$filename)){ $filetype=".gif"; } $path = "Picture/"; $path = $path.$User.$filetype; if(move_uploaded_file($_FILES['upfile']['tmp_name'],$path)){ print "<center><br>Upload Filename: ".$_FILES['upfile']['name']."

Success</center><br>"; } else print "<center>Upload not Success</center>"; } $result = mysql_query("SELECT * FROM member WHERE userid='$_GET[userid]'"); $row=mysql_fetch_array($result); if($path=="") $path=$row[path]; if($_SESSION[status]=="User") $_POST[status]="User"; $sql = "UPDATE `member` SET `name` = '$Name',`email` = '$Email',`username` =

'$User',`password` = '$Password',`path` = '$path',`status` = '$_POST[status]' WHERE `userid`= '$_GET[userid]' LIMIT 1";

mysql_query($sql) or die('Invalid query: ' . mysql_error()); ?> <html><head> <title> Edit member</title></head> <body><center> <table align=center> <th align=center colspan=2><font color=white>แกไขเรยบรอยแลว โดยมขอมลดงน</font>

Page 180: Build Automation Using Wireless Sensor Network

<tr> <td>ชอ : <td> <? echo $Name ?> </tr> <tr> <td>อเมล : <td> <?echo $Email ?> </tr> <tr> <td> ชอลอกอน : <td> <?echo $User ?> </tr> <tr> <td> Picture : <td> <?echo $path ?> </tr> <tr> <td>status : <td> <? echo $_POST[status] ?> </tr> </table> <? if($_SESSION["status"] == "Admin") echo "<meta http-equiv='Refresh' content='3; URL=Admin.php'>"?> <? if($_SESSION["status"] == "User") echo "<meta http-equiv='Refresh' content='3; URL=home.php'>"?> </center></body> </html>

Page 181: Build Automation Using Wireless Sensor Network

8. export_csv.php <? include("config.inc.php"); $db = "tmote"; $table = "tmote"; $or="ASC"; $Name=$_GET['Name']; $Name = str_replace("_%$%_"," ",$Name); $time1=$_GET['Time1']; $time1=ereg_replace("_"," ",$time1); $time2=$_GET['Time2']; $time2=ereg_replace("_"," ",$time2); $option=$_GET['option']; $option=ereg_replace("_"," ",$option); $option_array = explode(",",$option); $time1=$time1.":00"; $time2=$time2.":59"; $result = mysql_query("SELECT * FROM tmote WHERE (moteid='$Name') AND (time >= '$time1')

And (time <= '$time2') ORDER BY time $or " ); $columns=count($option_array); $out = ''; $out .="-- Auto Building Using Wireless Sensor Network -- \n"; $date= date ("Y-m-d H:i:s"); $out .="Data Export From WSN Project From ".$Name." At ".$date.','."\n"; $out .="From ".$time1." To ".$time2.','; $out .="\n"; // Count the table fields and put the value into $columns.

Page 182: Build Automation Using Wireless Sensor Network

$columns = count($option_array); $out.='"'."Time".'",'; // Put the name of all select to $out. for ($i = 0; $i < $columns; $i++) { $fields=$option_array[$i]; $out .= '"'.$fields.'",'; } $out .="\n"; // Add all values in the table to $out. while($row=mysql_fetch_array($result)) { for ($i = 0; $i < $columns; $i++) { if($i==0){ $datatime=$row["time"]; $out .='"'.$datatime.'",';} $data = $row[$option_array[$i]]; $out .='"'.$data.'",'; } $out .="\n"; } // Open file export.csv. $f = fopen ('WSN.csv','w'); // Put all values from $out to export.csv. fputs($f, $out); fclose($f); header('Content-type: application/csv'); header('Content-Disposition: attachment; filename="WSN.csv"'); readfile('WSN.csv'); ?>

Page 183: Build Automation Using Wireless Sensor Network

9. Floor3.php <? session_start(); if($_SESSION["userid"]=="") { echo"<meta http-equiv=Refresh content='1;URL=index.php'>"; return fault; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <title>Floor 3</title> <link href="style_page.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!--

if (document.images){ image1 = new Image(131, 33); image1.src = "images/top_nav_small_tab_hover.gif"; } //--> </script> <script type="text/javascript" src="Set_detail_mote.js"> </script> </head> <body> <ul id="topnav"> <li><a href="home.php" class="smalltab">Home</a></li> <? if($_SESSION["status"] == "Admin")

Page 184: Build Automation Using Wireless Sensor Network

echo "<li><a href=admin.php class=smalltab>Admin</a></li>" ?> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li> <li><a href="tmotestatistic.php" class="smalltab">Statistic</a></li> <li class="bigtab"><a href="#" >Floor 3</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li></ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img src="images/main_content_header_900.gif" width=900 height=3> <!-- START STATS BAR (IF YOU WISH TO NOT HAVE THE ICONS PLEASE LOOK AT INDEX_BLANK.HTML AS WE HAVE TAKEN THEM OUT FOR YOU) --> <!-- END STATS BAR --> <div id="container"><div id="right"> <p><img src="images/floor3.jpg" width="850" height="330" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="circle" coords="123,49,8" href="tmoterealtime.php?moteroom=Com_Project"

alt="mote13" onmouseover="Smote13();" /> <area shape="circle" coords="491,116,8" href="tmoterealtime.php?moteroom=Comp2" alt="mote8"

onmouseover="Smote8();" /> <area shape="circle" coords="518,48,8" href="tmoterealtime.php?moteroom=Comp2" alt="mote7"

onmouseover="Smote7();"/> <area shape="circle" coords="605,89,8" href="tmoterealtime.php?moteroom=Lab_Commu"

alt="mote3" onmouseover="Smote3();"/> <area shape="circle" coords="683,119,9" href="tmoterealtime.php?moteroom=Lab_Commu"

alt="mote2" onmouseover="Smote2();"/>

Page 185: Build Automation Using Wireless Sensor Network

<area shape="circle" coords="779,122,9" href="tmoterealtime.php?moteroom=Lab_Commu" alt="mote1" onmouseover="Smote1();"/>

<area shape="circle" coords="778,172,8" href="tmoterealtime.php?moteroom=Lab_Comp1" alt="mote4" onmouseover="Smote4();"/>

<area shape="circle" coords="511,166,8" href="tmoterealtime.php" alt="mote17" onmouseover="Smote17();"/>

<area shape="circle" coords="349,166,8" href="tmoterealtime.php" alt="mote16" onmouseover="Smote16();"/>

<area shape="circle" coords="684,154,8" href="tmoterealtime.php?moteroom=Lab_Comp1" alt="mote5" onmouseover="Smote5();"/>

<area shape="circle" coords="605,182,8" href="tmoterealtime.php?moteroom=Lab_Comp1" alt="mote6" onmouseover="Smote6();"/>

<area shape="circle" coords="171,115,9" href="tmoterealtime.php?moteroom=Com_Project" alt="mote14" onmouseover="Smote14();"/>

<area shape="circle" coords="235,49,8" href="tmoterealtime.php?moteroom=Embeded" alt="mote11" onmouseover="Smote11();"/>

<area shape="circle" coords="274,116,7" href="tmoterealtime.php?moteroom=Embeded" alt="mote12" onmouseover="Smote12();"/>

<area shape="circle" coords="204,163,7" href="tmoterealtime.php" alt="mote15" onmouseover="Smote15();"/>

<area shape="circle" coords="362,49,7" href="tmoterealtime.php?moteroom=Comp1" alt="mote9"

onmouseover="Smote9();"/> <area shape="circle" coords="377,116,8" href="tmoterealtime.php?moteroom=Comp1" alt="mote10"

onmouseover="Smote10();"/> </map> </p> <center><font color= blue size=3><strong>Mouse over mote to see picture of mote location. Click on

Page 186: Build Automation Using Wireless Sensor Network

mote to see realtime data of mote.</strong></font></center> <center> <form name="ntmote"> Mote : <input type="text" name="nntmote" size="15" value="Example Tmote"

onFocus="blur();" > </form> </center> <img src="images/tmote.jpg" name="tmote" alt="tmote" width="400" height="300" /> <h2>Welcome to WSN Project </h2> <div id="maincontent"> <h3>แบบจาลองการตดตง Sensors ภายในอาคาร 84 ชน3</h3><p align="left">จากรปดานบนแสดงแบบจาลองการตดตง Sensors ภายในอาคาร 84 ชนท 3 คณะวศวกรรมศาสตร มหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ ซงนกศกษาไดทาการตดตง Sensors เปนจานวน 17 motes ซงประกอบไปดวย mote 1 ถง mote 17 </p> <p> <label></label></p> <table width="693" border="0">

<tr> <td width="102"><div align="left">สถานท:</div></td> <td width="625"><div align="left">คณะวศวกรรมศาสตร มหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ </div></td>

</tr> <tr> <td><div align="left">อาคาร : </div></td>

<td><div align="left">84</div></td> </tr> <tr> <td><div align="left">บรเวณ : </div></td>

<td><div align="left">ชน3 หอง computer หองproject computer หองLab สอสารและ

Lab Computer และพนทใกลเคยง </div></td> </tr> <tr> <td><div align="left">จานวน mote : </div></td> <td><div align="left">17 motes </div></td> </tr>

Page 187: Build Automation Using Wireless Sensor Network

<tr> <td><div align="left">หมายเลข mote: </div></td> <td><div align="left">mote 1 ถง mote 17 </div></td>

</tr> <tr> <td><div align="left"></div></td>

<td><div align="left"></div></td> </tr>

</table> </div> </div> </div><p id="footer">By<a href="contact_us.php"> Smart Building Group</a></p> </body> </html>

Page 188: Build Automation Using Wireless Sensor Network

10. Floor4.php <? session_start(); if($_SESSION["userid"]==""){ echo"<meta http-equiv=Refresh content='1;URL=index.php'>"; return fault; }?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <title>Floor 4</title> <link href="style_page.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!-- if (document.images){ image1 = new Image(131, 33);

image1.src = "images/top_nav_small_tab_hover.gif"; } //--> </script> </head> <body> <ul id="topnav"> <li><a href="home.php" class="smalltab">Home</a></li> <? if($_SESSION["status"] == "Admin") echo "<li><a href=admin.php class=smalltab>Admin</a></li>" ?> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li> <li><a href="tmotestatistic.php" class="smalltab">Statistic</a></li>

Page 189: Build Automation Using Wireless Sensor Network

<li><a href="floor3.php" class="smalltab">Floor 3</a></li> <li class="bigtab"><a href="#" >Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li></ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img src="images/main_content_header_900.gif" width=900 height=3> <!-- START STATS BAR (IF YOU WISH TO NOT HAVE THE ICONS PLEASE LOOK AT INDEX_BLANK.HTML AS WE HAVE TAKEN THEM OUT FOR YOU) --> <!-- END STATS BAR --> <div id="container"> <div id="right"> <img src="images/floor4.jpg" alt="" width="860" height="410" border="0" usemap="#Map" /> <h2>Welcome to WSN Project </h2> <div id="maincontent"> <!--END MAIN CONTENT HERE --> </div> </div> </div> <p id="footer">By <a href="contact_us.php">Smart Building Group </a></p> </body> </html>

Page 190: Build Automation Using Wireless Sensor Network

11. Graph.php <? session_start(); ?> <? if($_SESSION["userid"]==""){ echo"<meta http-equiv=Refresh content='1;URL=index.php'>"; return false;} ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <title>Wireless Sensor Network Graph Statistic</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!-- if (document.images){ image1 = new Image(131, 33); image1.src = "images/top_nav_small_tab_hover.gif"; } //--> </script> <script type="text/javascript" src="Set_detail_mote.js"> </script> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <style type="text/css"> <!-- td{font-family:Arial,sans-serif;font-size:10pt} th{font-family:Arial,sans-serif;font-size:10pt;color:white} --> </style> </head>

Page 191: Build Automation Using Wireless Sensor Network

<body > <ul id="topnav"> <li><a href="home.php" class="smalltab">Home</a></li> <? if($_SESSION["status"] == "Admin") echo "<li><a href=admin.php class=smalltab>Admin</a></li>" ?> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li> <li class="bigtab"><a href="tmotestatistic.php" >Statistic</a></li> <li><a href="floor3.php" class="smalltab">Floor 3</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li> </ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img src="images/main_content_header_900.gif" width=900 height=3> <div id="container"> <? $moteid=$_GET['moteid']; $moteid = str_replace("_%$%_"," ",$moteid); $optionjoin1=$_GET[option]; $optionjoin=ereg_replace("_"," ",$optionjoin1); $option_array = explode(",",$optionjoin); $time01=$_GET['Time1']; $time1=ereg_replace("_"," ",$time01); $time02=$_GET['Time2']; $time2=ereg_replace("_"," ",$time02); $numline = count($option_array); echo "<br><center>";

Page 192: Build Automation Using Wireless Sensor Network

?> <? include("config.inc.php"); $or="ASC"; if(($numline>23)){ $xiii=0; for($index=23;$index<53;$index++){ $optionjoin2[$xiii] = $option_array[$index]; $xiii++; } $optionjoin2=implode(",",$optionjoin2); $optionjoin2=ereg_replace(" ","_",$optionjoin2); $moteid = str_replace(" ","_%$%_",$moteid);

echo "<center><img src=picgraph.php?moteid=".$moteid."&Time2=".$time02. "&Time1=".$time01."&option=".$optionjoin1."></center><p><p>"; echo "<center><img src=picgraph.php?moteid=".$moteid."&Time2=".$time02. "&Time1=".$time01."&option=".$optionjoin2."></center>";

} else{ $moteid = str_replace(" ","_%$%_",$moteid);

echo "<center><img src=picgraph.php?moteid=".$moteid."&Time2=". $time02."&Time1=".$time01."&option=".$optionjoin1."></center>";

} ?> <p id="footer2">By <a href="contact_us.php">Smart Building Group</a></p> </body> </html>

Page 193: Build Automation Using Wireless Sensor Network

12. home.php <? session_start(); if($_SESSION["userid"]==""){ echo"<meta http-equiv=Refresh content='1;URL=index.php'>"; return fault; }?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <title>Home</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!-- if (document.images){ image1 = new Image(131, 33); image1.src = "images/top_nav_small_tab_hover.gif"; } //--> </script> <style type="text/css"> <!--

.style1 {color: #F4F4F4}

.style2 {font-size: 14}

.style3 {font-size: 14px} --> </style> </head>

Page 194: Build Automation Using Wireless Sensor Network

<body> <ul id="topnav"> <li class="bigtab"><a name="home" id="home"></a>Home</li> <? if($_SESSION["status"] == "Admin") echo "<li><a href=admin.php class=smalltab>Admin</a></li>" ?> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li> <li><a href="tmotestatistic.php" class="smalltab">Statistic</a></li> <li><a href="floor3.php" class="smalltab">Floor 3</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li> </ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img src="images/main_content_header_900.gif" width=900 height=3> <div id="container"> <div id="left"> <h2><strong>Main</strong></h2> <ul id="leftnav"> <li><a href="#">Home</a></li> <li><a href="#smart_building" class="style1">Buildinng using WSN</a></li> <li><a href="#tinyos">TinyOS</a></li> <li><a href="#nesc">NesC</a></li> <li><a href="#tmoteinvent">Tmote Invent</a></li> <li><a href="#tmotesky">Tmote Sky</a></li> </ul> <h2><strong>Latest News</strong></h2>

Page 195: Build Automation Using Wireless Sensor Network

<div id="news"> <p><img src="images/news_icon.gif" alt="news" /><strong>18/01/08</strong> - อยากรไหม ระบบอาคารอจฉรยะ สรางขนเพออะไร.... <a href="object.php">Read More</a><img src="images/news_seperator.gif" alt="sep" width="140" height="14" /> </div></div> <div > <img src="images/slogan_box_2-2.jpg" alt="slogan" aligh="center" width="700" height="206" /> <h2 class="style3">&nbsp;</h2> <div id="maincontent"> <h3> Building Automation System Using Wireless Sensor Network <a name="smart_building" id="smart_building"></a></h3> <blockquote> <p align="right" class="style2"><a href="#home">Home</a></p> <p align="left" class="style2"><strong>Building Automation System Using Wireless Sensor Network; </strong><strong> </strong></p> <p align=left class="style2">โครงงานทไดรบแรงบนดาลใจมาจากเทคโนโลย Wireless Network โดยอาศยความสามารถของ Sensor Tmote Invent และ TmoteSky บวกกบหลกการของ Ad-hoc Network นามาสรางเปนระบบอาคารอจฉรยะทสามารถตรวจจบคาของ แสง อณหภม ความชน การเคลอนไหว แลวสงขอมลผานทาง Internet จากนนจงนาไปแสดงผลบน PC หรอ โทรศพทมอถอซงเปนการตดตอแบบไรสาย ทาใหสามารถ รบทราบสถานะของตวอาคารแมจะอยในพนท หางไกล ไดแคเพยงมคอมพวเตอรหรอโทรศพทมอถอ</p> <p align="center"><img src="images/model1.jpg" width="500" height="440" /></p><blockquote> <p align="center">รปแสดงหลกการทางานของ Building Automation Using Wireless Sensor Network </p></blockquote> <p align="left" class="style2"><strong>หลกการทางานของระบบอาคารอจฉรยะโดยใชเครอขายเซนเซอรแบบไรสาย</strong></p>

Page 196: Build Automation Using Wireless Sensor Network

<p align="left" class="style2">จากแบบจาลองการทางานของระบบอาคารอจฉรยะดงรป เราจะทาการสรางเครอขาย Ad hoc Wireless Network ซงกคอกลมของโหนดตางๆ ทกระจายอยบนพนท และมการตดตอสอสารกนผานทางเครอขายไรสาย โดยโครงสรางพนฐาน จะเปนการตดตอสอสารโดยไมมการใชสายสญญาณเขามาเกยวของ ทงนทางนกศกษาไดนา Tmote Sky ซงเปน Wireless Sensor ขนาดเลกชนดหนงเขามาใชเปนโหนดในการวจยโครงการ เพอเปนตวตรวจจบคาของ แสง อณหภม ความชน การเคลอนไหว ซงการทางานในสวนนจะใช protocol Zigbee และระบบปฏบตการ TinyOS เขามาควบคม เมอ sensor ตรวจจบขอมลไดแลวจะสงขอมลผานเกทเวยโดยใช GPRS ไปยง Internet และจาก Internet จะทาใหผใชงาน สามารถรบทราบสถานะของตวอาคารโดยผาน เครอง คอมพวเตอร (ใช Wi-Fi) หรอ โทรศพทมอถอ (โดยใช GPRS) ไดตลอดเวลา นอกจากนเรายงสามารถรบขอมลสถานะของตวอาคารไดโดยผานเกทเวยมายงมอถอโดยตรงโดยใช Blotooth</p> <p align="left" class="style2"><a href="#home">....กลบเมนหลก</a></p></blockquote> <h3>TinyOS<a name="tinyos" id="tinyos"></a></h3><blockquote> <p align="right"><a href="#home">Home</a></p> <p align="left">TinyOS เปนระบบปฏบตการขนาดเลกทใชใน Wireless Sensor Network โดยมตนกาเนดมาจาก การพฒนาของนกวจยท University of California (UC) at Berkeley ระบบ TinyOS มความสามารถ ในการจดการงาน(task management) ดวยการจดลาดบแบบ FIFO(First In First Out) การสอสารแบบไรสาย ดวยโปรโตคอลแบบ ad-hoc และรองรบ การทางานแบบพรอมกน(concurrent operation) มระบบตอบสนองตอเหตการณ(event-based execution) จงรองรบการทางานหลายแอพพลเคชน โดยไมจาเปนตองใชหนวยความจาขนาดใหญ ขอดอกอยางหนงของระบบ TinyOS คอเปนลกษณะ Open source software นอกจากนยงใชหนวยความจานอยและใช CPU ทไมตองมคณภาพสงมากนก ใน Wireless Sensor Network ระบบTinyOS จะทางานอยบนSensor ขนาดเลก (mote) โดยจะคอยควบคมการใชพลงงาน การรบสงขอมลและจดการกบขอมลท mote รบมา ในการสงขอมลของแตละ mote จะเปนลกษณะ multi-hop คอจะสงขอมลแบบ packet จาก mote หนงไปสอก mote หนงเปนทอดๆ ซงการสงขอมลในลกษณะน ทาใหประหยดพลงงาน และไดขอมลทมประสทธภาพ</p> <p align="left"><span class="style2"><a href="#home">....กลบเมนหลก</a></span></p></blockquote>

Page 197: Build Automation Using Wireless Sensor Network

<h3>NesC<a name="nesc" id="nesc"></a></h3><blockquote> <p align="right"><a href="#home">Home</a></p> <p align="left">ภาษา NesC ใชสาหรบพฒนาระบบปฏบตการTinyOS โดย NesC มลกษณะเปนแบบOOP(Object Oriented Programming) รองรบการเขยนโปรแกรมแบบ Event Driven (จะทางานเมอมเหตการณเกดขน) และ Component-based Model ซงชวยใหพฒนาโปรแกรมแบบ Concurrent (รองรบการทางานแบบพรอมกน) และ Data Aggregation (การทางานแบบ Aggregation ชวยให Application ลดจานวนการสงขอมล ทาใหประหยดพลงงาน เนองจากจะมการประมวลผลทตวของ mote กอน แลวจงจะทาการสงขอมลไปใหmoteถดไป แทนทจะใหmoteแตละตวสงขอมลไปใหคอมพวเตอรทาการประมวลผลทเดยวซงทาใหเสยเวลา)<br /> ในภาษา NesC จะแบงออกเปน<br /> <strong>Component </strong><br /> configuration เหมอนกบเปนโครงสรางของโปรแกรม โดยในสวนนบอกวา ตองใช component อะไรบาง และcomponent แตละตวเชอมตอกนอยางไร<br /> - module เปนสวนของcodeสาหรบการทางาน<br /> <strong> Interface</strong> การเชอมตอ จะม 2 หนาท <br /> 1. uses คอ การขอเชอมตอ<br /> 2.provider คอ การให component อนมาเชอมตอได <br /> - command เปนการใหบรการ component อนๆ <br /> - event การรองขอแจงเตอนเหตการณ</p> <p align="left"><strong>application</strong> จะเกดจากการนา component ตางๆมาเชอมตอกนผาน Interface</p> <p align="center"><img src="images/nesc1.jpg" width="504" height="326" /></p> <p align="center">รปแสดงโครงสรางของภาษา NesC</p> <p align="left"><a href="#home">....กลบเมนหลก</a></p> </blockquote><h3>Tmote Invent <a name="tmoteinvent" id="tmoteinvent"></a></h3> <blockquote><p align="right"><a href="#home">Home</a></p></blockquote><blockquote>

Page 198: Build Automation Using Wireless Sensor Network

<p align="left">TmoteInvent เปนอปกรณรนทมความสามารถสงกวา Tmotesky แตมความคลายคลงกนและถกพฒนามาบน TinyOS และใชภาษา nesC เหมอนกนจงทาใหสามารถใชงานรวมกนไดโดยในโครงงานนเราไดใช TmoteInvent เปนอปกรณในการ เชอมตอกบ Computer เพออานคาทรบไดจาก Sensor Node ตวอนๆ ในเครอขายไวเลสเซนเซอรทเราไดทาการตดตงไว </p> <p align="left">ใน TmoteInvent นนไดทาการเพมความสามารถของอปกรณใหมความสามารถเหนอกวา Tmotesky โดยมรายละเอยดดงน</p> <p align="left">-เพมชดคาสงใหงายตอการใชงาน และมโปรแกรมสาเรจรปเพออานคาและวดผลตางๆทอานได มาใหพรอมใชงาน</p> <p align="left">-ม Battery Lithium ion ภายในทาใหสะดวกในการใชงานและสามารถ Recharged ได</p> <p align="left">-มการเพมชนดของเซนเซอรทาใหสามารถนาไปประยกตใชกบงานไดหลากหลายกวาชนด Sensor ภายในของ TmoteInvent (ทเพมขนมาเมอเทยบกบ Tmotesky)</p> <p align="left">-Accelerometer Sensor คอ เซนเซอรทใชจบความเคลอนไหวโดยเซนเซอรจะถกตดตงไวภายในของ ตวอปกรณและสามารถจบความเคลอนไหวของตวอปกรณไดสองแกน(x,y)/p> <p align="left">-Microphone Sensor เปนเซนเซอรทใชวดคาตางๆ ทไมโครโฟนของTmoteInvent รบคามาได เชน อานคาระดบสญญาณทไมโคโฟน อานคาบฟเฟอรของไมโครโฟนและยงสามารถกาหนดคาของไมโครโฟนได เชน กาหนดคา Amplitude สาหรบการ Interruptt</p> <p align="left">-Speaker Sensor เปนเซนเซอรทใชอานคาระดบสญญาณทออกมาจากลาโพงภายใน และยงสามารถ เกบคาตางๆของลาโพง โดยใชคาสงผานทางเซนเซอรไดอกดวย</p> <p align="left">-Voltage Sensor คอ เซนเซอรทใชอานคาปรมาณการใชพลงงานของ TmoteInvent (mV)</p> <p align="center"><img src="images/tmoteinvent.jpg" width="489" height="304" /></p> </blockquote><p align="center">รปแสดง TmoteInvent</p> <p align="left"><a href="#home">....กลบเมนหลก</a></p> <h3>Tmote Sky<a name="tmotesky" id="tmotesky"></a></h3><blockquote> <p align="right"><a href="#home">Home</a></p>

Page 199: Build Automation Using Wireless Sensor Network

<p align="left"><strong>Tmotesky </strong>คอ อปกรณไรสายขนาดเลกรนลาสดทถกพฒนาโดยใชพลงงานตา ผลตมาเพอใชในระบบ เซนเซอรเนตเวรค, ระบบเฝาระวงและเปนตนแบบอปกรณทมความรวดเรวในการทางานในขณะทใชพลงงานตา โดยจดเดนของ Tmotesky คอ</p> <p align="left">-เปนอปกรณทใชมาตรฐาน IEEE 802.15.4 (<a href="http://en.wikipedia.org/wiki/ZigBee" title="ZigBee">Zigbee</a> certification) <br /> -ทางานท 2.4 GHz โดยมอตราการรบ-สงขอมลท 250 kbps<br /> -ใชไมโครคอนโทรลเลอร (Microcontroller) รน MSP430 ซงเปนไมโครคอนโทรลเลอร 16 บต พลงงานตา

จากบรษท Texas<br /> -มการใสเสาอากาศไวในแผงวงจรโดยมระยะการรบสญญาณสงสดท 125 เมตรbr /> -มเซนเซอรภายในแผงวงจร 3 ชนด คอ ความชน อณหภม และแสง<br /> -มการใชพลงงานตามาก<br /> -ในขณะทไมมการทางานตวอปกรณจะเขาสสภาวะ sleep และเมอมการเรมทางานจะกลบสสภาวะปรกต

ไดอยางรวดเรว (นอยกวา 6 us) ทาใหทางานไดรวดเรวและประหยดพลงงาน<br /> -มการเขารหสเพอความปลอดภยในการสงขอมลผาน Link Layer<br /> -สามารถทาการโปรแกรมหรอสงขอมลผาน USB port ทาใหสะดวกในการใชงาน<br /> -ตวอปกรณรองรบการทางานบน TinyOS ทาใหงายตอการพฒนาระบบ Wireless Mesh network</p> <p align="center"><img src="images/tmotesky.jpg" width="515" height="393" /></p> <p align="center">รปแสดง TmoteSky </p> <p><strong>รายละเอยดอปกรณ (Device Specification)</strong></p> <table width="436" border="0"> <tr> <td width="243"><div align="left"><strong>CPU</strong></div></td> <td width="177"><div align="center"></div></td> </tr>

<tr> <td><div align="left">BUS&nbsp;&nbsp;&nbsp;&nbsp;</div></td>

Page 200: Build Automation Using Wireless Sensor Network

<td> <div align="center">8 MHz</div></td> </tr>

<tr> <td><div align="left">RAM&nbsp;&nbsp;&nbsp;</div></td>

<td><div align="center">10 kB</div></td> </tr> <tr>

<td><div align="left">Program Space&nbsp;&nbsp;&nbsp;&nbsp;</div></td>

<td><div align="center">48 kB</div></td> </tr> <tr>

<td><div align="left">External Flash&nbsp;&nbsp;</div></td> <td><div align="center">1024 kB</div></td>

</tr> <tr>

<td><div align="left">Serial Communications</div></td> <td> <div align="center">DIO, SP1, I2C, UART</div></td>

</tr> <tr>

<td><div align="left">Current (active w/radio on)&nbsp;</div></td> <td><div align="center">19 mA</div></td>

</tr> <tr>

<td><div align="left">Current(sleep)&nbsp;</div></td> <td> <div align="center">5.1 uA</div></td> </tr> <tr> <td><div align="left">Startup Time</div></td>

<td><div align="center">6 uS</div></td>

Page 201: Build Automation Using Wireless Sensor Network

</tr> <tr>

<td><div align="left">Voltage&nbsp;</div></td> <td><div align="center">1.8-3.6 V</div></td>

</tr> <tr>

<td><div align="left"><strong>Radio</strong></div></td> <td><div align="center"></div></td>

</tr> <tr>

<td><div align="left">Frequency</div></td> <td><div align="center">2400-2483 MHz</div></td>

</tr> <tr>

<td><div align="left">Data Rate&nbsp;&nbsp;&nbsp;</div></td> <td><div align="center">250 kbps</div></td>

</tr> <tr>

<td><div align="left">Output Power&nbsp;&nbsp;</div></td> <td><div align="center">-25 to 0 dB</div></td>

</tr> <tr>

<td><div align="left">Startup Time&nbsp;&nbsp;</div></td> <td><div align="center">580 uS</div></td>

</tr> <tr>

<td><div align="left">Antenna Type&nbsp;&nbsp;</div></td> <td><div align="center">Inverted-F or SMA Coax</div></td> </tr> <tr>

Page 202: Build Automation Using Wireless Sensor Network

<td><div align="left"><strong>Humidity Sensor</strong></div></td> <td><div align="center"></div></td> </tr> <tr>

<td><div align="left">Humidity Accuracy&nbsp;</div></td> <td><div align="center">3.5% RH</div></td>

</tr> <tr> <td><div align="left">Temperature Accuracy&nbsp;&nbsp;&nbsp;</div></td> <td><div align="center">0.5 C</div></td> </tr>

<tr> <td><div align="left">Sampling Rate</div></td> <td><div align="center">90 Hz</div></td>

</tr> </table> <strong>การใชพลงงาน (Power)</strong> Tmotesky ใชพลงงานจาก Battery ขนาด AA จานวนสองกอน โดยมการออกแบบใหรองรบแรงดนได

ตงแต 2.1-3.6V </p> <p align="left"><strong>ชนด Sensor ภายในของ TmoteSky</strong></p> <p align="left">ใน TmoteSky จะมเซนเซอรสองชนดคอ Humidity/Temperature Sensor และ Light

Sensor โดยในการตรวจจบแสงใน Tmotesky นนจะใช Photodiode สองตวในการทางานเพอรบคา</p> <p align="left">1.Humidity/Temperature Sensor ซงใน Tmotesky จะใช Sensor no. SHT11 (Sensirion)

ใชในการตรวจจบความชนและอณหภม</p> <p align="left">2.Photo synthetically Active Radiation Sensor (P.A.R sensor) เปนเซนเซอรทถกพฒนา

Page 203: Build Automation Using Wireless Sensor Network

มาจาก เซนเซอรแสง และถกออกแบบมาเพอการวดการเปลยนแปลงทางเคม โดยอาศยการแผออก

ของแสง เปนตวกระตน โดยเซนเซอรประเภทนจะใชงานในการวดไดดในชวง 400-700 นาโนเมตร ของความยาว คลนแสง</p>

<p align="left">3. Total Solar Radiation Sensor (T.S.R sensor) เปนเซนเซอรทใชในการวดความเขมของ

พลงงานแสง โดยเซนเซอรตวนจะทางานคกบ P.A.R sensor เพอวดคาแลวนามาคานวณเพอใหได

คาทใกลเคยงมากทสด</p> <p align="left"><a href="#home">....กลบเมนหลก</a></p> </blockquote> </div></div> </div> <p id="footer">By <a href="contact_us.php">Smart Building Group</a></p> <center> </body> </html>

Page 204: Build Automation Using Wireless Sensor Network

13. index.php <? session_start(); ?> <? if($_SESSION["status"] == "Admin") echo "<meta http-equiv='Refresh' content='0; URL=Admin.php'>"?> <? if($_SESSION["status"] == "User") echo "<meta http-equiv='Refresh' content='0; URL=home.php'>"?> <html> <head> <title>Wireless Sensor Network Using Tmotesky</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-874"> <!-- start Css --> <link rel="stylesheet" type="text/css" href="StyleSheet.css" title="myStyle"> <!-- end Css --> </head> <body bgcolor="black"> <center><font size="+3" color="#ffffff">King Mongkut's University of Technology North

Bangkok</font><hr> <p align="center"><font size="+4" color="#fc7b08">ระบบอาคารอจฉรยะโดยใชเครอขาย Sensor ไรสาย <br>Building Automation System Using Wireless Sensor Network</b></font></p> <hr> <table border=0 bordercolor=white>

<tr> <td width=500>

<table align="center"> <tr> <td align=center colspan=3><font size="+3" color="#ffffff"> <strong><u>

รายชอสมาชกกลม</u></font> </tr>

Page 205: Build Automation Using Wireless Sensor Network

<tr> <td><font size="+3" color="#ffffff"> <strong>1.นายเอกชย </font> <td><font size="+3" color="#ffffff"><strong> ยอดตาคา</font> <td><font size="+3" color="#ffffff"><strong> 47-1016-131-8</font></strong> </tr> <tr> <td><font size="+3" color="#ffffff"><strong> 2.นางสาวกญญณฐ</font> <td><font size="+3" color="#ffffff"><strong> มนตประเสรฐ</font> <td><font size="+3" color="#ffffff"><strong> 47-1016-058-3</font> </tr> <tr> <td><font size="+3" color="#ffffff"><strong> 3.นางสาวชรนรตน </font> <td><font size="+3" color="#ffffff"><strong> วงศธนะรกษ</font> <td><font size="+3" color="#ffffff"><strong> 47-1016-008-8</font> </tr> <tr> <td><font size="+3" color="#ffffff"><strong> 4.นายสถาพร </font> <td><font size="+3" color="#ffffff"><strong> สงาศร</font> <td><font size="+3" color="#ffffff"><strong> 47-1016-115-1</font> </tr></font> <tr align=center> <td colspan=3><font size="+3" color="#ffffff"><strong>ทปรกษา : ดร.พงษศกด

กรตวนทกร</font> </tr> </table></td>

<td width=400><center><br><br> <form name=login action="checkLogin.php" method="post"> <table border=1 >

Page 206: Build Automation Using Wireless Sensor Network

<tr><td> <table border="0" cellspacing="2" cellpadding="0" align="center" > <tr> <td align="right" height="10"> <font size="+3" color="#6da5f2">Login : <td height="10"><input type="text" name="login" > </tr> <tr> <td align="right"><font size="+3" color="#6da5f2" >&nbsp; Password : &nbsp; <td><input type="password" name="pw"> </tr> <tr> <td> <td align="center" ><input type="submit" name="Submit" value="Login" > </form> </tr> <tr><td colspan="2"> <center><font size="+3" color="white">If you not member please </font>

<a style="color : red ; text-decoration : none; " href="Register.php"><font size="+3"

color="white"><u><strong> Register </u></a><br> </tr> <tr align="center"><td colspan=2><img src="images/network.gif"> </tr> </table></tr></table>

</tr> </table> </body> </html>

Page 207: Build Automation Using Wireless Sensor Network

14. Loguot.php <? session_start(); $_SESSION[userid]=""; $_SESSION[status]=""; session_destroy(); print "<meta http-equiv=Content-Type content=text/html; charset=windows-874 /><body bgcolor=black><font color=#fa6627><p align=center>คณไดทาการออกจากระบบแลว</p>"; print "<p align=center><a href=index.php><font color=#fa6627>กลบหนาหลก</a></p>" ?>

Page 208: Build Automation Using Wireless Sensor Network

15. object.php <? session_start(); if($_SESSION["userid"]==""){ echo"<meta http-equiv=Refresh content='1;URL=index.php'>"; return fault; }?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <title>Object</title> <link href="style_page.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!-- if (document.images){ image1 = new Image(131, 33); image1.src = "images/top_nav_small_tab_hover.gif"; } //--> </script> </head> <body> <ul id="topnav"> <li class="bigtab"><a name="home.php" id="home"></a>Home</li> <? if($_SESSION["status"] == "Admin") echo "<li><a href=admin.php class=smalltab>Admin</a></li>" ?> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li> <li><a href="tmotestatistic.php" class="smalltab">Statistic</a></li>

Page 209: Build Automation Using Wireless Sensor Network

<li><a href="floor3.php" class="smalltab">Floor 3</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li> </ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img src="images/main_content_header_900.gif" width=900 height=3> <div id="container"><div id="right"> <p> <img src="images/outdoortest.jpg" width="873" height="360" border="0" /></p> <h2>Welcome to WSN Project </h2> <div id="maincontent"> <h3>อยากรอะไร ? <a name="what" id="what"></a></h3> <table width="286" height="105" border="0"> <tr> <td width="26"><a href="#object1"><img src="images/kame1.gif" width="67"

height="64" border="0" /></a></td> <td width="639"><a href="#object1">วตถประสงค<strong> </strong></a></td> </tr> <tr>

<td><a href="#object2"><img src="images/kame1.gif" width="67" height="64"

border="0" /></a></td> <td><a href="#object2">ขอบเขต</a></td>

</tr> <tr>

<td><a href="#object3"><img src="images/kame1.gif" width="67" height="64" border="0" /></a></td>

Page 210: Build Automation Using Wireless Sensor Network

<td><a href="#object3">ประโยชนทคาดวาจะไดรบ</a></td> </tr>

</table> <h3>วตถประสงค<a name="object1" id="object1"></a></h3> <table width="739" height="105" border="0"> <tr> <td width="639"><div align="left">1. เพอศกษาเทคโนโลยการสอสารแบบไรสายและ

นาไปประยกตใช<strong> </strong></div></td> </tr>

<tr> <td><div align="left">2. เพอศกษาและพฒนาโปรแกรมทใชสอสารระหวาง Wireless

Sensorโดยผานเครอขายไรสายและเครอขายอนเตอรเนต </div></td> </tr> <tr> <td><div align="left">3. เพอออกแบบและสรางระบบอาคารอจฉรยะทสามารถรายงาน

สถานะและบนทกคาโดยผานระบบเครอขายไรสาย </div></td> </tr>

</table> <p><a href="#what">กลบหวขอหลก</a></p> <h3><strong>ขอบเขตของโครงงาน</strong><a name="object2" id="object2"></a></h3> <table width="739" border="0"> <tr> <td width="696"> <div align="left">1. สามารถสรางระบบตรวจจบแบบไรสายโดยเชอมผาน Internet

และ Mobile Phone ได</div></td> </tr>

Page 211: Build Automation Using Wireless Sensor Network

<tr> <td><div align="left">2. สามารถดคาทไดรบจาก Wireless Sensor ไดทกท ทก

เวลา</div></td> </tr> <tr>

<td><div align="left">3. มความรความเขาใจในการสอสารแบบไรสาย รโครงสราง

ทางภาษาทนามาใชในการควบคม sensor <br>&nbsp;&nbsp;&nbsp; และสามารถนาไปใชพฒนาเทคโนโลยใหมๆ</div></td> </tr>

<tr> <td>

<div align="left">4. ใช sensor ในการตรวจจบ แสง อณหภม ความชน การเคลอนไหว </div></td>

</tr> </table> <p><a href="#what">กลบหวขอหลก</a></p> <h3><strong>ประโยชนทคาดวาจะไดรบ</strong><a name="object3" id="object3"></a></h3> <table width="739" height="105" border="0"> <tr>

<td width="639"> <div align="left">1. มความรความเขาใจในเทคโนโลยการสอสารแบบไรสาย </div></td>

</tr> <tr>

<td><div align="left">2. ไดเรยนรวธการออกแบบระบบอาคารอจฉรยะ (Building

Automation System Using Wireless Sensor Network)</div></td> </tr>

Page 212: Build Automation Using Wireless Sensor Network

<tr> <td><div align="left">3. ไดศกษาและพฒนาโปรแกรมทใชในการตดตอกน

ระหวาง เครอขาย </div></td>

</tr> </table> <p><a href="#what">กลบหวขอหลก</a></p> </div></div></div> <p id="footer">By<a href="contact_us.php"> Smart Building Group</a><a href="http://www.zymic.com"> </a></p> </body> </html>

Page 213: Build Automation Using Wireless Sensor Network

16. pictograph.php <? include "jpgraph/jpgraph.php"; include "jpgraph/jpgraph_line.php"; include "jpgraph/jpgraph_scatter.php"; include "jpgraph/jpgraph_regstat.php"; //get parameter $moteid=$_GET['moteid']; $moteid = str_replace("_%$%_"," ",$moteid); $or="ASC"; $optionjoin=$_GET['option']; $optionjoin=ereg_replace("_"," ",$optionjoin); $option_array = explode(",",$optionjoin); $time1=$_GET['Time1']; $time1=ereg_replace("_"," ",$time1); $time2=$_GET['Time2']; $time2=ereg_replace("_"," ",$time2); $numline = count($option_array); if($numline){ $numline =23; } for ($n=0;$n<$numline;$n++) { if ($option_array[$n]=="reading1"){ $unit_array[$n]="TSR";} else if ($option_array[$n]=="reading2"){ $unit_array[$n]="PAR";} else if ($option_array[$n]=="reading3"){ $unit_array[$n]="Temperature";} else if ($option_array[$n]=="readin4"){ $unit_array[$n]="Quality";} } $db = mysql_connect("localhost","tmote","tmote") or die("ตดตอ Host ไมได"); mysql_select_db("tmote",$db) or die("ตดตอฐานขอมลไมได");

Page 214: Build Automation Using Wireless Sensor Network

$result = mysql_query("SELECT * FROM tmote WHERE (moteid='$moteid') AND (time >= '$time1')

And (time <= '$time2') ORDER BY time $or " ); $count_rows = mysql_num_rows($result); $result = mysql_query("SELECT * FROM tmote WHERE (moteid='$moteid') AND (time >= '$time1')

And (time <= '$time2') ORDER BY time $or " ); $numx = 0; while($row=mysql_fetch_array($result)){ $xdata[$numx] = $row["time"]; for($i=0;$i<$numline;$i++){ $comment=($row["comment"]); if($comment=="Packet Error"){$ydata[$i][$numx]=$ydata[$i][($numx-1)];} else{$ydata[$i][$numx] = $row[$option_array[$i]];} } $numx++; } //กาหนดจานวน label ของแกน x $xi=count($xdata); $xd=1; if(($xi>10)&&($xi<20)){$xd=2;} elseif(($xi>20)&&($xi<60)){$xd=4;} elseif($xi>60){$xd=$xi/10; $xdata[$xi]=""; } if($xi>10){

$n=0; for($n=0;$n<$xi;$n++){ $m=$n; if(($m%$xd)!= 0){ $xdata[$n]="";

Page 215: Build Automation Using Wireless Sensor Network

} }

} // Create the graph $g = new Graph(880,620,"auto"); $g->SetMargin(70,80,30,80); $g->title->Set("WSN :: Graph Data form ".$moteid." ".$time1." - ".$time2); $g->title->SetFont(FF_TIMES,FS_NORMAL,16); $g->SetMarginColor('lightblue'); $g->img->SetAntiAliasing(); $g->SetShadow(); $g->legend->Pos(0.01,0.5,"right","center"); $g->legend->SetFont(FF_TIMES,FS_NORMAL,12); $g->SetScale('textlin'); $g->xaxis->SetTickLabels($xdata); $g->xaxis->SetFont(FF_TIMES,FS_NORMAL,10); $g->xaxis->SetLabelAngle(25); $g->xaxis->title->Setcolor('red'); $g->yaxis->SetLabelFormat('%1.1f'); $serr=40; for($index=0;$index<$numline;$index++){ if($option_array[$index] =="load Type"){ $serr = $index ; } } for($n=0;$n<(count($option_array));$n++){ if ($option_array[$n]=="reading1"){ $option_array[$n]="TSR";} else if ($option_array[$n]=="reading2"){ $option_array[$n]="PAR";}

Page 216: Build Automation Using Wireless Sensor Network

else if ($option_array[$n]=="reading3"){ $option_array[$n]="Temperature";} else if ($option_array[$n]=="reading4"){ $option_array[$n]="Quality";} } if($numline>=1 && $serr != 0){ $p1 = new LinePlot($ydata[0]);

$p1->SetLegend($option_array[0]); $p1->SetColor("blue"); $p1->SetCenter(); $g->Add($p1); } if($numline>=2 && $serr != 1){ $p2 = new LinePlot($ydata[1]); $p2->SetLegend($option_array[1]); $p2->SetColor("red"); $p2->SetCenter(); $g->Add($p2); } if($numline>=3 && $serr != 2){ $p3 = new LinePlot($ydata[2]); $p3->SetLegend($option_array[2]); $p3->SetColor("green"); $p3->SetCenter(); $g->Add($p3); } if($numline>=4 && $serr != 3){ $p4 = new LinePlot($ydata[3]); $p4->SetLegend($option_array[3]); $p4->SetColor("black"); $p4->SetCenter();

Page 217: Build Automation Using Wireless Sensor Network

$g->Add($p4); } if($numline>=5 && $serr != 4){ $p5 = new LinePlot($ydata[4]); $p5->SetLegend($option_array[4]); $p5->SetColor("orange"); $p5->SetCenter(); $g->Add($p5); } $g->Stroke(); ?>

Page 218: Build Automation Using Wireless Sensor Network

17. Register.php <html> <head> <title>Register</title> <!-- start Css --> <link rel="stylesheet" type="text/css" href="StyleSheetCherry.css"title="myStyle"> <!-- end Css --> </style> <script language="Javascript"> <!-- Begin function resetform() { document.forms[0].elements[1]==""; } function submitForms() { if (isName() && isEmail() && isUser() && isPass() && isPicture() ) alert("Thank you for Register"); else return false; } function isName() { if (document.forms[0].Name.value == "") { alert ("\n The Name field is blank. \n\n Please enter your name.") document.forms[0].Name.focus(); return false; } return true; } function isEmail() { if (document.forms[0].Email.value == "") { alert ("\n The E-Mail field is blank. \n\n Please enter your E-Mail address.") document.forms[0].Email.focus();

Page 219: Build Automation Using Wireless Sensor Network

return false; } if (document.forms[0].Email.value.indexOf ('@',0) == -1 || document.forms[0].Email.value.indexOf ('.',0) == -1) { alert ("\n The E-Mail field requires a \"@\" and a \".\"be used. \n\nPlease re-enter

your E-Mail address.") document.forms[0].Email.select(); document.forms[0].Email.focus(); return false; } return true; } function isUser() { if (document.forms[0].User.value == "") { alert ("\n The Username Name field is blank. \n\nPlease enter your user name.") document.forms[0].User.focus(); return false; } if (document.forms[0].User.value.length<6) { alert ("\n The Username must be 6 character at least. \n\nPlease enter your

password.") document.forms[0].User.focus(); return false; } return true; } function isPass() { if (document.forms[0].Password.value.length<6) {

Page 220: Build Automation Using Wireless Sensor Network

alert ("\n The Password must be 6 character at least. \n\nPlease enter your password.")

document.forms[0].Password.focus(); return false; } if (document.forms[0].elements[4].value == "") { alert ("\n The Password field is blank. \n\nPlease enter your password.") document.forms[0].elements[4].focus(); return false; } if (document.forms[0].elements[5].value == "") { alert ("\n The Password field is blank. \n\nPlease enter your password.") document.forms[0].elements[5].focus(); return false; } if (document.forms[0].elements[4].value != document.forms[0].elements[5].value) { alert ("\n The password are unmatch. \n\nPlease insert password again.") document.forms[0].elements[4].focus(); return false; } return true; } function isPicture() { if (document.forms[0].elements[6].value == "") { alert ("\n The Picture field is blank. \n\nPlease select your picture.") document.forms[0].elements[6].focus(); return false; } if (document.forms[0].elements[6].value.indexOf ('.jpg',0) == -1

Page 221: Build Automation Using Wireless Sensor Network

&& document.forms[0].elements[6].value.indexOf ('.png',0) == -1 && document.forms[0].elements[6].value.indexOf ('.gif',0) == -1) { alert ("\n The Picture is invalid. \n\nPlease select your picture type as jpg, gif,

png.") document.forms[0].elements[6].focus(); return false; } return true; } --> </script> </head> <body bgcolor=black> <p align="center"><font size="6" color="#fc7b08"><b>Building Automation System Using Wireless

Sensor Network</b></font></p> <form name=infoGuest action="addRegister.php" method="post" enctype="multipart/form-data"

onSubmit="return submitForms()"> <table align="center" > <th align="center" colspan="2"><font size="5"color="#f60628"> Register Form</font></th> <tr> <td align="right" ><font color="#fa6627" size="4">Name</font><font color="white"

size="4">*<font color="#fa6627" size="4"> :</font> <td ><input type="text" name="Name"> </tr> <tr>

Page 222: Build Automation Using Wireless Sensor Network

<td align="right" ><font color="#fa6627" size="4">Address : </font> <td><font color="#fa6627" size="4"> <input type="text" name="Address" > </font> </tr> <tr> <td align="right" ><font color="#fa6627" size="4">Email</font><font color="white"

size="4">*<font color="#fa6627" size="4"> : </font> <td><font color="#fa6627" size="4"><input type ="text" name="Email"></font> </tr> <tr>

<td align="right" ><font color="#fa6627" size="4">Username</font><font color="white" size="4">*<font color="#fa6627" size="4"> : </font>

<td ><font color="#fa6627" size="4"> <input type="text" name="User"><font color="#fa6627" size="3"> must be 6 character

at least</font> </tr> <tr> <td align="right"><font color="#fa6627" size="4">Password</font><font color="white"

size="4">*<font color="#fa6627" size="4"> : </font> <td><font color="#fa6627" size="4"><input type="password" name="Password" >

<font color="#fa6627" size="3"> must be 6 character at least</font> </tr> <tr> <td align="right" ><font color="#fa6627" size="4">Confirm Password</font><font

color="white" size="4">*<font color="#fa6627" size="4"> : </font> <td><font color="#fa6627" size="4">

Page 223: Build Automation Using Wireless Sensor Network

<input type="password" name="Confirm" ></font> </tr>

<tr> <td align="right"><font color="#fa6627" size="4">Picture</font><font color="white"

size="4">*<font color="#fa6627" size="4"> : </font> <td><font color="#fa6627" size="4"><input type="file" name="Picture"> </font>

</tr> <tr> <td align="right"><font color="#fa6627" size="4"> status :

<td><select name='status'><option value='User'>User</option></select></font> </tr> <tr> <td colspan="2" align="center"><br> <input type="submit" value="Submit">&nbsp;&nbsp <input type="reset" value="Clear"> </tr> </table> </body></html>

Page 224: Build Automation Using Wireless Sensor Network

18. Remove_mem.php <? session_start(); if(($_SESSION["userid"]=="")||($_SESSION["status"]=="User")) echo "<meta http-equiv=Refresh content='1;URL=index.php'>" ; include ("config.inc.php"); $result = mysql_query("SELECT * FROM member WHERE userid='$_GET[userid]'"); $row=mysql_fetch_array($result); $result2 = mysql_query("SELECT * FROM member WHERE userid='$_GET[userid]'"); $row2=mysql_fetch_array($result2); ?> <html> <head><title> Remove_mem.php</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> </head> <body background="Background3.gif"> <?php if($_GET[action]=="") { ?> <form name=delete method=POST action="Remove_mem.php?action=delete&userid=<?echo

$_GET[userid];?>"> <table align=center >

<th bgcolor=red align=center colspan=2><font color=white >You want to Remove !</font> <tr> <td align=right>User id : <td><?echo $_GET[userid];?> </tr> <tr> <td align=right>Name : <td><?echo $row[name];?>

Page 225: Build Automation Using Wireless Sensor Network

</tr> <tr> <td align=right>Email : <td><?echo $row[email];?> </tr> <tr> <td align=right>User : <td><?echo $row[username];?> </tr> <tr> <td align=right>status : <td><?echo $row[status];?> </tr> <tr> <td align=right>Picture: <td><img src="<?echo $row[path];?>" height=200 width=200> </tr> </table><br><br><input type=radio name=verified value=1>Yes <input type=radio name=verified

value=0>No<p> <input type=submit value="OK"></center> </form> <?} if($_GET[action]=="delete" && $_POST[verified]) { echo "<p align=center><font color=red>Delete ID :". $_GET[userid] ." Success </p>"; echo "<p align=center><a href=Show_mem.php>กลบหนา Show member</a></p>"; mysql_query("DELETE FROM member WHERE `userid` = $_GET[userid] LIMIT 1"); echo"<meta http-equiv=Refresh content='2;URL=Show_mem.php'>";

Page 226: Build Automation Using Wireless Sensor Network

} if($_GET[action]=="delete"&& !$_POST[verified]){ echo "<p align=center><font color=red>Not change </font></p>"; echo "<p align=center><a href=Admin.php>กลบหนา Admin</a></p>"; echo"<meta http-equiv=Refresh content='2;URL=Admin.php'>"; }?> </body> </html>

Page 227: Build Automation Using Wireless Sensor Network

19. Show_mem.php <? session_start(); ?> <?php if(($_SESSION["userid"]=="")||($_SESSION["status"]!="Admin")) echo"<meta http-

equiv=Refresh content='1;URL=index.php'>";?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> show member list </title> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!-- if (document.images){ image1 = new Image(131, 33); image1.src = "images/top_nav_small_tab_hover.gif"; } //--> </script> <style type="text/css"> <!--

.style1 {color: #F4F4F4}

.style2 {font-size: 14}

.style3 {font-size: 14px} --> </style> </head> <body> <ul id="topnav"> <li><a href="home.php" class="smalltab">Home</a></li>

Page 228: Build Automation Using Wireless Sensor Network

<li class="bigtab" ><a href="Admin.php">Admin</a></li> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li> <li><a href="tmotestatistic.php" class="smalltab">Statistic</a></li> <li><a href="floor3.php" class="smalltab">Floor 3</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li> </ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/> <img src="images/main_content_header_900.gif" width=900 height=3> <img src="images/main_content_header_900.gif" width=900 height=3> <div id="container"><br> <center><font size="5" color="black">Show all member</font> <?php $p=$_GET[p]; $sort=$_GET[sort]; $order=$_GET[order]; include("config.inc.php"); $viewpage="20"; $total = mysql_num_rows(mysql_query("SELECT * FROM member")); if($total > $viewpage ){ $loop=ceil($total/$viewpage); echo "<center>Page "; for($i=1;$i<=$loop;$i++){

echo "[<a href=Show_mem.php?p=$i&sort=$sort&order=$order><font color=#665EED>-$i-</font></a>]";}

echo "</center>";

Page 229: Build Automation Using Wireless Sensor Network

} if($p=="") $p=1; $li1=($p-1)*$viewpage; if($order == "" || $order=="i"){$order2="d";} else if($order == "d"){$order2="i";} ?><br><br> <table align=center bgcolor=#fc7b08 border=0 cellspacing=1 cellpadding=3> <tr bgcolor="#FFFFFF"> <td width=20 align=center><b><a href=Show_mem.php?sort=userid&order=<?echo

$order2?>>userid</a></b></td> <td width=100 align=center><b><a href=Show_mem.php?sort=name&order=<?echo

$order2?>>Name</a></b></td> <td width=150 align=center><b><a href=Show_mem.php?sort=email&order=<?echo

$order2?>>Email</a></b></td> <td width=80 align=center><b><a href=Show_mem.php?sort=username&order=<?echo

$order2?>>Username</a></b></td> <td width=120 align=center><b><font size=4 color="#fc7b08">Picture</font></b></td> <? if($_SESSION[status]=="Admin") echo "<td bgcolor=white width=60><b><font

color=#fc7b08 size=4><a href=Show_mem.php?sort=status&order=$order2

>status</a></font></b></td>"."<td bgcolor=white width=100 align=center><b><font color=#fc7b08 size=4>Edit / Delete</font></b></td>";

?> </tr>

Page 230: Build Automation Using Wireless Sensor Network

<? include("config.inc.php"); if($sort==""){$sort="userid";} if($order=="" || $order=="i"){$or="ASC";} else if($order=="d"){$or="DESC";} $result = mysql_query("SELECT * FROM member ORDER BY $sort $or LIMIT $li1,$viewpage"); while($row=mysql_fetch_array($result)){ echo "<tr>"; echo "<td bgcolor=white align=center><font

size=4>".$row["userid"]."</font></td>"; echo "<td bgcolor=white><font size=3>".$row["name"]."</font></td>"; echo "<td bgcolor=white><font size=3>".$row["email"]."</font></td>"; echo "<td bgcolor=white align=center><font

size=3>".$row["username"]."</font></td>"; echo "<td bgcolor=white align=center><img height=200 width=200

src=".$row["path"]."></td>"; if($_SESSION[status]=="Admin") { echo "<td bgcolor=white align=center><font color=red

size=3>$row[status]</td>"."<td bgcolor=white align=center><a href=Edit_mem.php?userid=$row[userid]><font color=#665EED size=3>Edit</font></a> / <a href=Remove_mem.php?userid=$row[userid]><font color=#665EED size=3>Delete</font></a></td>";

} print "</tr>"; }?> </table><br> <? if($total > $viewpage ){

Page 231: Build Automation Using Wireless Sensor Network

$loop=ceil($total/$viewpage); //เศษปดขนหมด echo "<center>Page ";

for($i=1;$i<=$loop;$i++){echo "[<a href=Show_mem.php?p =$i&sort=$sort&order=$order><font color=#665EED>-$i-</font></a>]";}

echo "</center>"; } if($p=="") $p=1; $li1=($p-1)*$viewpage; $li2=($p)*$viewpage; if($order == "" || $order=="i"){$order2="d";} else if($order == "d"){$order2="i";} ?> <p id="footer2">By <a href="contact_us.php">Smart Building Group</a></p> </body> </html>

Page 232: Build Automation Using Wireless Sensor Network

20. tmoterealtime.php <? session_start(); if($_SESSION["userid"]==""){

echo"<meta http-equiv=Refresh content='1;URL=index.php'>"; return false;

}?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Wireless Sensor Network Real Time</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!-- if (document.images){ image1 = new Image(131, 33); image1.src = "images/top_nav_small_tab_hover.gif"; } //--> </script> <script type="text/javascript" src="Set_detail_mote.js"> </script> </style> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <meta http-equiv="refresh" content="20"; <style type="text/css"> <!-- td{font-family:Arial,sans-serif;font-size:10pt}

th{font-family:Arial,sans-serif;font-size:10pt;color:white}--> </style> </head>

Page 233: Build Automation Using Wireless Sensor Network

<body > <ul id="topnav"> <li><a href="home.php" class="smalltab">Home</a></li> <? if($_SESSION["status"] == "Admin") echo "<li><a href=admin.php class=smalltab>Admin</a></li>" ?> <li class="bigtab"><a href="#" >Realtime</a></li> <li><a href="tmotestatistic.php" class="smalltab">Statistic</a></li> <li><a href="floor3.php" class="smalltab">Floor 3</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li> </ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img src="images/main_content_header_900.gif" width=900 height=3> <div id="container"> <? $Name=$_GET["moteroom"]; if ($Name=="") $Name="All mote"; include("config.inc.php"); $or="DESC"; if($Name!="All mote"){

$result = mysql_query("SELECT * FROM moteroom WHERE room = '$Name' ORDER BY no ASC " ) or die ("Error in query: $query. " . mysql_error());

$i=0; while($row=mysql_fetch_array($result)){ $moteid[$i]= $row["moteid"]; $mote_room[$i]=$row["room"];

Page 234: Build Automation Using Wireless Sensor Network

$i++; }

} else{

$result = mysql_query("SELECT * FROM moteroom WHERE 1 ORDER BY no ASC " ) or die ("Error in query: $query. " . mysql_error());

$i=0; while($row=mysql_fetch_array($result)){ $moteid[$i]= $row["moteid"]; $mote_room[$i]=$row["room"]; $i++;

} } ?> <br><center> <table bgcolor="#f4afb5" border="1" bordercolor="#7b8c93" cellspacing="0" height="60" width="800"> <tr height="30" align="center"> <td align="center" bgcolor="#663333" > <font color="#ffffff">Real Time Sensor of <?php echo $Name; ?> </font> </tr> </table> <table bgcolor="#ffffff" border="1" bordercolor="#cccccc" cellspacing="0" width="800"> <tr height="30" bgcolor="#999966"> <td align="center" width="100">Room <td align="center" width="160">Time <td align="center" width="70">Mote <td align="center" width="80">TSR(Lux)

Page 235: Build Automation Using Wireless Sensor Network

<td align="center" width="80">PAR <td align="center" width="130">Tempurature(C) <td align="center" width="90">Quality <td align="center" width="90">Comment </tr> <? $countError=0; for($a=0;$a<count($moteid);$a++){ $result = mysql_query("SELECT * FROM tmote WHERE moteid='$moteid[$a]'

ORDER BY No $or LIMIT 1"); $row=mysql_fetch_array($result); ?> <tr bgcolor="#EEE8AA"> <? if($mote_room[$a]==""){$mote_room[$a]="Connecter"; }?> <td align="center" width="100"> <?php echo "<a href=floor3.php>".$mote_room[$a]."</a>"; ?> <td align="center" width="160"> <?php echo $row["time"]; ?> <td align="center" width="70"> <?php echo "<a href=floor3.php>".$moteid[$a]."</a>"; ?> <td align="center" width="80"> <?php echo $row["reading1"]; ?> <td align="center" width="80"> <?php echo $row["reading2"]; ?> <td align="center" width="130"> <?php echo $row["reading3"]; ?> <td align="center" width="90"> <?php echo $row["reading4"]; ?> <td align="center" width="90"> <?php echo $row["comment"]; ?> </tr>

Page 236: Build Automation Using Wireless Sensor Network

<? $Temp= $row["reading3"]; $Light=$row["reading1"]; $Time2=$row["time"]; $Time2 = str_replace("-","",$Time2); $Time2 = str_replace(":","",$Time2); $Time2 = str_replace(" ","",$Time2); $timein1 = date ("Ym"); $timein2 = date ("j"); if($timein2<10){ $timein2="0".$timein2;} $timein3 = date ("His"); $timein = $timein1.$timein2.$timein3; $timeHH = date ("His"); $Timemote=($timein-$Time2); $isError=$row["comment"];

if(($Timemote>("300"))&&($isError!="Packet Error")&&($Temp>100)){

$warning[$countError]="--- ".$row["moteid"]." Disconnect after Hight Temperature. May be Fire !!!!!.";

$countError++; $mid=1000; }

else if(($Timemote>("300"))&&($isError!="Packet Error")){ $warning[$countError]="--- ".$row["moteid"]." Disconnect.";

$mid3=1; $countError++;

} elseif(($Temp>100)&&($isError!="Packet Error")){

$warning[$countError]="--- Temperature at ".$row["moteid"]." very Hot !!! Please check Now!!!!.";

$countError++; $mid=1000; }

Page 237: Build Automation Using Wireless Sensor Network

elseif(($Temp<22)&&($isError!="Packet Error")){ $warning[$countError]="--- Temperature at ".$row["moteid"]." very cold.";

$countError++; $mid2=10; }

elseif(($timeHH>220000)&&($Light>50)){ $warning[$countError]="--- Lighting at ".$row["moteid"]." turn on after 22.00 o'clock.";

$countError++; $mid2=10; }

}?> </table></center><br><center> <table bgcolor="red" > <? for($rw=0;$rw<(count($warning));$rw++){ if($rw==0){ echo "<tr><td><center><font size=5 color=white>WARNING</center></tr>"; echo "<tr><td><font size=4 color=white>".$warning[$rw]."</tr>";

} else{ echo "<tr><td><font size=4 color=white>".$warning[$rw]."</tr>"; } } ?> </table> <br> <form name=myform action=tmoterealtime.php?moteroom= target="_parent" method=GET> Select Room : <select name="moteroom"> <option value="All mote" >All mote</option> <option value="Lab_Commu" >Communications Lab</option> <option value="Lab_Comp1" >Computer Lab</option> <option value="Comp1" >Computer1</option> <option value="Comp2" >Computer2</option>

Page 238: Build Automation Using Wireless Sensor Network

<option value="Embeded" >Embeded</option> <option value="Com_Project" >Computer project</option> </select> <input type="submit" value="Go!"> </form> * Select All mote may be take along time.<br><br> <? $Name = str_replace(" ","_%$%_",$Name); ?> <? echo "<form name=Statistic action=tmotestatistic.php?Name=".$Name." target=_parent method=post

enctype=multipart/form-data onSubmit=return submitForms()>"; echo "<center><input type=submit value=Statistic></center>"; ?> <br><font color="orange">** This page will be automatic update every 20 second.<br> Select more data will be take along time or low speed connection. </font></center><br> <table align=center>

<tr> <td> <div align=center> <object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"

width="230" height="44" hspace="10" align="left" id="mediaplayer1" align=center> <param name="FileName" value=<? if($mid==1000){echo "midi2.mid";}

elseif($mid2==10){echo "midi1.mid";} elseif($mid3==1){echo "midi3.mid";} ?>>

<param name="Autostart" value="True"> <param name="ShowControls" value="True"> <param name="Showstatusbar" value="False"> <param name="ShowDisplay" value="False"> <param name="Autorewind" value="False"> <param name="Repeat" value="True">

<PARAM NAME="Volume" VALUE="0">

Page 239: Build Automation Using Wireless Sensor Network

<embed src=<? if($mid==1000){echo "midi2.mid";} elseif($mid2==10){echo "midi1.mid";} elseif($mid3==1){echo "midi3.mid";} ?> width="230" height="44" hspace="10" autostart="True" align="left" filename=<? if($mid==1000){echo "midi2.mid";} elseif($mid2==10){echo "midi1.mid";} elseif($mid3==1){echo "midi3.mid";} ?> showcontrols="True" showstatusbar="False" showdisplay="False" Volume="0" autorewind="False"type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/"></embed>

</object> </div> </tr>

</table> </center> <p id="footer2">By <a href="contact_us.php">Smart Building Group</a></p> </body> </html>

Page 240: Build Automation Using Wireless Sensor Network

21. tmotestatistic.php <? session_start(); ?> <? if($_SESSION["userid"]==""){echo"<meta http-equiv=Refresh content='1;URL=index.php'>"; return false;} ?> <!DOCTYPE html PUBLIC "-//W3C//Dtd align="center" XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <title>Wireless Sensor Network Statistic</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script language="javascript"> var i=0;

function checkBoxes(obj){ count =0; if(document.myform.Year2.value < document.myform.Year1.value){ alert("Please enter valid year"); return false; } else if(document.myform.Year2.value == document.myform.Year1.value){ if(document.myform.Month2.value < document.myform.Month1.value){ alert("Please enter valid month"); return false; } else if(document.myform.Month2.value == document.myform.Month1.value){ if(document.myform.Day2.value < document.myform.Day1.value){ alert("Please enter valid date"); return false;

Page 241: Build Automation Using Wireless Sensor Network

} else if(document.myform.Day2.value == document. myform.Day1.value){

if (obj.form.elements["hour_array[]"][1].value) <(obj.form.elements["hour_array[]"][0].value)){

alert("Please enter valid hour"); return false;

} else if ((obj.form.elements["hour_array[]"][1].value)

==(obj.form.elements["hour_array[]"][0].value)){ if((obj.form.elements["minute_array[]"][1].value)

<(obj.form.elements["minute_array[]"][0].value)){

alert("Please enter valid minute"); return false;

} } } } } for (i = 0; i < obj.form.elements["option_array[]"].length; i++){ if(obj.form.elements["option_array[]"][i].checked) count++; } if (count==0){ alert("Please select data."); return false; } return true;

}

Page 242: Build Automation Using Wireless Sensor Network

</script> <script language=JavaScript src="CalendarPopup.js"></script> <script language=JavaScript>document.write(getCalendarStyles());</script> <style> a{text-decoration:none;} a:link { color: none; text-decoration: none; } a:visited { color: none; text-decoration: none; } a:hover { color: none; text-decoration: none; } a:active { color: none; text-decoration: none; } </style> </head> <body bgcolor="#D0DCE0"> <ul id="topnav"> <li><a href="home.php" class="smalltab">Home</a></li> <? if($_SESSION["status"] == "Admin") echo "<li><a href=admin.php class=smalltab>Admin</a></li>" ?> <li><a href="tmoterealtime.php" class="smalltab">Realtime</a></li>

Page 243: Build Automation Using Wireless Sensor Network

<li class="bigtab"><a href="tmotestatistic.php" >Statistic</a></li> <li><a href="floor3.php" class="smalltab">Floor 3</a></li> <li><a href="floor4.php" class="smalltab">Floor 4</a></li> <? if($_SESSION["status"] == "User")echo "<li><a href=contact_us.php class=smalltab>Contact us</a></li>" ?><li><a href="Logout.php" class="smalltab">Log Out</a></li> </ul> <img src="images/slogan_box.jpg" alt="slogan box" width=900 height=80/><img src="images/main_content_header_900.gif" width=900 height=3> <div id="container"> <center> <?$moteid=$_POST["moteid"]; $option_array = $_POST[option_array]; $hour_array = $_POST[hour_array]; $minute_array = $_POST[minute_array]; $Type = $_POST[Type]; $time01=$_POST[Year1]."-".$_POST[Month1]."-".$_POST[Day1]."

".$hour_array[0].":".$minute_array[0]; $time02=$_POST[Year2]."-".$_POST[Month2]."-".$_POST[Day2]."

".$hour_array[1].":".$minute_array[1]; $Y1=$_POST[Year1]; $Y2=$_POST[Year2]; $M1=$_POST[Month1]; $M2=$_POST[Month2]; $D1=$_POST[Day1]; $D2=$_POST[Day2]; $H= date ("H"); $MN= date ("i");

Page 244: Build Automation Using Wireless Sensor Network

if($Y1==""){ $Y1= date ("Y"); $Y2= date ("Y"); } if($M1==""){ $M1= date ("m"); $M2= date ("m"); } if($D1==""){ $D1= date ("j"); $D2= date ("j"); if($D1<10){ $D1="0".$D1; $D2="0".$D2; }} ?> <table width="900">

<tr> <td width="200" valign="top">

<table width="200"> <form name=myform action=tmotestatistic.php method=POST>

<tr> <td colspan="2" align="left" width="200"><strong>Show :

</strong> <select name="Type" >

<option value="Statistic" <? if($Type=="Statistic"){echo "selected";}?>>Statistic</option>

<option value="Graph" <? if($Type==""){echo "selected";}?>>Graph </option></select>

</tr> <tr>

<td align="left" colspan="2" align="left" width="200"> <strong>Of :</strong>

<select name="moteid"> <?php for($i=1;$i<=30;$i++) { echo "<option value= mote".$i.">mote".$i."</option> ";} ?> </select> </tr> <tr> <td align="left" colspan="2" width="200"> <strong>Form : </strong><br></tr>

Page 245: Build Automation Using Wireless Sensor Network

<tr> <td align="left" colspan="2" width="200"><select name="Year1" > <?php for($i=2008;$i<=2028;$i++) { echo "<option value=".$i; if($i==$Y1){ echo " selected ";} echo

">".$i."</option> "; } ?> </select> <select name="Month1"> <?php for($i=01;$i<=12;$i++) { if($i<10){

echo "<option value=0".$i; if($i==$M1){ echo " selected ";} echo ">0".$i."</option> ";

} else {

echo "<option value=".$i; if($i==$M1){

echo " selected "; } echo ">".$i."</option> ";

} } ?> </select>

<select name="Day1"> <?php for($i=01;$i<=31;$i++) {

if($i<10){ echo "<option value=0".$i; if($i==$D1){ echo " selected ";} echo ">0".$i."</option> ";

} else {

echo "<option value=".$i; if($i==$D1){ echo " selected ";}

Page 246: Build Automation Using Wireless Sensor Network

echo ">".$i."</option> "; }} ?> </select>

</tr> <tr> <td align="left" colspan="2" width="200"> <select name="hour_array[]"> <?php for($i=0;$i<=23;$i++) { ?> <? if ($i<10){

echo "<option value=0".$i; if($i==($H-1)){ echo " selected ";} echo " >0".$i." </option>";

} else {

echo "<option value=".$i; if($i==($H-1)){ echo " selected ";} echo ">".$i."</option> ";

}?> <? } ?> </select> : <select name="minute_array[]"> <?php for($i=0;$i<=59;$i++) { ?> <? if ($i<10){ echo "<option value=0".$i." >0".$i." </option>"; } else {echo "<option value=".$i.">".$i."</option> "; }?> <? } ?> </select> </tr> <tr>

<td align="left" colspan="2" width="200"> <strong>To :</strong><br>

Page 247: Build Automation Using Wireless Sensor Network

</tr> <tr> <td colspan="2" width="200"align="left"><select name="Year2"> <?php for($i=2008;$i<=2028;$i++) { echo "<option value=".$i;

if($i==$Y2){ echo " selected ";} echo ">".$i."</option> ";} ?>

</select> <select name="Month2"> <?php for($i=01;$i<=12;$i++) { if($i<10){echo "<option value=0".$i;

if($i==$M2){ echo " selected ";} echo ">0".$i."</option> ";}

else {echo "<option value=".$i; if($i==$M2){ echo " selected ";} echo ">".$i."</option> ";}} ?> </select>

<select name="Day2"> <?php for($i=01;$i<=31;$i++) { if($i<10){

echo "<option value=0".$i; if($i==$D2){ echo " selected ";} echo ">0".$i."</option> ";}

else {echo "<option value=".$i if($i==$D2){ echo " selected ";} echo ">".$i."</option> ";}

} ?> </select>

</tr>

Page 248: Build Automation Using Wireless Sensor Network

<tr> <td > <td align="left" > <select name="hour_array[]"> <?php for($i=0;$i<=23;$i++) { ?> <? if ($i<10){ echo "<option value=0".$i;

if($i==$H){ echo " selected ";} echo " >0".$i." </option>"; }

else {echo "<option value=".$i; if($i==$H){ echo " selected ";} echo ">".$i."</option> "; }?>

<? } ?> </select> : <select name="minute_array[]"> <?php for($i=0;$i<=59;$i++) { ?> <? if ($i<10){

echo "<option value=0".$i; if($i==$MN){ echo " selected ";} echo " >0".$i." </option>";

} else {echo "<option value=".$i;

if($i==$MN){ echo " selected ";} echo ">".$i."</option> "; }?>

<? } ?> </select> </tr> <tr>

<td colspan="2" align=left width="200"><br> <strong>Select Data </strong><br> <? $option_checked=$option_array;

Page 249: Build Automation Using Wireless Sensor Network

$ck0=$option_checked["0"]; $ck1=$option_checked["1"]; $ck2=$option_checked["2"]; $ck3=$option_checked["3"]; ?>

<input type="checkbox" name="option_array[]" value="reading1" <? if($ck0=="reading1"){ echo " checked "; }?> >

TSR(Lux)<br> <input type="checkbox" name="option_array[]" value="reading2" <? if(($ck0=="reading2")||($ck1=="reading2")){ echo " checked "; }?> >

PAR <br> <input type="checkbox" name="option_array[]" value="reading3" <? if(($ck0=="reading3")||($ck1=="reading3")||($ck2=="reading3")||($ck0

=="")){ echo " checked "; }?>> Temperature(C)<br>

<input type="checkbox" name="option_array[]" value="reading4" <? if(($ck0=="reading4")||($ck1=="reading4")||($ck2=="reading4")||($ck3

=="reading4")){ echo " checked "; }?> > Quality<br> </tr> <tr>

<td align="center" colspan="2" ><br><input type="submit" value="Submit" onClick="return checkBoxes(this)">

<input type="reset" name="reset" value="Clear">

Page 250: Build Automation Using Wireless Sensor Network

</tr> </table> </form> <td align="center" width="700"> <?if($Type=="Graph"){ $option_array=join(",",$option_array); $option_array=ereg_replace(" ","_",$option_array); $time01=ereg_replace(" ","_",$time01); $time02=ereg_replace(" ","_",$time02); $Name = str_replace(" ","_%$%_",$Name); echo"<meta http-equiv=Refresh content='0;URL

=graph.php?moteid=".$moteid."&Time1=".$time01."&Time2=".$time02."&opti

on=".$option_array." target=_parent'"; }

else{ if($moteid==""){

echo "<center><table align=center width=600><tr><td align=left><strong>Please select iformation form left panel.<br><br></strong></tr>";

echo "<tr><td align=left>1.Select type to show data (Statistic table or Graph).<br><br>";

echo "<tr><td align=left>2.Select Mote.<br><br></tr>"; echo "<tr><td align=left>3.Select time to show.<br><br></tr>"; echo "<tr><td align=left>4.Select Data of mote.<br><br></tr>"; echo "<tr><td align=left>5.Export data to excel, Please select type

Statistic.<br><br></tr>"; echo "<tr><td align=left>* Select more Data and/or more time will be take along

time (Up on your speed).<br></tr>";

Page 251: Build Automation Using Wireless Sensor Network

echo "<tr><td align=left>** To see location of mote open <a href=floor3.php>Floor3</a> or <a href=floor4.php>Floor4</a> page.<br></tr>";

echo "<tr><td align=left>*** If you have problem with this page <a href=contact_us.php>contact us.</a></table>";

} else if ($option_array[0]==""){echo "<center><strong>Please select Data</strong>";} else { if((count($option_array))<4){ $WidthTable=(count($option_array) +2 )*130; } else{$WidthTable=(count($option_array) +2 )*110; } echo "<br><center>"; echo "<table align=center width=".$WidthTable.">"; echo "<tr bgcolor=#f4afb5 border=1 bordercolor=#7b8c93 cellspacing=0

height=60 align=center >"; echo "<td align=center bgcolor=#663333 colspan=54><font face=sans-serif

size=3 color=#ffffff>Statisctic Sensor of ".$moteid." from ".$time01."

to ".$time02; include("config.inc.php"); $or="ASC"; for ($n=0;$n<(count($option_array)+1);$n++) { if ($option_array[$n]=="reading1"){ $show_array[$n]="TRS";

$unit_array[$n]="Lux"; }

else if ($option_array[$n]=="reading2"){ $show_array[$n]="PAR"; $unit_array[$n]="micron";

} else if ($option_array[$n]=="reading3"){

Page 252: Build Automation Using Wireless Sensor Network

$show_array[$n]="Temperature"; $unit_array[$n]="C";

} else if ($option_array[$n]=="reading4"){

$show_array[$n]="Quality"; $unit_array[$n]=""; }

else { $show_array[($n)]="Comment"; $unit_array[$n]="";} } echo "<tr height=30 bgcolor= #CC9966 border=1 bordercolor=black

cellspacing=0 align=center >"; echo "<td align=center width=100>Time </td>"; for ($i=0;$i<(count($option_array)+1);$i++) { if($unit_array[$i]!=""){

echo "<td align=center width=80>".$show_array[$i]." (".$unit_array[$i].") </td>";

} else{echo "<td align=center width=80>".$show_array[$i]." </td>";} } $result = mysql_query("SELECT * FROM tmote WHERE (moteid='$moteid')

AND (time >= '$time01') And (time <= '$time02') ORDER BY time $or " );

$ck=0; $plusHieght=0; while($row=mysql_fetch_array($result)){ if($ck!=$row["time"]){ echo "<tr bgcolor=#EEE8AA border=1 bordercolor=black

cellspacing=0 align=center height=20 >"; echo "<td align=center

width=150>".$row["time"]."</td>

Page 253: Build Automation Using Wireless Sensor Network

</td>"; for ($i=0;$i<(count($option_array)+1);$i++) { echo "<td align=center width=80>"; if($i<(count($option_array))){

echo $row[$option_array[$i]]; }

else echo $row["comment"]; echo "</td> </td>"; } } else {$plusHieght++;} $ck=$row["time"]; echo "</tr>"; } $option_array=join(",",$option_array); $option_array=ereg_replace(" ","_",$option_array); $time01=ereg_replace(" ","_",$time01); $time02=ereg_replace(" ","_",$time02); $Name = str_replace(" ","_%$%_",$Name); echo "</tr></table><br><br><table><tr><td></center>"; echo "<form name=plotGraph action=graph.php?moteid

=".$moteid."&Time1=".$time01."&Time2=".$time02."&option=".$option_array." target=_parent method=post enctype=multipart/form-data onSubmit=return submitForms()>";

echo "<center><input type=submit value=ShowGraph></form> "; $Name = str_replace(" ","_%$%_",$moteid); echo "<td><form action=export_csv.php?Name

Page 254: Build Automation Using Wireless Sensor Network

=".$Name."&Time1=".$time01."&Time2=".$time02."&option=".$option_array." method=post target=_blank enctype=multipart/form-data> ";

echo "<center><input type=submit value=Export></form> "; }

}?> </tr> </table> </table> <table width=100> <? for($i=0;$i<$plusHieght;$i++){ ?> <tr><td height=20><? echo " ";}?>

</tr> </table> </div> <p id="footer2">By <a href="contact_us.php">Smart Building Group</a></p> </body> </html>

Page 255: Build Automation Using Wireless Sensor Network

22. My # Example MySQL config file for small systems. # # This is for a system with little memory (<= 64M) where MySQL is only used # from time to time and it's important that the mysqld daemon # doesn't use much resources. # # You can copy this file to # C:/xampp/mysql/bin/my.cnf to set global options, # mysql-data-dir/my.cnf to set server-specific options (in this # installation this directory is C:/xampp/mysql/data) or # ~/.my.cnf to set user-specific options. # # In this file, you can use all long options that a program supports. # If you want to know which options a program supports, run the program # with the "--help" option. # The following options will be passed to all MySQL clients [client] # password = your_password port = 3306 socket = "C:/xampp/mysql/mysql.sock" # Here follows entries for some specific programs # The MySQL server [mysqld] port= 3306 socket= "C:/xampp/mysql/mysql.sock" basedir="C:/xampp/mysql" tmpdir="C:/xampp/tmp" datadir="C:/xampp/mysql/data" skip-locking key_buffer = 32M max_allowed_packet = 2M table_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 16M # Don't listen on a TCP/IP port at all. This can be a security enhancement, # if all processes that need to connect to mysqld run on the same host. # All interaction with mysqld must be made via Unix sockets or named pipes.

Page 256: Build Automation Using Wireless Sensor Network

# Note that using this option without enabling named pipes on Windows # (via the "enable-named-pipe" option) will render mysqld useless! # # commented in by lampp security #skip-networking # Replication Master Server (default) # binary logging is required for replication # log-bin deactivated by default since XAMPP 1.4.11 #log-bin=mysql-bin # required unique id between 1 and 2^32 - 1 # defaults to 1 if master-host is not set # but will not function as a master if omitted server-id = 1 # Replication Slave (comment out master section to use this) # # To configure this host as a replication slave, you can choose between # two methods : # # 1) Use the CHANGE MASTER TO command (fully described in our manual) - # the syntax is: # # CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, # MASTER_USER=<user>, MASTER_PASSWORD=<password> ; # # where you replace <host>, <user>, <password> by quoted strings and # <port> by the master's port number (3306 by default). # # Example: # # CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, # MASTER_USER='joe', MASTER_PASSWORD='secret'; # # OR # # 2) Set the variables below. However, in case you choose this method, then # start replication for the first time (even unsuccessfully, for example # if you mistyped the password in master-password and the slave fails to # connect), the slave will create a master.info file, and any later # change in this file to the variables' values below will be ignored and # overridden by the content of the master.info file, unless you shutdown # the slave server, delete master.info and restart the slaver server. # For that reason, you may want to leave the lines below untouched # (commented) and instead use CHANGE MASTER TO (see above)

Page 257: Build Automation Using Wireless Sensor Network

# # required unique id between 2 and 2^32 - 1 # (and different from the master) # defaults to 2 if master-host is set # but will not function as a slave if omitted #server-id = 2 # # The replication master for this slave - required #master-host = <hostname> # # The username the slave will use for authentication when connecting # to the master - required #master-user = <username> # # The password the slave will authenticate with when connecting to # the master - required #master-password = <password> # # The port the master is listening on. # optional - defaults to 3306 #master-port = <port> # # binary logging - not required for slaves, but recommended #log-bin=mysql-bin # Point the following paths to different dedicated disks #tmpdir = "C:/xampp/tmp" #log-update = /path-to-dedicated-directory/hostname # Uncomment the following if you are using BDB tables #bdb_cache_size = 4M #bdb_max_lock = 10000 # Comment the following if you are using InnoDB tables skip-innodb innodb_data_home_dir = "C:/xampp/mysql/" innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = "C:/xampp/mysql/" innodb_log_arch_dir = "C:/xampp/mysql/" # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high innodb_buffer_pool_size = 16M innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size innodb_log_file_size = 5M innodb_log_buffer_size = 8M

Page 258: Build Automation Using Wireless Sensor Network

innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 32M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [isamchk] key_buffer = 40M sort_buffer_size = 40M read_buffer = 4M write_buffer = 4M [myisamchk] key_buffer =40M sort_buffer_size = 40M read_buffer = 4M write_buffer = 4M [mysqlhotcopy] interactive-timeout

Page 259: Build Automation Using Wireless Sensor Network

โคดโปรแกรมบนโทรศพทมอถอ ประกอบไปดวย 10 ไฟล ดงน 1. mobileWSN.java 2. LabComputer.java 3. Computer2.java 4. Computer1.java 5. Embeded.java 6. ComputerProject.java 7. Allmote.java 8. moteDisconnect.java 9. WSNMAP.java 10. gui.java

Page 260: Build Automation Using Wireless Sensor Network

1. mobileWSN.java //At Lab Communication import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; import java.lang.*; import java.util.*; public class mobileWSN extends MIDlet implements CommandListener { private Command exitCommand; private Display display; private Form displayForm; private Displayable d; public mobileWSN() throws IOException{ Image myImage = Image.createImage("/LabCommu_1.gif"); displayForm = new Form("Status of Mote"); displayForm.append(new ImageItem(null, myImage,ImageItem.LAYOUT_TOP, "map")); try{ String result = getViaHttpConnection("http://202.44.37.232/mote/ByRoom.php?room=Lab_Commu"); displayForm.append(" " + result); } catch (Exception exc){ exc.printStackTrace(); } exitCommand = new Command("Exit", Command.SCREEN, 1); displayForm.addCommand(exitCommand); displayForm.setCommandListener(this);}

Page 261: Build Automation Using Wireless Sensor Network

public void startApp(){ display = Display.getDisplay(this); display.setCurrent(displayForm); display.setCurrent(d); } public void pauseApp(){ } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s){ if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } public void ImageExample(){ d = new ImageCanvas(); d.setCommandListener(this); } class ImageCanvas extends Canvas{ Image myImage; public ImageCanvas(){ try{ myImage = Image.createImage("/LabCommu_1.gif"); }catch(java.io.IOException e){} }//end ImageCanvas public void paint(Graphics g){ g.drawImage(myImage,0,0,g.LEFT|g.TOP); }// end paint }// end ImageCanvas

Page 262: Build Automation Using Wireless Sensor Network

private String getViaHttpConnection(String url) throws IOException { HttpConnection connect = null; InputStream inputs= null; StringBuffer buffer = new StringBuffer(); try { connect = (HttpConnection)Connector.open(url); inputs = connect.openInputStream(); int ch; while ((ch = inputs.read()) != -1) { buffer.append((char)ch); } } finally { if (inputs != null) inputs.close(); if (connect != null) connect.close(); } String val = parse(buffer.toString()); System.out.println(val); return val; } private String parse(String str){ int L1 = str.indexOf("Light01 :"); int T1= str.indexOf("Temp01 :"); int W1 = str.indexOf("Warning01 :"); int L2 = str.indexOf("Light02 :"); int T2= str.indexOf("Temp02 :"); int W2 = str.indexOf("Warning02 :"); int L3 = str.indexOf("Light03 :"); int T3= str.indexOf("Temp03 :"); int W3 = str.indexOf("Warning03 :");

Page 263: Build Automation Using Wireless Sensor Network

String Light1 = ""; String Temp1 = ""; String Warn1 = ""; String Light2 = ""; String Temp2 = ""; String Warn2 = ""; String Light3 = ""; String Temp3 = ""; String Warn3 = ""; int a = 9; int b = 14; int c = 8; int d = 14; int e = 11; int f = 46; if (L1 != -1){Light1 = str.substring(L1+a, L1+b);} if (T1 != -1){Temp1 = str.substring(T1+c, T1+d);} if (W1 != -1){Warn1 = str.substring(W1+e, W1+f);} if (L2 != -1){Light2 = str.substring(L2+a, L2+b);} if (T2 != -1){Temp2 = str.substring(T2+c, T2+d);} if (W2 != -1){Warn2 = str.substring(W2+e, W2+f);} if (L3 != -1){Light3 = str.substring(L3+a, L3+b);} if (T3 != -1){Temp3 = str.substring(T3+c, T3+d);} if (W3 != -1){Warn3 = str.substring(W3+e, W3+f);} return ":: Lab Communication ::\n"+ "Mote 1 \n"+"Light : " + Light1 + "\nTemp : " + Temp1 + " C\n"+Warn1+"\n"+ "Mote 2 \n"+"Light : " + Light2 + "\nTemp : " + Temp2 + " C\n"+Warn2+"\n"+ "Mote 3 \n"+"Light : " + Light3 + "\nTemp : " + Temp3 + " C\n"+Warn3+"\n"; } }

Page 264: Build Automation Using Wireless Sensor Network

2. LabComputer.java //At Lab Computer import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; import java.lang.*; import java.util.*; public class LabComputer extends MIDlet implements CommandListener { private Command exitCommand; private Display display; private Form displayForm; private Displayable d; public LabComputer() throws IOException{ Image myImage = Image.createImage("/LabComputer_1.gif"); displayForm = new Form("Status of Mote"); displayForm.append(new ImageItem(null, myImage,ImageItem.LAYOUT_TOP, "map")); try{ String result = getViaHttpConnection("http://202.44.37.232/mote/ByRoom.php?room=Lab_Comp1"); displayForm.append(" " + result); } catch (Exception exc){ exc.printStackTrace(); } exitCommand = new Command("Exit", Command.SCREEN, 1); displayForm.addCommand(exitCommand); displayForm.setCommandListener(this);}

Page 265: Build Automation Using Wireless Sensor Network

public void startApp(){ display = Display.getDisplay(this); display.setCurrent(displayForm); } public void pauseApp(){ } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s){ if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } public void ImageExample(){ d = new ImageCanvas(); d.setCommandListener(this); } class ImageCanvas extends Canvas{ Image myImage; public ImageCanvas(){ try{ myImage = Image.createImage("/LabComputer_1.gif"); }catch(java.io.IOException e){} }//end ImageCanvas public void paint(Graphics g){ g.drawImage(myImage,0,0,g.LEFT|g.TOP); }// end paint }// end ImageCanvas

Page 266: Build Automation Using Wireless Sensor Network

private String getViaHttpConnection(String url) throws IOException { HttpConnection connect = null; InputStream inputs= null; StringBuffer buffer = new StringBuffer(); try { connect = (HttpConnection)Connector.open(url); inputs = connect.openInputStream(); int ch; while ((ch = inputs.read()) != -1) { buffer.append((char)ch); } } finally { if (inputs != null) inputs.close(); if (connect != null) connect.close(); } String val = parse(buffer.toString()); System.out.println(val); return val; } private String parse(String str){ int L4 = str.indexOf("Light04 :"); int T4= str.indexOf("Temp04 :"); int W4 = str.indexOf("Warning04 :"); int L5 = str.indexOf("Light05 :"); int T5= str.indexOf("Temp05 :"); int W5 = str.indexOf("Warning05 :"); int L6 = str.indexOf("Light06 :"); int T6= str.indexOf("Temp06 :"); int W6 = str.indexOf("Warning06 :");

Page 267: Build Automation Using Wireless Sensor Network

String Light4 = ""; String Temp4 = ""; String Warn4 = ""; String Light5 = ""; String Temp5 = ""; String Warn5 = ""; String Light6 = ""; String Temp6 = ""; String Warn6 = ""; int a = 9; int b = 14; int c = 8; int d = 14; int e = 11; int f = 46; if (L4 != -1){Light4 = str.substring(L4+a, L4+b);} if (T4 != -1){Temp4 = str.substring(T4+c, T4+d);} if (W4 != -1){Warn4 = str.substring(W4+e, W4+f);} if (L5 != -1){Light5 = str.substring(L5+a, L5+b);} if (T5 != -1){Temp5 = str.substring(T5+c, T5+d);} if (W5 != -1){Warn5 = str.substring(W5+e, W5+f);} if (L6 != -1){Light6 = str.substring(L6+a, L6+b);} if (T6 != -1){Temp6 = str.substring(T6+c, T6+d);} if (W6 != -1){Warn6 = str.substring(W6+e, W6+f);} return ":: Lab Computer ::\n"+ "Mote 4 \n"+"Light : " + Light4 + "\nTemp : " + Temp4 + " C\n"+Warn4+"\n"+ "Mote 5 \n"+"Light : " + Light5 + "\nTemp : " + Temp5 + " C\n"+Warn5+"\n"+ "Mote 6 \n"+"Light : " + Light6 + "\nTemp : " + Temp6 + " C\n"+Warn6+"\n"; } }

Page 268: Build Automation Using Wireless Sensor Network

3. Computer2.java //At Computer2 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; import java.lang.*; import java.util.*; public class Computer2 extends MIDlet implements CommandListener { private Command exitCommand; private Display display; private Form displayForm; private Displayable d; public Computer2() throws IOException{ Image myImage = Image.createImage("/Computer2_1.gif"); displayForm = new Form("Status of Mote"); displayForm.append(new ImageItem(null, myImage,ImageItem.LAYOUT_TOP, "map")); try{ String result = getViaHttpConnection("http://202.44.37.232/mote/ByRoom.php?room=Comp2"); displayForm.append(" " + result); } catch (Exception exc){ exc.printStackTrace(); } exitCommand = new Command("Exit", Command.SCREEN, 1); displayForm.addCommand(exitCommand); displayForm.setCommandListener(this);}

Page 269: Build Automation Using Wireless Sensor Network

public void startApp(){ display = Display.getDisplay(this); display.setCurrent(displayForm); } public void pauseApp(){ } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s){ if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } public void ImageExample(){ d = new ImageCanvas(); d.setCommandListener(this); } class ImageCanvas extends Canvas{ Image myImage; public ImageCanvas(){ try{ myImage = Image.createImage("/Computer2_1.gif"); }catch(java.io.IOException e){} }//end ImageCanvas public void paint(Graphics g){ g.drawImage(myImage,0,0,g.LEFT|g.TOP); }// end paint }// end ImageCanvas

Page 270: Build Automation Using Wireless Sensor Network

private String getViaHttpConnection(String url) throws IOException { HttpConnection connect = null; InputStream inputs= null; StringBuffer buffer = new StringBuffer(); try { connect = (HttpConnection)Connector.open(url); inputs = connect.openInputStream(); int ch; while ((ch = inputs.read()) != -1) { buffer.append((char)ch); } } finally { if (inputs != null) inputs.close(); if (connect != null) connect.close(); } String val = parse(buffer.toString()); System.out.println(val); return val; } private String parse(String str){ int L7 = str.indexOf("Light07 :"); int T7= str.indexOf("Temp07 :"); int W7 = str.indexOf("Warning07 :"); int L8 = str.indexOf("Light08 :"); int T8= str.indexOf("Temp08 :"); int W8 = str.indexOf("Warning08 :");

Page 271: Build Automation Using Wireless Sensor Network

String Light7 = ""; String Temp7 = ""; String Warn7 = ""; String Light8 = ""; String Temp8 = ""; String Warn8 = ""; int a = 9; int b = 14; int c = 8; int d = 14; int e = 11; int f = 46; if (L7 != -1){Light7 = str.substring(L7+a, L7+b);} if (T7 != -1){Temp7 = str.substring(T7+c, T7+d);} if (W7 != -1){Warn7 = str.substring(W7+e, W7+f);} if (L8 != -1){Light8 = str.substring(L8+a, L8+b);} if (T8 != -1){Temp8 = str.substring(T8+c, T8+d);} if (W8 != -1){Warn8 = str.substring(W8+e, W8+f);} return ":: Computer 2 ::\n"+ "Mote 7 \n"+"Light : " + Light7 + "\nTemp : " + Temp7 + " C\n"+Warn7+"\n"+ "Mote 8 \n"+"Light : " + Light8 + "\nTemp : " + Temp8 + " C\n"+Warn8+"\n"; } }

Page 272: Build Automation Using Wireless Sensor Network

4. Computer1.java //At LComputer1 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; import java.lang.*; import java.util.*; public class Computer1 extends MIDlet implements CommandListener { private Command exitCommand; private Display display; private Form displayForm; private Displayable d; public Computer1() throws IOException{ Image myImage = Image.createImage("/Computer1_1.gif"); displayForm = new Form("Status of Mote"); displayForm.append(new ImageItem(null, myImage,ImageItem.LAYOUT_TOP, "map")); try{ String result = getViaHttpConnection("http://202.44.37.232/mote/ByRoom.php?room=Comp1"); displayForm.append(" " + result); } catch (Exception exc){ exc.printStackTrace(); } exitCommand = new Command("Exit", Command.SCREEN, 1); displayForm.addCommand(exitCommand); displayForm.setCommandListener(this);}

Page 273: Build Automation Using Wireless Sensor Network

public void startApp(){ display = Display.getDisplay(this); display.setCurrent(displayForm); } public void pauseApp(){ } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s){ if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } public void ImageExample(){ d = new ImageCanvas(); d.setCommandListener(this); } class ImageCanvas extends Canvas{ Image myImage; public ImageCanvas(){ try{ myImage = Image.createImage("/Computer1_1.gif"); }catch(java.io.IOException e){} }//end ImageCanvas public void paint(Graphics g){ g.drawImage(myImage,0,0,g.LEFT|g.TOP); }// end paint }// end ImageCanvas

Page 274: Build Automation Using Wireless Sensor Network

private String getViaHttpConnection(String url) throws IOException { HttpConnection connect = null; InputStream inputs= null; StringBuffer buffer = new StringBuffer(); try { connect = (HttpConnection)Connector.open(url); inputs = connect.openInputStream(); int ch; while ((ch = inputs.read()) != -1) { buffer.append((char)ch); } } finally { if (inputs != null) inputs.close(); if (connect != null) connect.close(); } String val = parse(buffer.toString()); System.out.println(val); return val; } private String parse(String str){ int L9 = str.indexOf("Light09 :"); int T9= str.indexOf("Temp09 :"); int W9 = str.indexOf("Warning09 :"); int L10 = str.indexOf("Light10 :"); int T10= str.indexOf("Temp10 :"); int W10 = str.indexOf("Warning10 :");

Page 275: Build Automation Using Wireless Sensor Network

String Light9 = ""; String Temp9 = ""; String Warn9 = ""; String Light10 = ""; String Temp10 = ""; String Warn10 = ""; int a = 9; int b = 14; int c = 8; int d = 14; int e = 11; int f = 46; if (L9 != -1){Light9 = str.substring(L9+a, L9+b);} if (T9 != -1){Temp9 = str.substring(T9+c, T9+d);} if (W9 != -1){Warn9 = str.substring(W9+e, W9+f);} if (L10 != -1){Light10 = str.substring(L10+a, L10+b);} if (T10 != -1){Temp10 = str.substring(T10+c, T10+d);} if (W10 != -1){Warn10 = str.substring(W10+e, W10+f);} return ":: Computer 1 ::\n"+ "Mote 9 \n"+"Light : " + Light9 + "\nTemp : " + Temp9 + " C\n"+Warn9+"\n"+ "Mote 10 \n"+"Light : " + Light10 + "\nTemp : " + Temp10 + " C\n"+Warn10+"\n"; } }

Page 276: Build Automation Using Wireless Sensor Network

5. Embeded.java //Embeded import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; import java.lang.*; import java.util.*; public class Embeded extends MIDlet implements CommandListener { private Command exitCommand; private Display display; private Form displayForm; private Displayable d; public Embeded() throws IOException{ Image myImage = Image.createImage("/Embeded.gif"); displayForm = new Form("Status of Mote"); displayForm.append(new ImageItem(null, myImage,ImageItem.LAYOUT_TOP, "map")); try{ String result = getViaHttpConnection("http://202.44.37.232/mote/ByRoom.php?room=Embeded"); displayForm.append(" " + result); } catch (Exception exc){ exc.printStackTrace(); } exitCommand = new Command("Exit", Command.SCREEN, 1); displayForm.addCommand(exitCommand); displayForm.setCommandListener(this);}

Page 277: Build Automation Using Wireless Sensor Network

public void startApp(){ display = Display.getDisplay(this); display.setCurrent(displayForm); } public void pauseApp(){ } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s){ if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } public void ImageExample(){ d = new ImageCanvas(); d.setCommandListener(this); } class ImageCanvas extends Canvas{ Image myImage; public ImageCanvas(){ try{ myImage = Image.createImage("/Embeded.gif"); }catch(java.io.IOException e){} }//end ImageCanvas public void paint(Graphics g){ g.drawImage(myImage,0,0,g.LEFT|g.TOP); }// end paint }// end ImageCanvas

Page 278: Build Automation Using Wireless Sensor Network

private String getViaHttpConnection(String url) throws IOException { HttpConnection connect = null; InputStream inputs= null; StringBuffer buffer = new StringBuffer(); try { connect = (HttpConnection)Connector.open(url); inputs = connect.openInputStream(); int ch; while ((ch = inputs.read()) != -1) { buffer.append((char)ch); } } finally { if (inputs != null) inputs.close(); if (connect != null) connect.close(); } String val = parse(buffer.toString()); System.out.println(val); return val; } private String parse(String str){ int L11 = str.indexOf("Light11 :"); int T11= str.indexOf("Temp11 :"); int W11 = str.indexOf("Warning11 :"); int L12 = str.indexOf("Light12 :"); int T12= str.indexOf("Temp12 :"); int W12 = str.indexOf("Warning12 :");

Page 279: Build Automation Using Wireless Sensor Network

String Light11 = ""; String Temp11 = ""; String Warn11 = ""; String Light12 = ""; String Temp12 = ""; String Warn12 = ""; int a = 9; int b = 14; int c = 8; int d = 14; int e = 11; int f = 46; if (L11 != -1){Light11 = str.substring(L11+a, L11+b);} if (T11 != -1){Temp11 = str.substring(T11+c, T11+d);} if (W11 != -1){Warn11 = str.substring(W11+e, W11+f);} if (L12 != -1){Light12 = str.substring(L12+a, L12+b);} if (T12 != -1){Temp12 = str.substring(T12+c, T12+d);} if (W12 != -1){Warn12 = str.substring(W12+e, W12+f);} return "\n:: Embeded ::\n"+ "Mote 11 \n"+"Light : " + Light11 + "\nTemp : " + Temp11 + " C\n"+Warn11+"\n"+ "Mote 12 \n"+"Light : " + Light12 + "\nTemp : " + Temp12 + " C\n"+Warn12+"\n"; } }

Page 280: Build Automation Using Wireless Sensor Network

6. ComputerProject.java //At ComputerProject import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; import java.lang.*; import java.util.*; public class ComputerProject extends MIDlet implements CommandListener { private Command exitCommand; private Display display; private Form displayForm; private Displayable d; public ComputerProject() throws IOException{ Image myImage = Image.createImage("/ComProject.gif"); displayForm = new Form("Status of Mote"); displayForm.append(new ImageItem(null, myImage,ImageItem.LAYOUT_TOP, "map")); try{ String result = getViaHttpConnection("http://202.44.37.232/mote/ByRoom.php?room=Com_Project"); displayForm.append(" " + result); } catch (Exception exc){ exc.printStackTrace(); } exitCommand = new Command("Exit", Command.SCREEN, 1); displayForm.addCommand(exitCommand); displayForm.setCommandListener(this);}

Page 281: Build Automation Using Wireless Sensor Network

public void startApp(){ display = Display.getDisplay(this); display.setCurrent(displayForm); } public void pauseApp(){ } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s){ if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } public void ImageExample(){ d = new ImageCanvas(); d.setCommandListener(this); } class ImageCanvas extends Canvas{ Image myImage; public ImageCanvas(){ try{ myImage = Image.createImage("/ComProject.gif"); }catch(java.io.IOException e){} }//end ImageCanvas public void paint(Graphics g){ g.drawImage(myImage,0,0,g.LEFT|g.TOP); }// end paint }// end ImageCanvas

Page 282: Build Automation Using Wireless Sensor Network

private String getViaHttpConnection(String url) throws IOException { HttpConnection connect = null; InputStream inputs= null; StringBuffer buffer = new StringBuffer(); try { connect = (HttpConnection)Connector.open(url); inputs = connect.openInputStream(); int ch; while ((ch = inputs.read()) != -1) { buffer.append((char)ch); } } finally { if (inputs != null) inputs.close(); if (connect != null) connect.close(); } String val = parse(buffer.toString()); System.out.println(val); return val; } private String parse(String str){ int L13 = str.indexOf("Light13 :"); int T13= str.indexOf("Temp13 :"); int W13 = str.indexOf("Warning13 :"); int L14 = str.indexOf("Light14 :"); int T14= str.indexOf("Temp14 :"); int W14 = str.indexOf("Warning14 :");

Page 283: Build Automation Using Wireless Sensor Network

String Light13 = ""; String Temp13 = ""; String Warn13 = ""; String Light14 = ""; String Temp14 = ""; String Warn14 = ""; int a = 9; int b = 14; int c = 8; int d = 14; int e = 11; int f = 46; if (L13 != -1){Light13 = str.substring(L13+a, L13+b);} if (T13 != -1){Temp13 = str.substring(T13+c, T13+d);} if (W13 != -1){Warn13 = str.substring(W13+e, W13+f);} if (L14 != -1){Light14 = str.substring(L14+a, L14+b);} if (T14 != -1){Temp14 = str.substring(T14+c, T14+d);} if (W14 != -1){Warn14 = str.substring(W14+e, W14+f);} return "\n:: Computer Project ::\n"+ "Mote 13 \n"+"Light : " + Light13 + "\nTemp : " + Temp13 + " C\n"+Warn13+"\n"+ "Mote 14 \n"+"Light : " + Light14 + "\nTemp : " + Temp14 + " C\n"+Warn14+"\n"; } }

Page 284: Build Automation Using Wireless Sensor Network

7. Allmote.java import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; import java.lang.*; import java.util.*; public class Allmote extends MIDlet implements CommandListener { private Command exitCommand; private Display display; private Form displayForm; private Displayable d; public String Light1 = ""; public String Temp1 = ""; public String RecT1 = ""; public String Warn1_1 = ""; public String Light2 = ""; public String Temp2 = ""; public String RecT2 = ""; public String Warn1_2 = ""; public String Light3 = ""; public String Temp3 = ""; public String RecT3 = ""; public String Warn1_3 = ""; public String Light4 = ""; public String Temp4 = ""; public String RecT4 = ""; public String Warn1_4 = ""; public String Light5 = "";

Page 285: Build Automation Using Wireless Sensor Network

public String Temp5 = ""; public String RecT5 = ""; public String Warn1_5 = ""; public String Light6 = ""; public String Temp6 = ""; public String RecT6 = ""; public String Warn1_6 = ""; public String Light7 = ""; public String Temp7 = ""; public String RecT7 = ""; public String Warn1_7 = ""; public String Light8 = ""; public String Temp8 = ""; public String RecT8 = ""; public String Warn1_8 = ""; public String Light9 = ""; public String Temp9 = ""; public String RecT9 = ""; public String Warn1_9 = ""; public String Light10 = ""; public String Temp10 = ""; public String RecT10 = ""; public String Warn1_10 = ""; public String Light11 = ""; public String Temp11 = ""; public String RecT11 = ""; public String Warn1_11 = ""; public String Light12 = ""; public String Temp12 = ""; public String RecT12 = "";

Page 286: Build Automation Using Wireless Sensor Network

public String Warn1_12 = ""; public String Light13 = ""; public String Temp13 = ""; public String RecT13 = ""; public String Warn1_13 = ""; public String Light14 = ""; public String Temp14 = ""; public String RecT14 = ""; public String Warn1_14 = ""; public Allmote() throws IOException{ Image myImage = Image.createImage("/f3_1.gif"); displayForm = new Form("Status of Mote"); displayForm.append(new ImageItem(null, myImage,ImageItem.LAYOUT_TOP, "map")); try{ String result = getViaHttpConnection("http://202.44.37.232/mote/AllMote.php"); displayForm.append(" " + result);} catch (Exception exc){ exc.printStackTrace();} exitCommand = new Command("Exit", Command.SCREEN, 1); displayForm.addCommand(exitCommand); displayForm.setCommandListener(this); } public void startApp(){ display = Display.getDisplay(this); display.setCurrent(displayForm); } public void pauseApp(){ } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s){

Page 287: Build Automation Using Wireless Sensor Network

if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } public void ImageExample(){ d = new ImageCanvas(); d.setCommandListener(this); } class ImageCanvas extends Canvas{ Image myImage; public ImageCanvas(){ try{ myImage = Image.createImage("/f3_1.gif"); }catch(java.io.IOException e){} }//end ImageCanvas public void paint(Graphics g){ g.drawImage(myImage,0,0,g.LEFT|g.TOP); }// end paint }// end ImageCanvas private String getViaHttpConnection(String url) throws IOException { HttpConnection connect = null; InputStream inputs= null; StringBuffer buffer = new StringBuffer(); try { connect = (HttpConnection)Connector.open(url); inputs = connect.openInputStream(); int ch; while ((ch = inputs.read()) != -1) {

Page 288: Build Automation Using Wireless Sensor Network

buffer.append((char)ch);} } finally { if (inputs != null) inputs.close(); if (connect != null) connect.close();} String val = parse(buffer.toString()); System.out.println(val); return val; } /********* Start record value mote 1 to mote 14 **************/ private String parse(String str){ int L1 = str.indexOf("L_mote1:"); int T1 = str.indexOf("T_mote1:"); int R1 = str.indexOf("R_mote1:"); int W1_1 = str.indexOf("W1_mote1:"); int L2 = str.indexOf("L_mote2:"); int T2 = str.indexOf("T_mote2:"); int R2 = str.indexOf("R_mote2:"); int W1_2 = str.indexOf("W1_mote2:"); int L3 = str.indexOf("L_mote3:"); int T3 = str.indexOf("T_mote3:"); int R3 = str.indexOf("R_mote3:"); int W1_3 = str.indexOf("W1_mote3:"); int L4 = str.indexOf("L_mote4:"); int T4 = str.indexOf("T_mote4:"); int R4 = str.indexOf("R_mote4:"); int W1_4 = str.indexOf("W1_mote4:"); int L5 = str.indexOf("L_mote5:"); int T5 = str.indexOf("T_mote5:"); int R5 = str.indexOf("R_mote5:");

Page 289: Build Automation Using Wireless Sensor Network

int W1_5 = str.indexOf("W1_mote5:"); int L6 = str.indexOf("L_mote6:"); int T6 = str.indexOf("T_mote6:"); int R6 = str.indexOf("R_mote6:"); int W1_6 = str.indexOf("W1_mote6:"); int L7 = str.indexOf("L_mote7:"); int T7 = str.indexOf("T_mote7:"); int R7 = str.indexOf("R_mote7:"); int W1_7 = str.indexOf("W1_mote7:"); int L8 = str.indexOf("L_mote8:"); int T8 = str.indexOf("T_mote8:"); int R8 = str.indexOf("R_mote8:"); int W1_8 = str.indexOf("W1_mote8:"); int L9 = str.indexOf("L_mote9:"); int T9 = str.indexOf("T_mote9:"); int R9 = str.indexOf("R_mote9:"); int W1_9 = str.indexOf("W1_mote9:"); int L10 = str.indexOf("L_mote10:"); int T10 = str.indexOf("T_mote10:"); int R10 = str.indexOf("R_mote10:"); int W1_10 = str.indexOf("W1_mote10:"); int L11 = str.indexOf("L_mote11:"); int T11 = str.indexOf("T_mote11:"); int R11 = str.indexOf("R_mote11:"); int W1_11 = str.indexOf("W1_mote11:"); int L12 = str.indexOf("L_mote12:"); int T12 = str.indexOf("T_mote12:"); int R12 = str.indexOf("R_mote12:"); int W1_12 = str.indexOf("W1_mote12:");

Page 290: Build Automation Using Wireless Sensor Network

int L13 = str.indexOf("L_mote13:"); int T13 = str.indexOf("T_mote13:"); int R13 = str.indexOf("R_mote13:"); int W1_13 = str.indexOf("W1_mote13:"); int L14 = str.indexOf("L_mote14:"); int T14 = str.indexOf("T_mote14:"); int R14 = str.indexOf("R_mote14:"); int W1_14 = str.indexOf("W1_mote14:"); // value Light = b - a, value Temp = d – c, value Record Time = f – e, value Warning1 = h - g int a = 8; int b = 12; int p = 8; int q = 11; int c = 9; int d = 17; int e = 9; int f = 29; int g = 10; int h = 45; /**************************** Light **************************************/ if (L1 != -1){Light1 = str.substring(L1+p, L1+q);} if (L2 != -1){Light2 = str.substring(L2+p, L2+q);} if (L3 != -1){Light3 = str.substring(L3+p, L3+q);} if (L4 != -1){Light4 = str.substring(L4+p, L4+q);} if (L5 != -1){Light5 = str.substring(L5+p, L5+q);} if (L6 != -1){Light6 = str.substring(L6+p, L6+q);} if (L7 != -1){Light7 = str.substring(L7+p, L7+q);} if (L8 != -1){Light8 = str.substring(L8+p, L8+q);} if (L9 != -1){Light9 = str.substring(L9+p, L9+q);}

Page 291: Build Automation Using Wireless Sensor Network

if (L10 != -1){Light10 = str.substring(L10+a, L10+b);} if (L11 != -1){Light11 = str.substring(L11+a, L11+b);} if (L12 != -1){Light12 = str.substring(L12+a, L12+b);} if (L13 != -1){Light13 = str.substring(L13+a, L13+b);} if (L14 != -1){Light14 = str.substring(L14+a, L14+b);} /********************** Temp **************************/ if (T1 != -1){Temp1 = str.substring(T1+c, T1+d);} if (T2 != -1){Temp2 = str.substring(T2+c, T2+d);} if (T3 != -1){Temp3 = str.substring(T3+c, T3+d);} if (T4 != -1){Temp4 = str.substring(T4+c, T4+d);} if (T5 != -1){Temp5 = str.substring(T5+c, T5+d);} if (T6 != -1){Temp6 = str.substring(T6+c, T6+d);} if (T7 != -1){Temp7 = str.substring(T7+c, T7+d);} if (T8 != -1){Temp8 = str.substring(T8+c, T8+d);} if (T9 != -1){Temp9 = str.substring(T9+c, T9+d);} if (T10 != -1){Temp10 = str.substring(T10+c, T10+d);} if (T11 != -1){Temp11 = str.substring(T11+c, T11+d);} if (T12 != -1){Temp12 = str.substring(T12+c, T12+d);} if (T13 != -1){Temp13 = str.substring(T13+c, T13+d);} if (T14 != -1){Temp14 = str.substring(T14+c, T14+d);} /****************** Record Time *********************/ if (R1 != -1){RecT1 = str.substring(R1+e, R1+f);} if (R2 != -1){RecT2 = str.substring(R2+e, R2+f);} if (R3 != -1){RecT3 = str.substring(R3+e, R3+f);} if (R4 != -1){RecT4 = str.substring(R4+e, R4+f);} if (R5 != -1){RecT5 = str.substring(R5+e, R5+f);} if (R6 != -1){RecT6 = str.substring(R6+e, R6+f);} if (R7 != -1){RecT7 = str.substring(R7+e, R7+f);} if (R8 != -1){RecT8 = str.substring(R8+e, R8+f);} if (R9 != -1){RecT9 = str.substring(R9+e, R9+f);}

Page 292: Build Automation Using Wireless Sensor Network

if (R10 != -1){RecT10 = str.substring(R10+e, R10+f);} if (R11 != -1){RecT11 = str.substring(R11+e, R11+f);} if (R12 != -1){RecT12 = str.substring(R12+e, R12+f);} if (R13 != -1){RecT13 = str.substring(R13+e, R13+f);} if (R14 != -1){RecT14 = str.substring(R14+e, R14+f);} /************************* Warning1 ****************/ if (W1_1 != -1){Warn1_1 = str.substring(W1_1+g, W1_1+h);} if (W1_2 != -1){Warn1_2 = str.substring(W1_2+g, W1_2+h);} if (W1_3 != -1){Warn1_3 = str.substring(W1_3+g, W1_3+h);} if (W1_4 != -1){Warn1_4 = str.substring(W1_4+g, W1_4+h);} if (W1_5 != -1){Warn1_5 = str.substring(W1_5+g, W1_5+h);} if (W1_6 != -1){Warn1_6 = str.substring(W1_6+g, W1_6+h);} if (W1_7 != -1){Warn1_7 = str.substring(W1_7+g, W1_7+h);} if (W1_8 != -1){Warn1_8 = str.substring(W1_8+g, W1_8+h);} if (W1_9 != -1){Warn1_9 = str.substring(W1_9+g, W1_9+h);} if (W1_10 != -1){Warn1_10 = str.substring(W1_10+g, W1_10+h);} if (W1_11 != -1){Warn1_11 = str.substring(W1_11+g, W1_11+h);} if (W1_12 != -1){Warn1_12 = str.substring(W1_12+g, W1_12+h);} if (W1_13 != -1){Warn1_13 = str.substring(W1_13+g, W1_13+h);} if (W1_14 != -1){Warn1_14 = str.substring(W1_14+g, W1_14+h);} return ":: Mote 1 :: \n"+"At : Lab Communication\n"+"Light : " + Light1 + "\nTemp : " + Temp1 + " C\n"+"Time :"+RecT1+"\nWarning :\n "+Warn1_1+"\n"+ ":: Mote 2 :: \n"+"At : Lab Communication\n"+"Light : " + Light2 + "\nTemp : " + Temp2 + " C\n"+"Time :"+RecT2+"\nWarning :\n "+Warn1_2+"\n"+ ":: Mote 3 :: \n"+"At : Lab Communication\n"+"Light : " + Light3 + "\nTemp : " + Temp3 + " C\n"+"Time :"+RecT3+"\nWarning :\n "+Warn1_3+"\n"+

Page 293: Build Automation Using Wireless Sensor Network

":: Mote 4 :: \n"+"At : Lab Computer\n"+"Light : " + Light4 + "\nTemp : " + Temp4 + " C\n"+"Time :"+RecT4+"\nWarning :\n "+Warn1_4+"\n"+ ":: Mote 5 :: \n"+"At : Lab Computer\n"+"Light : " + Light5 + "\nTemp : " + Temp5 + " C\n"+"Time :"+RecT5+"\nWarning :\n "+Warn1_5+"\n"+ ":: Mote 6 :: \n"+"At : Lab Computer\n"+"Light : " + Light6 + "\nTemp : " + Temp6 + " C\n"+"Time :"+RecT6+"\nWarning :\n "+Warn1_6+"\n"+ ":: Mote 7 :: \n"+"At : Computer 2\n"+"Light : " + Light7 + "\nTemp : " + Temp7 + " C\n"+"Time :"+RecT7+"\nWarning :\n "+Warn1_7+"\n"+ ":: Mote 8 :: \n"+"At : Computer 2\n"+"Light : " + Light8 + "\nTemp : " + Temp8 + " C\n"+"Time :"+RecT8+"\nWarning :\n "+Warn1_8+"\n"+ ":: Mote 9 :: \n"+"At : Computer 1\n"+"Light : " + Light9 + "\nTemp : " + Temp9 + " C\n"+"Time :"+RecT9+"\nWarning :\n "+Warn1_9+"\n"+ ":: Mote 10 :: \n"+"At : Computer 1\n"+"Light : " + Light10 + "\nTemp : " + Temp10 + " C\n"+"Time :"+RecT10+"\nWarning :\n "+Warn1_10+"\n"+ ":: Mote 11 :: \n"+"At : Embeded\n"+"Light : " + Light11 + "\nTemp : " + Temp11 + " C\n"+"Time :"+RecT11+"\nWarning :\n "+Warn1_11+"\n"+ ":: Mote 12 :: \n"+"At : Embeded\n"+"Light : " + Light12 + "\nTemp : " + Temp12 + " C\n"+"Time :"+RecT12+"\nWarning :\n "+Warn1_12+"\n"+ ":: Mote 13 :: \n"+"At : Computer Project\n"+"Light : " + Light13 + "\nTemp : " + Temp13 + " C\n"+"Time :"+RecT13+"\nWarning :\n "+Warn1_13+"\n"+ ":: Mote 14 :: \n"+"At : Computer Project\n"+"Light : " + Light14 + "\nTemp : " + Temp14 + " C\n"+"Time :"+RecT14+"\nWarning :\n "+Warn1_14+"\n"; } }

Page 294: Build Automation Using Wireless Sensor Network

8. moteDisconnect.java import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; import java.lang.*; import java.util.*; public class moteDisconnect extends MIDlet implements CommandListener { private Command exitCommand; private Display display; private Form displayForm; public String Warn1_1 = ""; public String Warn1_2 = ""; public String Warn1_3 = ""; public String Warn1_4 = ""; public String Warn1_5 = ""; public String Warn1_6 = ""; public String Warn1_7 = ""; public String Warn1_8 = ""; public String Warn1_9 = ""; public String Warn1_10 = ""; public String Warn1_11 = ""; public String Warn1_12 = ""; public String Warn1_13 = ""; public String Warn1_14 = ""; public moteDisconnect(){ displayForm = new Form("Status of Mote"); try{

Page 295: Build Automation Using Wireless Sensor Network

String result = getViaHttpConnection("http://202.44.37.232/mote/AllMote.php"); displayForm.append(" " + result); } catch (Exception exc){ exc.printStackTrace(); } exitCommand = new Command("Exit", Command.SCREEN, 1); displayForm.addCommand(exitCommand); displayForm.setCommandListener(this); } public void startApp(){ display = Display.getDisplay(this); display.setCurrent(displayForm); } public void pauseApp(){ } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s){ if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } private String getViaHttpConnection(String url) throws IOException { HttpConnection connect = null; InputStream inputs= null; StringBuffer buffer = new StringBuffer(); try { connect = (HttpConnection)Connector.open(url); inputs = connect.openInputStream(); int ch;

Page 296: Build Automation Using Wireless Sensor Network

while ((ch = inputs.read()) != -1) { buffer.append((char)ch); } } finally { if (inputs != null) inputs.close(); if (connect != null) connect.close(); } String val = parse(buffer.toString()); System.out.println(val); return val; } /****************** Start record value mote 1 to mote 14 *********************/ private String parse(String str){ int W1_1 = str.indexOf("W1_mote1:"); int W1_2 = str.indexOf("W1_mote2:"); int W1_3 = str.indexOf("W1_mote3:"); int W1_4 = str.indexOf("W1_mote4:"); int W1_5 = str.indexOf("W1_mote5:"); int W1_6 = str.indexOf("W1_mote6:"); int W1_7 = str.indexOf("W1_mote7:"); int W1_8 = str.indexOf("W1_mote8:"); int W1_9 = str.indexOf("W1_mote9:"); int W1_10 = str.indexOf("W1_mote10:"); int W1_11 = str.indexOf("W1_mote11:"); int W1_12 = str.indexOf("W1_mote12:"); int W1_13 = str.indexOf("W1_mote13:"); int W1_14 = str.indexOf("W1_mote14:");

Page 297: Build Automation Using Wireless Sensor Network

// value Warning1 = h - g int g = 10; int h = 45; /******************** Warning1 **************************/ if (W1_1 != -1){Warn1_1 = str.substring(W1_1+g, W1_1+h);} if (W1_2 != -1){Warn1_2 = str.substring(W1_2+g, W1_2+h);} if (W1_3 != -1){Warn1_3 = str.substring(W1_3+g, W1_3+h);} if (W1_4 != -1){Warn1_4 = str.substring(W1_4+g, W1_4+h);} if (W1_5 != -1){Warn1_5 = str.substring(W1_5+g, W1_5+h);} if (W1_6 != -1){Warn1_6 = str.substring(W1_6+g, W1_6+h);} if (W1_7 != -1){Warn1_7 = str.substring(W1_7+g, W1_7+h);} if (W1_8 != -1){Warn1_8 = str.substring(W1_8+g, W1_8+h);} if (W1_9 != -1){Warn1_9 = str.substring(W1_9+g, W1_9+h);} if (W1_10 != -1){Warn1_10 = str.substring(W1_10+g, W1_10+h);} if (W1_11 != -1){Warn1_11 = str.substring(W1_11+g, W1_11+h);} if (W1_12 != -1){Warn1_12 = str.substring(W1_12+g, W1_12+h);} if (W1_13 != -1){Warn1_13 = str.substring(W1_13+g, W1_13+h);} if (W1_14 != -1){Warn1_14 = str.substring(W1_14+g, W1_14+h);} if(Warn1_1 != "" ){Warn1_1 = " Mote 1 \n";}else Warn1_1 = ""; if(Warn1_2 != "" ){Warn1_2 = " Mote 2 \n";}else Warn1_2 = ""; if(Warn1_3 != "" ){Warn1_3 = " Mote 3 \n";}else Warn1_3 = ""; if(Warn1_4 != "" ){Warn1_4 = " Mote 4 \n";}else Warn1_4 = ""; if(Warn1_5 != "" ){Warn1_5 = " Mote 5 \n";}else Warn1_5 = ""; if(Warn1_6 != "" ){Warn1_6 = " Mote 6 \n";}else Warn1_6 = ""; if(Warn1_7 != "" ){Warn1_7 = " Mote 7 \n";}else Warn1_7 = ""; if(Warn1_8 != "" ){Warn1_8 = " Mote 8 \n";}else Warn1_8 = ""; if(Warn1_9 != "" ){Warn1_9 = " Mote 9 \n";}else Warn1_9 = ""; if(Warn1_10 != "" ){Warn1_10 = " Mote 10 \n";}else Warn1_10 = ""; if(Warn1_11 != "" ){Warn1_11 = " Mote 11 \n";}else Warn1_11 = "";

Page 298: Build Automation Using Wireless Sensor Network

if(Warn1_12 != "" ){Warn1_12 = " Mote 12 \n";}else Warn1_12 = ""; if(Warn1_13 != "" ){Warn1_13 = " Mote 13 \n";}else Warn1_14 = ""; if(Warn1_14 != "" ){Warn1_14 = " Mote 14 \n";}else Warn1_14 = ""; return " :: Mote Disconnect ::\n"+ Warn1_1 + Warn1_2 + Warn1_3 + Warn1_4 + Warn1_5 + Warn1_6 + Warn1_7 + Warn1_8 + Warn1_9 + Warn1_10 + Warn1_11 + Warn1_12 + Warn1_13 +Warn1_14; }//End record value mote 1 to mote 14 }

Page 299: Build Automation Using Wireless Sensor Network

9. WSNMAP.java import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class WSNMAP extends MIDlet implements CommandListener { private Display mainDisplay; private DrawWSNMAP mainDrawWSNMAP; private Command exitCommand; public WSNMAP() { exitCommand = new Command( "Exit", Command.SCREEN, 0); } public void startApp() { mainDisplay = Display.getDisplay( this); mainDrawWSNMAP = new DrawWSNMAP(); mainDrawWSNMAP.addCommand( exitCommand); mainDrawWSNMAP.setCommandListener( this); mainDisplay.setCurrent( mainDrawWSNMAP); } public void pauseApp() {} public void destroyApp( boolean unconditional) {} public void commandAction( Command c, Displayable d) { destroyApp( false); notifyDestroyed(); } } class DrawWSNMAP extends Canvas { int x, y, dx, pix, s, w, h; private Image[] imageData = new Image[7];

Page 300: Build Automation Using Wireless Sensor Network

public DrawWSNMAP() { x = 0; y = 0; dx = 0; pix = 0; s = 32; w = getWidth(); h = getHeight(); try { imageData[ 0] = Image.createImage( "/f3.gif"); imageData[ 1] = Image.createImage( "/LabCommu.gif"); imageData[ 2] = Image.createImage( "/LabComputer.gif"); imageData[ 3] = Image.createImage( "/Computer2.gif"); imageData[ 4] = Image.createImage( "/Computer1.gif"); imageData[ 5] = Image.createImage( "/Embeded.gif"); imageData[ 6] = Image.createImage( "/ComProject.gif"); } catch ( java.io.IOException e) {} } public void paint( Graphics g) { g.setColor( 255, 255, 255); g.fillRect( 0, 0, w, h); g.drawImage( imageData[dx], x, y, 0); } public void keyPressed( int keyCode) { int button = getGameAction( keyCode); switch ( keyCode) { case KEY_NUM0 : dx = 0; x = (x <= 0) ? 0 : x - 1; break; // left case KEY_NUM1 : dx = 1; x = (x >= w - s) ? w - s : x + 1; break; // right case KEY_NUM2 : dx = 2;

Page 301: Build Automation Using Wireless Sensor Network

y = (y <= 0) ? 0 : y - 1; break; // up case KEY_NUM3 : dx = 3; y = (y >= h - s) ? h - s : y + 1; break; // down case KEY_NUM4 : dx = 4; y = (y >= h - s) ? h - s : y + 1; break; // down case KEY_NUM5 : dx = 5; y = (y >= h - s) ? h - s : y + 1; break; // down case KEY_NUM6 : dx = 6; y = (y >= h - s) ? h - s : y + 1; break; // down } repaint(); } }

Page 302: Build Automation Using Wireless Sensor Network

10. gui.java import java.io.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class gui extends MIDlet implements CommandListener { Display display; List menu; List choose; TextBox input; TextBox status; // ticker Ticker ticker = new Ticker(" WSN Monitoring "); // form Form form = new Form("Status of Tmote"); // text field TextField textfield01 = new TextField("", " Set Tmote in building 84 floor 3 ", 100, 0); TextField textfield02 = new TextField("", ":: Lab Communication ::\n Mote : 1, 2 and 3 ", 100, 0); TextField textfield03 = new TextField("", ":: Lab Computer ::\n Mote : 4, 5 and 6 ", 100, 0); TextField textfield04 = new TextField("", ":: Computer 2 ::\n Mote : 7 and 8 ", 100, 0); TextField textfield05 = new TextField("", ":: Computer 1 ::\n Mote : 9 and 10 ", 100, 0); TextField textfield06 = new TextField("", ":: Embeded ::\n Mote : 11 and 12 ", 100, 0); TextField textfield07 = new TextField("", ":: Computer Project ::\n Mote : 13 and 14 ", 100, 0); // command static final Command backCommand = new Command("Back", Command.BACK, 0);

Page 303: Build Automation Using Wireless Sensor Network

static final Command mainMenuCommand = new Command("Main", Command.SCREEN, 1); static final Command exitCommand = new Command("Exit", Command.STOP, 2); String currentMenu; // constructor. public gui() {} public void startApp() throws MIDletStateChangeException {} {display = Display.getDisplay(this); menu = new List( "Components of services", Choice.IMPLICIT); menu.append("Mote Status", null); menu.append("Credit", null); menu.addCommand(exitCommand); menu.setCommandListener(this); menu.setTicker(ticker); mainMenu(); // form form.append(textfield01); form.append(textfield02); form.append(textfield03); form.append(textfield04); form.append(textfield05); form.append(textfield06); form.append(textfield07); } public void pauseApp() { display = null; choose = null; menu = null;

Page 304: Build Automation Using Wireless Sensor Network

ticker = null; form = null; input = null; status = null; textfield01 = null; textfield02 = null; textfield03 = null; textfield04 = null; textfield05 = null; textfield06 = null; textfield07 = null; } public void destroyApp(boolean unconditional) { notifyDestroyed();} // main menu void mainMenu() { display.setCurrent(menu); currentMenu = "Main";} public void Mote() { form.setTicker(new Ticker(" WSN Monitoring ")); form.addCommand(backCommand); form.setCommandListener(this); display.setCurrent(form); currentMenu = "form"; } public void Credit() { input = new TextBox ("Credit", "", 100, TextField.ANY); input.setTicker(new Ticker(" WSN Monitoring ")); input.addCommand(backCommand); input.setCommandListener(this);

Page 305: Build Automation Using Wireless Sensor Network

input.setString(":: By Project :: \n Building Automation System Using Wireless Sensor Network \n"); display.setCurrent(input); currentMenu = "input"; } public void commandAction(Command c,Displayable d) { String label = c.getLabel(); if (label.equals("Exit")) { destroyApp(true); } else if (label.equals("Back")) { if(currentMenu.equals("list")|| currentMenu.equals("input") ||currentMenu.equals("date")|| currentMenu.equals("form")) { // go back to menu mainMenu();} } else { List down = (List)display.getCurrent(); switch(down.getSelectedIndex()) { case 0: Mote() ;break; case 1: Credit() ;break; } } } }

Page 306: Build Automation Using Wireless Sensor Network

ประวตผแตง

ปรญญานพนธเรอง : ระบบอาคารอจฉรยะโดยใชเครอขายเซนเซอรไรสาย สาขาวชา : วศวกรรมไฟฟา ภาควชา : วศวกรรมไฟฟา คณะ : วศวกรรมศาสตร ชอ : นายเอกชย ยอดตาคา ประวต เกดเมอวนท 1 เมษายน 2528 ทอาเภอรองกวาง จงหวดแพร สาเรจการศกษาระดบมธยมศกษาตอนตนจากโรงเรยนบานวงปง และไดเขาศกษาตอระดบปรญญาวชาชพท วทยาลย เทคนค แพร จงหวดแพร ในสาขาวชาชางอเลกทรอนกส จากนนไดเขามาศกษาตอในระดบปรญญาตรทภาควชาวศวกรรมไฟฟา คณะวศวกรรมศาสตร มหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ ปจจบนอาศยอยบานเลขท 74/2 หม 4 ตาบลไผโทน อาเภอรองกวาง จงหวดแพร 54140 e-mail: [email protected] ชอ : นางสาวกญญณฐ มนตประเสรฐ ประวต สาเรจการศกษาระดบประกาศนยบตรวชาชพจากมหาลยวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ (เทคนคไทย - เยอรมน) ในสาขาไฟฟาและอเลกทรอนกส และไดเขารบการศกษาตอในระดบปรญญาตรทภาควชาวศวกรรมไฟฟา คณะวศวกรรมศาสตร มหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ ปจจบนอาศยอยบานเลขท 100/356 ถนนลาดปลาเคา 63 แขวงอนสาวรย เขตบางเขน กรงเทพฯ e-mail: [email protected]

Page 307: Build Automation Using Wireless Sensor Network

112

ประวตผแตง (ตอ) ชอ : นางสาวชรนรตน วงศธนะรกษ ประวต เกดเมอวนท 18 พฤศจกายน 2529 จงหวดกรงเทพฯ สาเรจการศกษาระดบมธยมศกษาจากโรงเรยนวดเขมาภรตาราม และไดเขามาศกษาตอในระดบปรญญาตรทภาควชาวศวกรรมไฟฟา คณะวศวกรรมศาสตร มหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ ปจจบนอาศยอยบานเลขท 79/4 หม 4 ตาบลสวนใหญ อาเภอเมอง จงหวดนนทบร 11000 e-mail: [email protected] ชอ : นายสถาพร สงาศร ประวต เกดเมอวนท 28 กนยายน 2527 จงหวดลพบร สาเรจการศกษาระดบมธยมศกษาตอนตนจากโรงเรยนอยธยาวทยาลย และไดเขาศกษาตอระดบปรญญาวชาชพทมหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ ในสาขาวชาชางไฟฟาและอเลกทรอนกส จากนนไดเขามาศกษาตอในระดบปรญญาตรทภาควชาวศวกรรมไฟฟา คณะวศวกรรมศาสตร มหาวทยาลยเทคโนโลยพระจอมเกลาพระนครเหนอ ปจจบนอาศยอยบานเลขท 330/52 ซอยวงศสวาง 11 แขวงบางซอ เขตบางซอ กรงเทพฯ 10800 e-mail: [email protected]