Vous êtes sur la page 1sur 57

ZIGBEE BASED WEB ENABLED POWER MONITOR

Saurabh Ahuja B.Tech., Uttar Pradesh Technical University, India, 2007

PROJECT

Submitted in partial satisfaction of the requirements for the degree of

MASTER OF SCIENCE

in

ELECTRICAL AND ELECTRONIC ENGINEERING at CALIFORNIA STATE UNIVERSITY, SACRAMENTO

FALL 2010

ZIGBEE BASED WEB ENABLED POWER MONITOR

A Project

by

Saurabh Ahuja

Approved by: _______________________________________, Committee Chair Jing Pang, Ph. D. ________________________________________, Second Reader Preetham Kumar, Ph. D. __________________________ Date

ii

Student: Saurabh Ahuja

I certify that this student has met the requirements for the format contained in the University format manual, and that this project is suitable for shelving in the Library and credits is to be awarded for the Project.

_________________________, Graduate Coordinator Preetham Kumar, Ph. D.

_____________________ Date

Department of Electrical and Electronic Engineering

iii

Abstract of ZIGBEE BASED WEB ENABLED POWER MONITOR by Saurabh Ahuja

In this high-tech world, there are hundreds of mechanical machines and electronic products being introduced in market, on weekly basis, to increase the comfort level of human beings. However, to operate on these devices, more power is required. More power generation means more energy requirement and so energy resources. However, today world is facing critical energy resource shortage and "Green House Effect" problems. There are bunch of research projects going on to reduce the total power consumption and at the same time maximize energy/power efficiency. So this project is done as an effort to address the above issue- maximizing the power efficiency and minimizing the power usage. Aim of this project is to control and monitor the power usage of the devices with the help of low-cost, low-power technology known as Zigbee Technology.This project also focuses on developing a Graphical User Interface through which one can control and monitor the power usage of different devices. The graphical user interface give commands to embedded board using Zigbee wireless technology, which in turn controls the switching ON or OFF of different devices. iv

Overall project can be divided into two modules Power Measurement Embedded module and Home server Module. Power Measurement Embedded Module contains power measurement circuit, Microprocessor Control Unit and Zigbee Transceiver. On the other hand, Home Server Module contains Zigbee Transceiver and module through which one can send commands. This project focuses on the Home Server module in which one can send commands to control the devices as well monitor the power consumed by the devices. This project also includes a webpage development through which one can monitor and compare the power consumed by the devices in a tabular form as well as in a chart. This user-friendly representation of the data allows user to understand the power consumption by the devices easily and effectively.

____________________, Committee Chair Jing Pang, Ph. D. _______________________ Date

ACKNOWLEDGMENTS

Here, I would like to take the opportunity to express my gratitude towards all the people who have been involved in successful completion of this project. Without whom this project would have never reached the epic where it is right now. With sincere respect, I would like to thank my project advisor and first reader Dr. Jing Pang for her valuable time, efforts, guidance and moral support. Her continuous guidance and support led this project to a successful completion. By providing an opportunity to work on this project, she helped to gain profound knowledge of wireless transmission fundamentals and ASP.net framework. I sincerely thank Dr. Preetham Kumar for providing me important suggestions to perk up this project. His support during the final phase of my project was very influential. Finally, I would like to thank my peers, my friends and my family for providing me constant inspiration and support during the different phases of the project.

Saurabh Ahuja

vi

TABLE OF CONTENTS Page Acknowledgements .................................................................................................................. vi List of Figures .......................................................................................................................... ix Chapter 1. INTRODUCTION ............................................................................................................... 1 1.1 Overview ................................................................................................................ 1 1.2 Objective of the Project ........................................................................................ 2 2. FUNDAMENTALS OF ZIGBEE TECHNOLOGY .......................................................... 4 2.1 Introduction............................................................................................................ 4 2.2 Types of Zigbee Devices ....................................................................................... 5 2.2.1 Zigbee Coordinator ................................................................................ 5 2.2.2 Full Function Device ............................................................................. 5 2.2.3 Reduced Function Device ...................................................................... 6 2.3 Zigbee Network ..................................................................................................... 7 2.3.1 Network Setup ....................................................................................... 7 2.3.2 Mechanism for Data Transfer ................................................................ 8 2.3.3 Zigbee Network Topology ..................................................................... 8 2.4 Zigbee Devices Communication Flow Chart ....................................................... 10 3. PROJECT RESOURCES.................................................................................................. 12 3.1 Overview .............................................................................................................. 12 3.2 Hardware Resources ............................................................................................ 13 3.2.1 Wireless Device ................................................................................... 13 3.2.2 RS232 Device ...................................................................................... 14

vii

3.2.3 Communication between RS232 and Zigbee Device .......................... 17 3.3 Software Resources.............................................................................................. 18 3.3.1 Microsoft ASP.net ............................................................................... 18 3.3.2 Microsoft Access ................................................................................. 19 4. PROJECT DETAILS ........................................................................................................ 21 4.1 Windows Based Graphical User Interface ........................................................... 21 4.1.1 Control of the Devices ......................................................................... 23 4.1.2 Power Usage of the Devices ................................................................ 26 4.2 Web Enabled Power Monitoring ......................................................................... 28 4.2.1 Data in Tabular Form ........................................................................... 28 4.2.2 Data in Chart ........................................................................................ 29 5. SIMULATION AND RESULTS ....................................................................................... 30 5.1 Graphical User Interface ...................................................................................... 30 5.2 Website ............................................................................................................... 33 6. CONCLUSION AND FUTURE EXPANSION ................................................................ 35 6.1 Conclusion ................................................................................................................ 35 6.2 Future Expansion ..................................................................................................... 36 Appendix A. Graphical User Interface .................................................................................. 37 Appendix B. Chart Feature .................................................................................................... 41 Appendix C. Main Page ......................................................................................................... 43 Appendix D. Database Feature .............................................................................................. 44 References ............................................................................................................................... 46

viii

LIST OF FIGURES Page 1. Figure 2.1 Zigbee Coordinator ........................................................................................ 5 2. Figure 2.2 Full Function Device...................................................................................... 6 3. Figure 2.3 Reduced Function Device ............................................................................. 6 4. Figure 2.4 Star Topology ................................................................................................. 8 5. Figure 2.5 Mesh Topology ............................................................................................... 9 6. Figure 2.6 Cluster Tree Topology ................................................................................... 9 7. Figure 2.7 Flow Chart Showing Working of Zigbee Coordinator ............................ 10 8. Figure 2.8 Flow Chart Showing Working of Zigbee Device .................................... 11 9. Figure 3.1 Packet Format ............................................................................................... 13 10. Figure 3.2 Example Showing Voltage Levels for Serial Communication ............ 15 11. Figure 3.3 Serial Port Pin Layout ................................................................................ 16 12. Figure 4.1 Serial Port Configurations ......................................................................... 22 13. Figure 4.2 Overview of the Communication between GUI and Microprocessor . 23 14. Figure 4.3 GUI Button Configurations....................................................................... 24 15. Figure 4.4 GUI Attributes Property Name ................................................................. 25 16. Figure 4.5 Pointers to Extended Database Classes ................................................... 27 17. Figure 4.6 Table Showing the Structure of the Database ........................................ 28 18. Figure 4.7: Setting of Chart Attributes ....................................................................... 29 19. Figure 5.1: GUI with One Device ON........................................................................ 30 20. Figure 5.2: Hardware Kit Showing Device 1 ON ..................................................... 31

ix

21. Figure 5.3: GUI with All Devices ON........................................................................ 32 22. Figure 5.4: Hardware Kit with All Devices ON........................................................ 32 23. Figure 5.5 Data Viewed on the Website .................................................................... 33 24. Figure 5.5 Data Shown in Chart Form ....................................................................... 34

1
Chapter 1 INTRODUCTION

In 21st Century, with the advent of new technologies almost every day, the living standards and comfort level of people has reached a very high level. A large part of the modern lifestyle is usage of electronic and electrical devices. However, increased electronic and electrical appliances usage has exponentially increased the power consumption. Due to the demand-supply gap, the price that the end user has to pay is increasing day by day. As a result, there is an unmet need of new technologies so that the power usage can be optimized. This unmet need has resulted in fundamental and applied research in this field. Such research has led to some advanced monitoring and control features so people are able to control the power consumption as well as monitor the system so that they can see how much power the devices consume and how they can optimize them to get better performance. 1.1 Overview Today various wireless technologies are used with the help of which one can monitor as well as control the power consumption of the devices. Usually modules developed with the help of these wireless technologies, collects the data of total power consumed at regular intervals and send them via transmitting device. At the receiver end, the data is collected and processed for monitoring purposes. The device, which uses this technology, is called as Smart Meter. There are various wireless technologies available in the market that fulfils similar needs, and each of them has its own pros and cons. The

2 oldest one is Infrared technology, whose power consumption in transferring the collected data is low but the number of units that can be controlled or monitored by this technology is only 1. The transfer rate for data is also very low i.e. 38 Kbps [1]. Another wireless technology, which can fulfill the requirements of transferring the data, is Bluetooth Technology. The power consumption of this technology for tr ansferring the data is on the higher side but it can control 7 devices at a time. Moreover, the data transfer rate is as high as 1 Mbps [1]. However, a new technology known as Zigbee Technology is superior to both technologies mentioned above. Zigbee is a low cost, low power, wireless mesh networking standard. Zigbee can control 254 devices at a time and has the data transfer rate of 250kbps. Because of Zigbees low cost, low power consumption and ability to connect large number of devices, it could be considered the best option to be used in wireless control and monitoring applications. Zigbee is also complaint with IEEE 802.15.4-2003 standard, which also allows this technology to be used worldwide [1]. 1.2 Objective of the Project The main objective of this project was to develop a Zigbee based Web-Enabled power monitor. The specific objectives of the overall project could be described as: Power measurement Sending data from power measurement device to microprocessor Sending data from microprocessor to Zigbee transceiver and then wirelessly to

other Zigbee transceiver

3 Develop a Graphical User Interface, which controls as well as monitors the data

received by the Zigbee transceiver serially. In addition, stores the data in SQL database so that it can be accessed later on for references. This report describes the software aspects of the project, i.e. developing a graphical user interface which can control the devices remotely and monitor the received data. A website, which shows the chart for the collected information as well as collected data in tabular form, was also developed. Visual Studio 2010 and SQL server were used for development of the user interface.

4
Chapter 2

FUNDAMENTALS OF ZIGBEE TECHNOLOGY

2.1

Introduction In 21st century, wireless sensor networks are becoming necessary and seen as

indispensible in various medical and telecommunication equipments, smart energy resources, home automation products etc., which require monitoring and control. Zigbee is a wireless technology, which communicates on the principle of IEEE 802.15.4 standard. IEEE 802.15.4 is a standard that states the details for the lower layers of the communication. This standard focuses on the low-cost and low power communication. Because of Zigbees low cost, low power consumption and ability to connect in a mesh network, it is becoming more optimum solution for monitoring and control applications. Ability to connect in mesh network allows Zigbee to provide more range compared to other wireless technologies such as INFRARED, BLUETOOTH etc. In addition, it also provides high reliability of the data reproduced at receiver. It also consumes less power in communicating data between its transmitter and receiver, which means longer life with smaller batteries. The primary reason for low power consumption in Zigbee devices is that they work on very small duty cycle that helps them to have a longer life span. Variation in duty cycle depends upon the application usage, for example, some applications need data more frequently like in health centers compared to others such as home automation systems.

5 2.2 2.2.1 Types of Zigbee Devices Zigbee Coordinator This acts as the building block of the Zigbee communication. Zigbee coordinator forms the root of the various topologies like mesh, star, tree topology network etc. and communicates from one device to other. There is only one Zigbee coordinator in the whole Zigbee environment [2].

Zigbee Devices

Zigbee Coordinator

Figure 2.1: Zigbee coordinator 2.2.2 Full Function Device Full function devices support all IEEE 802.15.4 functions and features that are defined by the standard. They can also function as a Zigbee coordinator. More memory and computing power availability helps them to work as router also, which helps in transmitting data to longer distances through different networks [2].

Full Function Devices

Figure 2.2: Full function device 2.2.3 Reduced Function Device Reduced function devices just talk to the Zigbee coordinators or Full function devices. They cannot perform the functions of a router or coordinator [2].

Reduced Function Devices

Figure 2.3: Reduced function device

7 2.3 2.3.1 Zigbee Network Network Setup The Zigbee coordinator does Zigbee network initialization. As soon as the network is powered up, the coordinator starts the network initialization sequence. After that, the coordinator starts a search for the full function devices and reduced function devices to establish a network. Joining Network as a New Device Whenever a new device either Full Function Device (FFD) or Reduced Function Device (RFD) wants to join a network, it sends a request to all other parent capability devices such as FFDs that it wants to join the network. Then all the parent devices send a packet, which gives the information about their address and number of devices already connected to it. The child device that can be either FFD or RFD collects all the data and then selects one of the devices as a parent device, which is best suited for it. Then that parent device is responsible to provide the child device a unique ID [3]. Joining Previous Network Zigbee devices save the information in a table whenever they are connected to a network. This table stores the information, which helps the device to reconnect to the same network again. So next time whenever they are switched on, they first look into that table about the previous information and try to connect to the old network. If the table is blank then they try to connect into a network as a new device.

8 2.3.2 Mechanism for Data Transfer Whenever a device wants to send a data packet, it has to check for channel. If the channel is idle, device can send a packet else it has to wait. If the receiver is FFD then transmitters can send the packet any time because its transceiver always remains ON. However if the receiver is RFD then there are chances that its transceiver is OFF to save power. So to avoid data loss all RFDs send a packet to their corresponding parent device as soon as there transceiver comes to ON position to get the data packet which was send to them when they were in sleeping mode [3]. 2.3.3 Zigbee Network Topology

Zigbee network topology can be divided into three types [3]: Star Topology Star topology consists of one Zigbee coordinator and one or more RFDs or FFDs. All end point devices directly communicate to coordinator. If the end point devices want to talk to each other they have to send the information to coordinator first and then coordinator sends that information to appropriate receiver.

Zigbee Coordinator Full Function Device Reduced Function Device

Figure 2.4: Star topology

9 Mesh Topology Mesh topology also consists of one Zigbee coordinator and one or more RFDs or FFDs, but in this topology, FFDs can directly contact other FFDs to communicate the data packet.

Zigbee Coordinator Full Function Device Reduced Function Device

Figure 2.5: Mesh topology Cluster Tree Topology This type of topology is used when range from transmitter to receiver is large and Zigbee coordinator has to join two or more networks.

Zigbee Coordinator Full Function Device Reduced Function Device

Figure 2.6: Cluster tree topology

10 2.4 Zigbee Device Communication Flow Chart

Initialize the Device Setup a New Network

Waiting for the RFD/FFD to join

RFD/FF D Join?
NO
YES

Receive the RFD/FFD Data

Figure 2.7: Flow Chart showing working of Zigbee coordinator

11

Initialize the Device

Send Signal to join network

Join Network YES Waiting for the data from/to sensor/device

NO

Send/Receive data to/from Coordinator

YES
Suucessfully Transferred

NO

Figure 2.8 Flow Chart showing working of Zigbee device

12
Chapter 3

PROJECT RESOURCES

3.1

Overview To start with, the Graphical User Interface receives the total power consumption

in terms of units, through a Reduced Function Device as described in chapter 2. The Reduced Function Device is connected to RS232 serial communication device, which inturn is connected to the serial port of the laptop. Data received by the laptop is processed by the Graphical User Interface that is developed in Visual Studio and is stored in the Microsoft Access server for future references. A local website is also developed in visual studio, which processes that collected data and shows a chart of the collected information. It also tracks information of the time at which a particular data is received and the number of units at that particular time. To conclude, this project primarily includes two types of resources: Hardware resources which include RF module, also called as Zigbee module and

RS232 device that is used for the serial communication between Zigbee device and the computer serial port. Software Resources includes Visual studio in which Visual Basic coding is done

and Microsoft Access that is used for data handling.

13 3.2 Hardware Resources

This project includes two types of hardware devices. 3.2.1 Wireless Device Wireless devices used for transferring data are Zigbee Transceivers. Zigbee Transceivers work on the principle of low cost, low power consumption and high reliability communication. Ability to connect in mesh networks helps Zigbee devices to become highly reliable devices. Reason behind low power consumption in Zigbee devices is their ability to work in very small duty cycles. Packet Format

Preamble Bits (1010.1010)

Sync Word

DATA FIELD

CRC

Figure 3.1: Packet format Zigbee devices communicate with each other in a particular packet format. Packet consists of Preamble bits, Sync Word and CRC, which are inserted by the Zigbee transmitter and then at the receiver end removed by the Receiver. Zigbee packet also consists of data, which is then forwarded to the RS232 device by the receiver. When a particular amount of preamble bits are sent, which are combination of ones and zeros, Zigbee transmitter sends a sync word that is unique to the receiver. CRC (cyclic redundancy check) is generated by the transmitter for error purposes [4].

14 Packet Handling in Transmit Mode Whenever a Zigbee device needs to send a packet, it starts transmitting certain amount of preamble bits. Until that time, the data that is required to be transferred is stored in the transmitters First in First out FIFO register. After preamble bits are transferred, transmitter starts sending sync word that is combination of the unique address of the receiver and payload length. After that, Zigbee transmitter calculates the CRC on that data payload and sends to the receiver [4]. Packet Handling in Receiver Mode In receive mode, Zigbee receiver constantly searches for preamble bits. If receiver starts getting preamble bits, it will search for unique address, which is only valid for one particular receiver. If the unique address matches, the receiver will take that data payload and forward them to the appropriate source like RS232 device [4]. 3.2.2 RS232 Device Electronic data communication usually falls in 2 criteria, single ended and differential. In single ended signals, voltage level of the data bits is compared against the ground level. While in differential type, two types of voltage signals are used to decode or encode one bit of serial data, one is at positive level and the other is at the negative level. Using the differential type communication gives the advantage of noise cancellation, but this is only helpful when the wires are very close by and the level of voltage is high. So in this project, serial ended data communication is used.

15 Signal Levels To distinguish between 0 and 1 bit, RS232 has different voltage levels for them. If 0 needs to be transferred then voltage should be above +3V and below +12V. If 1 needs to be transferred then voltage level should be below -3V and above -12V. The intermediate +3V to -3V allow RS232 single ended communication to reject noise signals, which are generated by the nearby environment [5].

Figure 3.2: Example showing voltage levels for serial communication Pin Configuration RS232 has two types of connection, one that has 15 pins also called DB15 connector and other has 9 pins which is called DB9 connector. In this project, DB9 pin connector configuration is used to get data from the Zigbee device.

16

Figure 3.3: Serial port pin layout Pin 1: Data Career Detect Pin 2: Received Data Pin 3: Transmitted Data Pin 4: Data Terminal Ready Pin 5: Signal Ground Pin 6: Data Set Ready Pin 7: Request to Send Pin 8: Clear to Send Pin 9: Ring Indicator Among all these pins, the most important pins are Pin 2, Pin 3 and Pin 5, which are used for Received Data, Transmitted Data and Ground signal respectively. In this project, only these three pins are used to connect RS232 DB9 serial communication

17 device to serial port of the laptop. Data is sent to the Zigbee module through Tx pin and received at Rx pin [5]. Data Handling RS232 device communicates in an asynchronous manner that means signals are not fetched as a reference to a clock. Whenever it needs to transmit data, it just needs to match up with the minimum levels of the voltages so that 0 and 1 could be detected. If the voltage level is between +3V and -3V, channel is considered as Idle. As described above, if it is more than +3V and less than +12V it is considered as 0 or if it is less than -3V and more than -12V it is considered as 1. 3.2.3 Communication between RS232 and Zigbee Device As described previously, Zigbee transmitter makes the packet for the Zigbee receiver, which contains preamble bits, sync word, data field and CRC. Zigbee receiver takes that packet which it is getting serially and separates the data from that packet. Zigbee is connected to the RS232 device through wires. Zigbee devices Tx pin is connected to RS232 devices Rx pin and vice versa. So whenever Zigbee starts receiving data, it starts sending data to RS232 device. As there in no synchronous signal, one has to define particular number of bits that the RS232 device would be receiving per sec before we can start the system. This is also called bit rate, which can be defined as maximum number of bits that can be transferred in a second. Another parameter that should be configured before starting data reception is baud rate, which is defined as the maximum number state change allowed (0 to 1 or 1 to 0) in a second. Default baud rate for RS232 device and Zigbee module is 9600 and bit rate is 8 [3].

18 3.3 Software Resources As the title of the project-Zigbee Based Web-Enabled Power Monitor reveals, the focus of this project is to monitor power consumption through wireless technology called Zigbee. The project also includes web page creation, which represents data in userfriendly manner. Therefore, to fulfill all these requirements, the preferred software applications are Microsoft ASP.net and Microsoft Access Database. Microsoft ASP .net framework is used to develop Graphical User Interface and web page, while Microsoft Access Database is used for data collection. 3.3.1 Microsoft ASP .net Microsoft ASP.net is a framework on which millions of people work on, in todays world to develop applications. Microsoft ASP .net framework is useful for both windows type applications and web-based applications. It provides many class libraries, multiple languages to code e.g. Visual Basic, C#, Visual C++ etc and common platform to run. This project uses Visual Basic to develop the Graphical User interface and Web page. Why ASP.net ASP.net provides the easiest and fastest way of coding for windows applications as well as web based applications. ASP.net also provides Object Oriented Programming environment. With Visual Basic one can easily make use of new features of ASP.net framework such as powerful new forms, automatic control ordering and placement. Forms drag and drop feature also allows designer to put necessary functionalities on the windows application without writing the code for it. ASP.net also does automatic

19 alignment of the code that keeps the code clean and helps designers while debugging errors. It also needs less lines of code compared to other frameworks for the same amount of work, which helps ASP.net framework to run faster. Another advantage of using ASP.net framework is its ability to connect to the database server, which helps in storing and retrieving the data at later time simultaneously [6]. Language Used ASP.net framework gives designers lots of different options to code, for example, Visual Basic, C sharp and Visual C++ etc. There are many text based languages, which does not allow user to interact properly with graphics, but Visual Basic is graphic based language, which allows user to work directly with graphics. In this project, Visual Basic language is used to develop a graphical user interface and web application, which exploits the advantages of ASP.net very efficiently. Visual Basic has variety of data types and it can take values from different inputs such as serial port of a laptop or computer. With the use of Visual basic, one can create professional and powerful looking applications within less time and with less coding efforts. To end, Visual Basic is a complete package that allows user to develop user interfaces, very easily and quickly with many functions and less code. 3.3.2 Microsoft Access Microsoft access is used as a database. Data can be stored and again retrieved through different commands using ASP.net framework and Visual Basic language. This property of data storage and retrieving allows developers to interconnect different applications around web services and across any platform or device. Separating data from

20 main application allows data security. User can give different permissions to different users for same database for example one could have permissions only to VIEW and other might have permissions to VIEW as well as permissions to WRITE.

21
Chapter 4

PROJECT DETAILS

This project allows user to control the devices and monitor the power consumed by the controlled devices. With the help of a Graphical User Interface, one can control the devices, for instance when and which device to switch ON and switch OFF. In addition, with the help of an online webpage, one can monitor the overall usage of the devices. Therefore, this project is divided into two parts: 4.1 Windows based Graphical User Interface Web based power monitoring Windows Based Graphical User Interface This project is developed using the advanced and easy to configure features of Visual Studio 2010. Graphical User Interface and hardware kit communicates to each other with the help of serial port. As explained in chapter 3 RS232 device is connected to the serial port, which allows two way communication of Zigbee Reduced Function device with Graphical User Interface and vice versa. However, before any communication starts, GUI and serial port needs to be configured, so that they can communicate properly. Basic properties for serial port to communicate are [7]: Baud Rate: Maximum number state change allowed (0 to 1 or 1 to 0) in a second. Parity: To allow parity check or not. Data Bits: Maximum number of bits that can be transferred in a second.

22 Stop Bits: Is used to show the end of the character. Usually one bit is used to

show the end of a data stream. Handshake: Is necessary or not. To implement this functionality one need to enter commands to configure the properties of serial port. Figure 4.1 shows how the properties of serial port are configured in GUI.

Figure 4.1: Serial port configurations First one needs to check if the serial port is open or close. This can be done by checking the value of serialport.IsOpen function. If it is open then it needs to be closed before one can communicate to avoid sending inappropriate signals. To close the serial port one has to write serialport.close (). Serial port needs to be opened again before any

23 communication is initialized. However, this time serial port is opened with essential settings required to communicate. After configuring the communication channel, one can send commands to control devices and receive data bits, to and from the communication channel. 4.1.1 Control of the Devices To implement the functionality of controlling the devices, GUI sends a set of numbers to RS232 device, which in turn forwards those bits to Zigbee devices. At that time, Zigbee transceiver acts as transmitter and sends those bits to its counterpart, which is connected to the microprocessor. Microprocessor takes those bits, process them and then decides what to do, either switch ON or switch OFF the respective relays, which in turn controls the switching ON or OFF of the devices [8].

Power Usage Figure 4.2: Overview of the communication between GUI and Microprocessor

24 Each button on Graphical User Interface has different functionality. These functionalities can be set as shown in the following figure.

Figure 4.3: GUI button configurations If someone wants to switch ON the device1, then he has to click on the box whose property name is BUTTON 4, which in turn sends 1 to RS232 device. GUI uses serialport.write (Value need to be transferred) function to send the value to the serial port. RS232 device receives data and sends that data to Zigbee Device. Zigbee Reduced Function Device forms a packet with appropriate properties and sends 1 as data bits. On the other side Zigbee transceiver decodes that packet, takes that data, and gives it to microprocessor. As soon as microprocessor processes the received data, it transmits signal to relay 1, which in turn switch ON the device 1. To turn off the device 1, user needs to press button whose property name is BUTTON 1. When BUTTON 1 is pressed

25 GUI sends 2 to microprocessor via the same method describe above and microprocessor switches OFF the device 1. Same thing goes with the control of other devices, just the differences are that they have different buttons for their control and they send different bits to microprocessor for different function. Following figure 4.4 shows the property name of the boxes and textbox used in the project, through which, one can access the buttons and send the commands to the devices.

Figure 4.4: GUI attributes property name

26 4.1.2 Power Usage of the Devices On the other side, when user wants to check the power consumed by the devices, one has to click on the meter-reading button. Meter reading buttons property name is BUTTON 7, which sends m to microprocessor when pressed. RS232 device receives that data bits and gives it to Zigbee Transceiver. Zigbee Transceiver makes a packet using those data bits and sends it to its counterpart. Other Zigbee Transceiver receives that packet, decodes it and sends that data to microprocessor. As soon as microprocessor receives m on its receiver bit, it sends the power consumed by the devices to Zigbee Transceiver. Zigbee Transceiver takes that data, makes a packet, and starts sending that packet to other Zigbee Transceiver from whom it got the request. The Zigbee Transceiver, which is connected to GUI via RS232 interface, receives that packet, decodes it and sends data to GUI. GUI takes those data bits and displays the power usage in textbox, whose property name is TextBox10. Data bits received by the GUI needs to be stored in the database for future reference as well as for web enabled monitoring. To store received data bits to a database, one has to connect GUI to the database. This project uses Microsoft access as a database server. To connect to the database one has to import system.data and system.data.oledb classes in ASP.net framework, so that they can access the database [7]. After importing the base classes, one can connect to the database server by providing a pointer to it. To have full access to database one has to point to three classes of system.data.oledb base class. Figure 4.5 shows the pointers to the extended classes of the system.data.oledb base class.

27

Figure 4.5: Pointers to extended database classes After making pointers to extended classes and new objects of these classes, one can use these pointers to have access to database. When data is received by the serial port, it is stored into the database by providing the location where the database is stored and in what format data needs to be stored. Figure 4.6 shows the format of the data stored in the database.

28

Figure 4.6: Table showing the structure of the database 4.2 Web Enabled Power Monitoring Another part of this project is to see how much power is consumed by the devices. This part shows the collected information in a tabular form as well as in chart on a local host server based website. 4.2.1 Data in Tabular Form This part uses the data stored in a database server by Graphical User interface and displays the collected data in a tabular form. As previously discussed, one needs to import system.data and system.data.Oledb base classes to get access to the database server. To have full access to database one has to point to three classes of system.data.oledb base class. To show the data in tabular form, one database command is used to fetch data from the database. This database command fetches the data in the order

29 of descending dates. Local host website displays the data in tabular form with latest data first and then the older ones. 4.2.2 Data in Chart This part uses the data stored in a database server by Graphical User interface and displays the collected data in a chart. To display the information on the chart with proper labels and attributes, one needs to configure the chart properties. This can be easily done by exploiting the new features of Visual Studio 2010. One can select different chart types by giving the appropriate command names, for example for line type, command is SeriesChartType.line and for bubble type it is SeriesChartType.bubble [7]. One can also enable the labels for the values so that they can be displayed on the graph. Following figure 4.7 shows how one can set the chart types, enable labels through command.

Figure 4.7: Setting of chart attributes

30
Chapter 5

SIMULATION AND RESULTS

5.1

Graphical User Interface As explained in previous chapters, one can control the devices with the help of a

Graphical User Interface. If user clicks on the GUI to switch ON the first device, then a status message is displayed on the text box and a set of bits is sent to the microprocessor. Status that would be displayed in the Text Box will be Device 1 is switched ON at this date and time. Following figure shows the GUI with the status message.

Figure 5.1: GUI with one device ON

31 Microprocessor processes that data bit and sends signal to switch on the device 1, which is shown by the LED in the following figure 5.2.

Figure 5.2: Hardware kit showing device 1 ON Working of other devices can also be checked by switching on the other devices. Figure 5.3 show the status of the devices when all the devices are switched ON and figure 5.4 shows the same thing on the Hardware Kit.

32

Figure 5.3: GUI with all devices ON

Figure 5.4: Hardware kit with all devices ON

33 User can also check power consumed by the devices by clicking on the meterreading button. As soon as meter-reading button is pressed, GUI sends signal to microprocessor to give the data for the power consumed by the devices until that time. Microprocessor processes the data and sends the total power consumed back to GUI. GUI displays that data in the textbox as shown in figure 5.3. 5.2 Website Graphical user interface is not only displaying the data on the screen but it is also saving the data in a table. Figure 5.5 shows the collected data in a tabular form, which is visible on the website.

Figure 5.5 Data viewed on the website

34

Figure 5.6 Data shown in chart form

35
Chapter 6

CONCLUSION AND FUTURE EXPANSION

6.1

Conclusion Zigbee-based web enabled power monitor serves as a reliable and efficient

system for efficiently controlling the power consumption. Wirelessly controlling and monitoring of devices not only allows user to reduce the power consumption of devices, but it also allows user to see how much power the device consumes. Zigbee based web enabled power monitor is much cheaper in cost, consumes less power and can control 254 devices, which in turn leads to the development of lots of new technologies like Home Automation, Health Care Automation etc. Scope for Zigbee based Web enabled Power Monitor has been successfully implemented using ASP.net, Visual basic, Visual Studio 2010 and Microsoft Access Database that includes controlling of the devices using GUI and viewing of the power consumed by the devices on the website. I have learned a lot while implementing these functionalities for the Zigbee Project. In last couple of years, I was working on the hardware side of the electrical and computer engineering, but this project gave me opportunity to learn the software side too. From the start of the project, the learning curve for me was going higher and higher. Initially, I have to know how I can configure the serial port of the machine to communicate with the software. After that, I learned how to use Visual Studio to make GUI and finally how I can use commands to connect the GUI to database.

36 To summarize, I would like to make a note that Zigbee based Web Enabled power Monitor will soon serve as an efficient and cost effective application for controlling and monitoring the devices. 6.2 Future Expansion Zigbee based Web Enabled Power Monitor project is dealing with controlling and monitoring the devices with the help of wireless technology. By using efficient RF modules, one can control the devices from far distance as compared to what this project is doing now. In future, one can also add features to control the devices directly from the website, which would enable user to control the devices from wherever they are. Zigbee Based Web Enabled Power monitor project can also be extended in the field of Home Automation, Automatic Health Monitoring, Telecommunication services etc. This project not only helps in power monitoring, it can also be extended in the field of temperature control. For example, one can control the room temperatures before coming into the house directly through the wireless Zigbee Transmission Technique.

37
APPENDIX A

Graphical User Interface

frmpower.vb code page frmpower.vb implements the Graphical User Interface


'base class import Imports VB = Microsoft.VisualBasic Imports VB6 = Microsoft.VisualBasic Imports System.Data.SqlClient Imports System.Data Imports System.Data.OleDb Imports System.IO Public Class frmpower Public con As SqlConnection Public com, com1 As SqlCommand Public dr As SqlDataReader Public da As SqlDataAdapter Public ds As DataSet Public dt As DataTable Public k Public temp, temp1, a Public s As Object Dim d As New Date(Today.Year, Today.Month, Today.Day) Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer) 'pointers to database connection Dim accCon As OleDbConnection Dim accCmd As OleDbCommand Dim acccDr As OleDbDataReader Dim accIcount As Integer Dim accStr As String Dim dbPath As String = System.AppDomain.CurrentDomain.BaseDirectory & "powerconsumption.mdb" Private Sub frmpower_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label1.Text = Today.Date k = 0 'to check if serial port is open or not If SerialPort1.IsOpen Then 'to close the serial port SerialPort1.Close()

38
End If Try 'to configure the properties of the serial port communication With SerialPort1 .PortName = "COM1" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One .Handshake = IO.Ports.Handshake.None End With SerialPort1.Open() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived Dim InBuff As String InBuff = SerialPort1.ReadExisting() If a = "1" Then temp = InBuff TextBox10.BeginInvoke(New myDelegate(AddressOf updateTextBox), New Object() {}) ElseIf a = "2" Then temp1 = InBuff rtxt.BeginInvoke(New myDelegate(AddressOf updateTextBox1), New Object() {}) End If Sleep(200) ' to insert the values received into the table Try accCon = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & dbPath & ";") 'C:\PowerConsumption.mdb accCon.Open() accStr = "insert into DeviceReading ([Value],[CreatedDate],[Type]) values('" & InBuff & "','" & Now.ToString() & "','" & a & "')" accCmd = New OleDbCommand(accStr, accCon) accIcount = accCmd.ExecuteNonQuery ' MessageBox.Show(accIcount) Catch ex As Exception MessageBox.Show(ex.Message.ToString()) Finally

39
accCon.Close() End Try End Sub Public Delegate Sub myDelegate() Public Sub updateTextBox() Sleep(100) With TextBox10 .Text = TextBox10.Text.Trim + temp.Trim .ScrollToCaret() End With End Sub Public Sub updateTextBox1() Sleep(100) With rtxt .Text = rtxt.Text.Trim + temp1.Trim .ScrollToCaret() End With End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click TextBox10.Text = "" a = "1" SerialPort1.Write("m") Sleep(200) End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click rtxt.Text = "" SerialPort1.Write("s") a = "2" 'Sleep(200) End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 'device 1 ON SerialPort1.Write("1") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'device 1 OFF SerialPort1.Write("2") End Sub

40
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 'device 2 ON SerialPort1.Write("3") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'device 2 OFF SerialPort1.Write("4") End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click 'device 3 ON SerialPort1.Write("5") End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'device 3 OFF SerialPort1.Write("6") End Sub End Class

41 APPENDIX B Chart Feature

default.vb code page default.vb shows code for displaying chart on the website
'Base Class Import Imports System.Data.OleDb Imports System.Data Imports System.IO Imports System.Web.UI.DataVisualization.Charting Partial Class _Default Inherits System.Web.UI.Page 'declaration of pointers to database Dim accCon As OleDbConnection Dim accCmd As OleDbCommand Dim acccDr As OleDbDataReader Dim accIcount As Integer Dim accStr As String Dim dbPath As String = "C:\Documents and Settings\XPMUser\Desktop\powerconsumptionweb\Database\powerconsumption. mdb" 'System.AppDomain.CurrentDomain.BaseDirectory & "powerconsumption.mdb" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try FillData() ' Set series chart type Chart1.Series("Series1").ChartType = SeriesChartType.Line Chart1.Series("Series2").ChartType = SeriesChartType.Spline ' Set point labels Chart1.Series("Series1").IsValueShownAsLabel = True Chart1.Series("Series2").IsValueShownAsLabel = True ' Enable X axis margin Chart1.ChartAreas("ChartArea1").AxisX.IsMarginVisible = True

42

' Enable 3D Chart1.Series("Series1")("ShowMarkerLines") = "True" Chart1.Series("Series2")("ShowMarkerLines") = "True" Catch ex As Exception Response.Write(ex.Message.ToString()) Finally accCon.Close() End Try End Sub Private Sub FillData() 'get data from database accCon = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & dbPath & ";") 'C:\PowerConsumption.mdb accCon.Open() ' change 500000 to 5 for actual data accCmd = New OleDbCommand("select * from DeviceReading WHERE value <> ""0"" and CreatedDate<Now()", accCon) acccDr = accCmd.ExecuteReader() Dim plotY As Double = 0 ' Dim plotY2 As Double = 200.0 If Chart1.Series("Series1").Points.Count > 0 Then plotY = Chart1.Series("Series1").Points(Chart1.Series("Series1").Points.Count 1).YValues(0) End If Dim random = New Random() Dim pointIndex As Integer = 0 While acccDr.Read() plotY = Convert.ToDecimal(acccDr.Item("Value")) 'Chart1.Series("Series1").Points.AddY(plotY) Chart1.Series("Series1").Points.AddXY(CDate(acccDr.Item("CreatedDate")) .ToString("hh:mm:ss"), plotY) pointIndex = pointIndex + 1 End While End Sub End Class

43 APPENDIX C Main Page

about.aspx code page about.aspx is the main page for the website
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="about.aspx.vb" Inherits="about" %> <!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 id="Head1" runat="server"> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Power Consumption</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="header"> <img src="images/logo.jpg" style="float:right;" /> <h1>Power <br/><br/> Consumption</h1> </div> <div id="menu"> <ul> <li><a href="default.aspx">Home</a></li> <li><a href="detail.aspx">Detail</a></li> <li><a href="about.aspx">About Us</a></li> </ul> </div> <div id="content"> <div id="left" ><img src="images/user.jpg" style="paddingleft:25px;"/></div> </div> <div id="footer"> <p class="links"><a href="http://www.csus.edu/">California State University, Sacramento</a> </p> </div> </div> </body> </html>

44 APPENDIX D Database Feature

detail.vb code page detail.vb shows the database in a tabular form

Imports Imports Imports Imports

System.Data.OleDb System.Data System.IO System.Web.UI.DataVisualization.Charting

Partial Class _detail Inherits System.Web.UI.Page Dim accCon As OleDbConnection Dim accCmd As OleDbCommand Dim acccDr As OleDbDataReader Dim accIcount As Integer Dim accStr As String Dim dbPath As String = "C:\Documents and Settings\XPMUser\Desktop\powerconsumptionweb\Database\powerconsumption. mdb" 'System.AppDomain.CurrentDomain.BaseDirectory & "powerconsumption.mdb" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try bindGrid() Catch ex As Exception Response.Write(ex.Message.ToString()) Finally accCon.Close() End Try End Sub Public Sub bindGrid() Try accCon = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & dbPath & ";") 'C:\PowerConsumption.mdb accCon.Open()

45
accCmd = New OleDbCommand("select * from DeviceReading order by CreatedDate desc", accCon) grdList.DataSource = accCmd.ExecuteReader grdList.DataBind() Catch ex As Exception ' MessageBox.Show(ex.Message.ToString()) x : Time , y: Value Finally accCon.Close() End Try End Sub End Class

46
REFERENCES

[1] Ying-Wen Bai and Chi-huang Hung, Remote power on/off control and current measurement for home electric outlets based on a low-power embedded board and Zigbee communication, IEEE International Symposium on Consumer Electronics, 2008 [2] S. Ondrej, B. Zdenek, F. Petr and H. Ondrej, Zigbee Technology and Device Design, International Conference on Systems and Mobile Communication, 2006 [3] Microchip, Microchip Zigbee-2006 Residential Stack Protocol, pp 2-9, 2008 [4] Texas Instruments, Low-Cost Low-Power 2.4 GHz RF Transceiver, pp 29-35, 2009 [5] Guoxin Luo, Wireless transmission of RS232 interface signal based on Zigbee, Internatioonal Conference on Anti-counterfeiting security and identification, 2010 [6] .NET Feature, [ONLINE], Available: http://www.startvbdotnet.com/aspsite/asp/ [7] Connection between Database and GUI, [ONLINE], Available: http://msdn.microsoft.com/en-us/library/6d9ew87b%28v=VS.71%29.aspx [8] Namrata Agarwal, Remote Power Control Using Embedded Board and Zigbee, Masters Project Report, California State University, Sacramento, CA, Fall 2010

Vous aimerez peut-être aussi