Home

TR11-214 - Faculty of Computer Science

image

Contents

1. Screenshot at a browser window with the BaseComm web application showing a result table for a date query 32
2. Victoria Pimentel and Bradford G Nickerson Communication and control of a digital wind sensor Technical report University of New Brunswick October 2011 www cs unb ca tech reports documents TR11 211 pdf Jetty web server wikipedia Internet accessed October 2011 http en wikipedia org wiki Jetty_ 28Web_server 29 Ian Hickson The websocket api Internet September 2011 W3C Working Draft http www w3 org TR websockets Aditya Yadav Deploying HTML5 CreateSpace 2010 Victoria Pimentel and Bradford G Nickerson Communication and display of real time sensor data using the websocket protocol IEEE Submitted to Internet Computing Magazine November 2011 Chandan Luthra and Deepak Mittal Firebug 1 5 Editing Debugging and Monitoring Web Pages Packt Publishing April 2010 Maydene Fisher Jon Ellis and Jonathan Bruce JDBC API Tutorial and Reference Prentice Hall third edition 2003 Helmut Kopka and Patrick W Daly Guide to Latex Addison Wesley fourth edition February 2004 Texmaker free cross platform latex editor Internet accessed October 2011 http waw xmimath net texmaker Websequencediagrams com Internet accessed October 2011 http www websequencediagrams com Dia a drawing program Internet accessed October 2011 http projects gnome org dia 24 A User Manual This manual was written to guide the user under the installation of the software developed and presente
3. ew WebSocket GET Upgrade request WindCommServlet SerialComm Thread WindSonic l l l l InputStream OutputStream acceptWebSocket heckOrigin doWebSocketConnect WebSocket object readline broadcast data readline 101 Upgrade response WebSocket object onOpen onOpen StartCode 0 clients add diente add WebSocket sendMessag e data _onMessage data Figure 10 Sequence diagram that shows interaction between WindComm servlet and a client to change the sensor to configuration mode 17 270 90 lt wind fromnow wind from now A wind from now 4A wind from now 2A wind from now 3A Figure 11 Compass like graphic that shows 5 last measurements time intervals are shown When the wind speed is below 0 05 m s the graph shows the most recent nonempty wind direction value colored in red 5 1 2 Two dimensional Graphic The two dimensional graphic uses two arrays with a maximun length of 200 One of these arrays contains wind speed values and the other one wind direction values Both of the arrays are passed as arguments to a function that calculates the number of pixels per unit on both the x and y axes The values contained in both arrays are multiplied by the number of pixels per unit These new vales are interpreted as point coordinates and a line is drawn following each of these points As
4. with the graph in a transparent background that can be copied or saved as an image 7 Results We developed a database and two web based softwares to display sensor data The first web application is called WindComm and accesses the database to store sensor measurements The second web application is called BaseComm and queries the database The WebSocket protocol was chosen to be used on the WindComm web application to deliver real time sensor data Tests results show that for the real time low volume contin uous data used HTTP polling average latency is signficantly higher between 5 and 1 767 times higher than either WebSocket or long polling The WebSocket protocol can have a lower or greater average latency than HTTP long polling Under heavy traffic conditions or over longer distances e g to Japan the WebSocket protocol has significantly lower av erage latency than long polling Detailed results of the testing done to measure latency are presented in 9 WindComm displays real time sensor data at a high speed efficiently Sensor data is presented in graphics that are updated continuously at the output rate of the sensor The WindComm web application also uses the WebSocket protocol to provide a full duplex channel between the user and the wind sensor through a user friendly interface The user can change settings for the wind sensor and choose to save the data that is currently being displayed in a remote database BaseComm displays
5. 2011 12 07 13 10 06 13 America Halifax 21Q 110 001 71 M 00 019 2011 12 07 13 10 07 5 America Halifax Command Send Message Sensor mode Continuous Database recording ON Screenshot at a browser window running the WindComm web application with the sensor in continuous mode and the database recording ON 31 B 3 BaseComm Web Application Figure shows a screenshot at a BaseComm web application showing a query results set 131 202 240 184 8080 BaseComm v G 2 COMPUTER UNB SC ENCE HOMEPAGE WINDCOMM BASECOMM PHOTOS Comments BaseCo m m When the reported wind speed value is below 0 05 m s the wind sensor does not report a value for Node Address Direction Speed Units Status Date and time UTC offset lt 0 05 m s wind direction The raw observation has e g Q 202 0 07 M 00 2011 12 13 09 12 05 74 4 0 N Q 000 03 M 00 where the wind direction is Q 215 0 05 M 00 2011 12 13 09 12 06 66 4 0 N R 6 9 B Q 215 0 03 M 00 2011 12 13 09 12 07 73 4 0 Y missing We record a missing wind direction in Q 114 0 75 M 00 2011 12 13 09 12 08 81 4 0 N the database as the negative of the most recent Q 123 1 33 M 00 2011 12 13 09 12 09 73 4 0 N wind direction having a wind speed gt 0 05 m s Q M 2011 12 13 09 12 10 80 N If wind directions are missing since the start of aes SSeS database recordin
6. MySQL database and a Jetty server with the BaseComm web applica tion The database is used by base station 1 to store sensor readings and by the BaseComm web application The BaseComm web application implements a Jetty servlet that manages HTTP requests to query the database with parameters especified by the user through an HTML form 2 4 Client The client connects to either WindComm or BaseComm web applications through a web browser The web browser must support the Canvas element and the WebSocket protocol from HTML5 The client can connect to the WindComm web application to see real time wind sensor data or to the BaseComm web application to query the database Database Base Station 2 Observation Base Station 1 Gill WindSonic Sensor node MySQL D N Servlet class onSocket js toServer js wrah index html BaseComm web application WindComm web application Jetty Jetty HTTP and WebSocket HTTP web server server Near real time channel Database query channel Supporting HTMLS and the WebSocket protocol Show observations near real time Queries the DB Web Browser Client Figure 1 Architecture diagram showing the base station computers and their components WindSonic mra Base station 1 computer Power Special RS232 RS232 to USB USB serial supply connector cable adaptor port cable Figure 2 The Gill WindSonic wind sensor and the instruments and devices used in devel
7. Venezuela Guest student for the Jul Dec 2011 period at the University of New Brunswick Fredericton Canada Contact v_pimentel gue gmail com Bradford G Nickerson Professor in the Faculty of Computer Science at the University of New Brunswick Assistant Dean Research and Outreach for UNB s Faculty of Computer Science and Software Engineering program coordinator More information Screenshot at a browser window running the WindSensor web application 30 B 2 WindComm Web Application Figure shows a screenshot at a running WindComm web application B 131 202 243 62 8080 windcomm ve WindComm N mis deg 0 19 182 0 15 145 6 11 109 2 WwW E 270 90 07 728 04 36 4 S 0 0 Speed mis 09 180 Direction deg Number of measurements on the graph 47 Maximum speed value 001 87 Minimum speed value 000 10 Maximum direction value 182 Minimum direction value 032 21Q 045 000 27 M 00 01A 2011 12 07 13 09 57 999 America Halifax 1Q 032 000 28 M 00 015 2011 12 07 13 09 59 7 America Halifax 21Q 100 001 04 M 00 11A 2011 12 07 13 09 59 999 America Halifax RQ 113 001 03 M 00 11F 2011 12 07 13 10 01 7 America Halifax 1Q 124 000 42 M 00 01F 2011 12 07 13 10 01 998 America Halifax 21Q 111 000 21 M 00 1C 2011 12 07 13 10 03 6 America Halifax 1Q 104 000 11 M 00 01B 2011 12 07 13 10 04 13 America Halifax 21Q 090 000 19 M 00 01F 2011 12 07 13 10 05 5 America Halifax RQ 118 001 07 M 00 110
8. WebSocket connection with the following call this _ws new WebSocket hostlocation protocol The variable hostlocation is the name of the host and the location of the servlet The variable protocol corresponds to the optional argument of a protocol for a particular web application This method parses components and returns a new object It establishes a socket con nection by sending an upgrade request to the server Then the client waits for the server response and validates it If everything went fine the client is ready to handle the socket methods such as onOpen onMessage onError and onClose These methods are im plemented in the client 3 2 3 Testing Jetty Setup Jetty distribution comes with a web application called test Once the Jetty server is locally installed this test application can be accessed through http localhost 8080 The test jar file comes with several demos for all of Jetty s features including the WebSocket implementation The chat demo application was used to test web browser support and to check the successful installation of Jetty web server The chat implementation explained by 10 Aditya Yadav 8 provides a very good understanding on how to work with the WebSocket protocol using Jetty components with Java and JavaScript Jetty was chosen among other servers because the WebSocket protocol implementation is fully integrated into the Jetty servlet container Thus a servlet that
9. following command export LD_LIBRARY_PATH RXTX_HOME Linux i686 unknown linux gnu If your computer runs in a 64 bit processor try the following export LD_LIBRARY_PATH RXTX_HOME Linux ia64 unknown linux gnu 27 or export LD_LIBRARY_PATH RXTX_HOME Linux x86_64 unknown linux gnu 4 Start Jetty on the opened terminal where you performed the previous step by running java jar start jar 5 Open a web browser and go to http localhost 8080 WindComm if accessing from localhost To access from other computer go to http ipaddress 8080 WindComm and replace ipaddress with the ip address of the computer where you are running the Jetty web server 6 Instructions for using WindComm are found in the user interface presented at http ipaddress 8080 WindComm Please read the button legends and the supported com mands for the WindSonic WindSensor and BaseComm run in the same Jetty server After going through the sections A 2 1 and A 3 1 you can run the steps on section A 3 2 and have both WindSensor and WindComm web applications running in the server A 4 BaseComm Web Application The following steps will guide you through the BaseComm web application installation on the Jetty web server and the BaseComm database setup On the following steps it is asumed that Jetty and MySQL are correctly installed on the selected computer most Linux distributions come with MySQL type mysql in a command line to check Jet
10. open the ports 123 8080 843 and 8787 These ports will be used by Jetty and by the WebSocket protocol A 3 2 Running the WindComm Web Application 1 Check that the sensor is connected correctly to the computer through the serial port open a terminal and run minicom Make sure Minicom is well configured Press Ctrl A and then O Move to Serial port setup and change the necessary fields until the configuration looks like Serial Port Setup A Serial Device dev ttyUSBO B Lockfile Location var lock C Callin Program D Callout Program f E Bps Par Bits 9600 8N1 F Hardware Flow Control No G Software Flow Control No Press Esc and move to Modem and Dialing and change the the Init string value to empty as shown above Modem and Dialing JA Init string Press Esc move to Save setup as dfl press Enter and then move to Exit and press Enter Restart Minicom to check that the sensor is in continuous mode You should see data incoming If not it might be that Minicom is not well configured or that the sensor is not in continuous mode Make sure that Minicom is well configured and change the sensor to continuous mode using the WindSonic configuration commands Exit Minicom pressing Ctrl A then X and Enter 2 Open a terminal and cd to JETTY_HOME 3 If your computer runs in a 32 bit processor run the
11. DB query String ContextH andlerCollection sendErrorMsg response HttpServiletResponse sendResponse rs ResultSet response HttpServletResponse ContextH andler contextPath resourceBase classLoader SessionHandler SessionManager SecurityHandler WebAppContext b b webapps index html jCanvasScript js grap hCanvas js calendar js toServer js export html response htm l stylegraph css graph htm style css aia web xml classes basecomm BaseCommServlet class Figure 13 Jetty class diagram and BaseComm web application file structure Files followed by an were created for this project 20 Node Address Direction Speed Units Status Date and time UTC offset lt 0 05 m s Q 118 1 25 M 00 2011 12 0713 09 23 963 4 0 N Q 144 0 45 M 00 2011 12 0713 09 24 970 4 0 N Q 144 0 03 M 00 2011 12 0713 09 25 978 4 0 Y Table 1 Example of the table that is used to present query results to users separated by the tab character t and rows separated by the new line character n The user can copy the text from the HTML table presented or use the exported plain text format as input to other applications To Plot means that the data presented in the table as a result of a query is plotted in the two dimensional graphic used in the WindComm web application A new tab is opened
12. Installation lt tr tee ay eS Se Si dee Se eo ee ee Windsensor Web Application 4 a aye Hide ow We Been ele oh RA A 2 1 Installing the WindSensor Web Application A 2 2 Running the WindSensor Web Application WindComm Web Application ow eee ace ere Arce sel dae cee be A 3 1 Installing the WindComm Web Application A 3 2 Running the WindComm Web Application BaseComm Web Application 2 a a a w Be eB amp 12 12 16 16 18 19 19 21 22 A 4 1 Installing the BaseComm Web Application 28 A 4 2 Running BaseCcomm Web Application 29 B Screenshots 30 B 1 Windsensor Web Application y 4 4 ctu Sete Mae al oe al ee wee eS 30 B 2 WindComm Web Application te tes ae oe te Bee eke he ee 31 B 3 BaseComm Web Application lt x lt 4 ay a a a 32 List of Figures 1 2 10 11 12 13 Architecture diagram showing the base station computers and their components 5 The Gill WindSonic wind sensor and the instruments and devices used in developing the applications Gute rs aoa a ed le a Bln amp EW acd Ge 6 Default format for a wind measurement message of the WindSonic extracted fror El Ye Se Be ie eink ak ile Sa Wi ee ae ee Re Be ee Se 6 Jetty is the union between connectors handlers and a thread pool extracted Teng Ne sin A EE R oO Ae eG ted ve Se CA ee al ea eR a ee a Se 7 Jetty s detailed comp
13. To stop Jetty press Ctrl C on the console where you ran step 5 A 2 WindSensor Web Application The following steps will guide you through the WindSensor web application installation on the Jetty web server In the following steps it is asumed that Jetty is correctly installed on the selected computer under JETTY_HOME 25 A 2 1 Installing the WindSensor Web Application 1 Select a computer to be base station 1 2 Open the project CD and go to Code JettyFolders and copy the folder WindSensor 3 Make sure Jetty is not running and paste the folder into JETTY_HOME webapps A 2 2 Running the WindSensor Web Application 1 Start jetty on a terminal running java jar start jar 2 Open a web browser and go to http localhost 8080 WindSensor if accessing from localhost To access from other computer go to http ipaddress 8080 WindSensor and replace ipaddress with the ip address of the computer where you are running the Jetty web server A 3 WindComm Web Application The following steps will guide you through the WindComm web application installation on the Jetty web server and the RXTX Java library download and setup In the following steps it is asumed that Jetty and Minicom are correctly installed on the selected computer most Linux distributions come with Minicom type minicom in a command line to check Jetty is installed under JETTY HOME and the Gill WindSonic wind sensor is available powered up and the s
14. Web Display of Real time Wind Sensor Data by Victoria Pimentel and Bradford G Nickerson TR11 214 December 2011 Faculty of Computer Science University of New Brunswick Fredericton N B E3B 5A3 Canada Phone 506 453 4566 Fax 506 453 3566 E mail fes unb ca http www cs unb ca Contents 7 8 Introduction Software Architecture 2al 2 2 2 3 2 4 The Gill WindSonic Wind Sensor 0 0 0 0 0 000000 es Observation Base Station 1 2 2 0 0 0 00000 a Database Base Station2 0 aaa e a Client sretao drabas keh Se aa eel eh aed eatin ot Pee Sea B Sa Bes Solution Design 3 1 3 2 3 3 3 4 Wind Sensor Communication 2 0 0000000 eee ee Jetty Web OETVEL 2 ob Gat sbes p 8 6 a Rein SR ee Se it eae ar 3 2 1 Web Applications sack ahh pce Soe Ee ae ES ale Oe pte won 3 2 2 Implementation of the WebSocket API 3 2 3 Testing Jetty Setup oaa Database Design a sadis a a TRR aE TE len E TE a Peeks A TAT E Experimental Desigt s is dany 0k eae E EA ee ee RT R T T WindSensor Web Application WindComm Web Application 5 1 WindComm User Interface oa aaa a 5 1 1 Compass like Graphic ode coh ated oie ke ah Y See Y Bd 5 1 2 Two dimensional Graphic 2 200022 tees BaseComm Web Application 6 1 BaseComm User Interface 0 0 0 0000 eee eee Results Conclusions References A User Manual A l A 2 A 3 A 4 Jetty Web Server
15. a handshake message from the client and the response handshake from the server The second part is data transfer To establish a WebSocket connection a servlet must receive and respond to HTTP requests and must support upgrade requests from HTTP to WebSocket connections Jetty s implementation of the WebSocket API is fully integrated into Jetty HTTP server and servlet container Thus a Jetty servlet can process and accept a request to upgrade an HTTP connection to a WebSocket connection Figure 6 shows a sequence diagram that describes the interaction between the server and the client to establish a WebSocket connec tion In a Jetty servlet the method init gets called once upon the first client request to the new WebSocket Jetty_S erver nito 1 acceptWebSocket CheckOrigin doWebSocketConnect WebSocket object upgrade WebSocket object onOpen At this point a two way communication is established between the server and the client Client Jetty_Server www websequencediagrams com Figure 6 Sequence diagram that shows interaction between any WebSocket client and a Jetty servlet server This method is to manage resources that are held for the life of the servlet and must start and configure the WebSocketFactory When a server receives a GET request the method doGet is called This method handles all HTTP GET requests Both of this methods init and doGet belong to the H
16. al RS232 RS422 and RS485 output and serial number 08320007 to the base station 1 through an RS232 output cable which is connected to a USB serial port in the base station 1 computer via an adapter We simulated wind with a rotating fan that provides continuously changing wind direction and speed The WindSonic wind sensor can operate in three modes continuous polled and config uration Continuous and polled modes are measurement modes In continuous mode the sensor sends wind measurements at a fixed constant rate In polled mode the sensor sends data upon a request from the base station 1 computer In configuration mode settings for the wind sensor can be changed such as measurements units change of measurement mode and output rate In the default format a measurement message from the WindSonic wind sensor is 24 char acters long As explained in the WindSonic user manual 1 a message from the WindSonic looks like the one shown in Figure 3 2 2 Observation Base Station 1 Base station 1 runs a Jetty server with the WindComm web application The WindComm application implements a Jetty servlet that manages HTTP and WebSocket requests The application reads data from the sensor and makes it accessible to clients through a web interface The WindComm web application stores the data that is currently being received from the sensor in a remote database running on the base station 2 computer 2 3 Database Base Station 2 Base station 2 runs a
17. alues for wind direction means that the wind speed value is below 0 05 m s and that the direction value displayed corresponds to the latest nonempty wind direction reported To avoid confusing users the negative symbol is removed from the wind direction value and another column labeled lt 0 05 m s is displayed on the results table This column can have two possible values Y or N Y means the wind speed is below 0 05 m s and the wind direction value corresponds to the most recent nonempty value reported N means the wind speed is greater or equal to 0 05 m s Table 1 is an example of how the table presented to users looks like when the client displays a query response from the server Once the table is presented the user can choose to Export or Plot the results presented in the table To Export means to present the table data in a plain text format with columns 19 Connector t host String port int ThreadPool dispatch runnable Runnable javax http HttpServlet doGet req HttpServietRequest resp HttpServletResponse doPost req HttpServletRequest resp HttpServiletResponse init 1 BaseCommServlet connection Connection connected boolean connect connectionuURL String username String password String dateQuery request HttpServietRequest directionQuery request HttpServietRequest speedQuery request HttpServietRequest query
18. an improvement in latency for real time applications We im plemented two Jetty servlets in two different computers and a MySQL database One servlet runs an application that reads data from the sensor and uses the WebSocket protocol to transmit real time sensor data and to provide a full duplex communication channel with clients This application also displays and stores real time measurements in a database that is used by the second Jetty servlet This second application provides a query channel to display subsets of sensor data The web applications use the Canvas element from HTML5 to display sensor data Graphical user interfaces are provided for display of real time wind data and for displaying and exporting the results of a database query 1 Introduction This project investigates the real time measurement and display of relatively high speed i e up to 4 Hz environmental sensor data This project develops a web based software platform for use by graduate students and researchers working on sensor networks The project involves developing software for two computers One reads real time sensor measurements from a serial port and a second one stores and serves up sensor data The speed at which measurements are delivered to the user provides evidence of the application s ability to deliver real time sensor data and to keep up with the sensor output rate We explored different ways of accessing data from a sensor connected to a serial port Th
19. base created and grant all privileges and usage to the users created on the previous step with the following commands gt grant all privileges on BaseComm to basecomm gt flush privileges gt grant usage on to basecomm identified by basecommaccess gt flush privileges gt grant all privileges on BaseComm to windcomm gt flush privileges gt grant usage on to windcomm identified by windcommaccess gt flush privileges A 4 2 Running BaseComm Web Application 1 Open a terminal and cd to JETTY_HOME 2 Start jetty on the opened terminal by running java jar start jar 3 Open a web browser and go to http localhost 8080 BaseComm if accessing from localhost To access from other computer go to http ipaddress 8080 BaseComm and replace ipaddress with the ip address of the computer where you are running the Jetty web server 29 B Screenshots B 1 WindSensor Web Application Figure shows a screenshot at a running WindSensor web application B 131 202 243 62 8080 WindSensor rej Faculty of J COMPUTER HOMEPAGE UNB SCIENCE WINDCOMM BASECOMM PHOTOS Web Display of Real time Wind Sensor Data by Victoria Pimentel and Bradford G Nickerson This project was built to provide a Linux web platform software for the Gill WindSonic wind sensor The Gill WindSonic is a robust ultrasonic wind sensor with no moving parts The sensor measures wind direction and spee
20. d We connected the WindSonic option 3 with analog plus serial RS232 RS422 and RS485 output and serial number 08320007 through an RS232 output cable to a USB serial port in a base station computer via an adapter The WindSonic wind sensor can operate in three modes continuous polled and configuration In continuous mode the WindSonic takes and sends measurements up to four times per second In polled mode the sensor sends a measurement upon a host request In configuration mode the user can change settings for the wind sensor operation The Base Station 1 computer has a Jetty server running with the WindComnr b application This application communicates with the sensor and uses the WebSocket protocol to transmit real time sensor data at an output rate up to 4 Hz The WindComm application uses the Java DataBase Connectivity JDBC to store in a remote database the data that is currently being received from the sensor The base station 1 computer provides a near real time channel for sensor data The Base Station 2 computer runs a MySQL database accessed by the WindComm application to store sensor readings The base station 2 also has a Jetty server running with the Ba mm application This application queries the database that runs locally using JDBC This web application provides a database query channel for clients that request less recent sensor measurements Victoria Pimentel Undergraduate student at Universidad Simon Bolivar Caracas
21. d in this project The software has been developed and is intended to be installed on a Linux platform Once installed the software can be accessed from any web browser client supporting HTML5 regardless of the operating system Web browsers suggested are the latest versions of Mozilla Firefox and Google Chrome A 1 Jetty Web Server Installation These steps will guide you through the Jetty web server download and installation 1 Go to http download eclipse org jetty and select the stable 8 version and click download 2 Select the file extension of your choice recommended tar gz and save the file in the local directory of your choice 3 Go to the directory where you saved the Jetty downloaded file and extract it in the directory where you want to install Jetty We will refer to this directory as JETTY_ HOME 4 Open a terminal and cd to JETTY_HOME 5 Run the following command java jar start jar Jetty is running in this terminal If you close or stop the terminal Jetty will be stopped and the server will not be accessible 6 Open a browser and go to http localhost 8080 7 If you see a Jetty welcome page Jetty was successfully installed Click on the link WebSocket and try the chat application to test browser support for the WebSocket protocol If you get a message that says that WebSockets is not supported on your browser update your browser to the latest version and try the previous step again 8
22. d the best case scenario for HTTP polling in a real time application 9 We experimentally validated latency behavior at a 4 Hz rate for low volume around 100 bytes per second of sensor data communication typical of real time sensor networks We implemented three web applications called WindComm LongPollingWindComm and PollingWindComm that use the WebSocket protocol HTTP long polling and HTTP polling respectively Our tests ran each of these applicationes one after another at three different times of day until 1 198 messages were succesfully delivered for each application At an output rate of 4 Hz the fastest test lasted five minutes The first test was planned for around 8 00 not busy the second test around 13 00 normal traffic and the third test around 20 00 busy We chose these different times of day to vary the state of the network for all of the tests We ran the tests between our server located at the University of New Brunswick Fredric ton N B Canada with clients in Canada Venezuela Sweden and Japan 4 WindSensor Web Application WindSensor is a very simple user friendly web application that shows the project homepage and has links to the WindComm web application in base station 1 and to the BaseComm web applicacion in base station 2 5 WindComm Web Application WindComm is the web application that runs in base station 1 WindComm is an application that uses the WebSocket protocol to communicate near real time sensor
23. data to all the clients connected Figure 8 a shows HTTP headers from the WindComm web application obtained using Firebug 10 for Mozilla Firefox version 6 0 2 These headers show the upgrade request from HTTP connection to WebSocket connection and the server response Figure 8 b shows the timeline provided by Firebug for the GET windcomm upgrade request shown in Figure 8 a These times may vary 12 XI 2 Console HTML CSS Script DOM Netv th Clear Persist HTML CSS JS XHR Images Flash Media GET WindComm GET jCanvaScript js GET onSocket js GET style css GET compassCanvas js GET windcomm Headers Response Response Headers Upgrade Connection Sec WebSocket Accept Sec WebSocket Protocol Request Headers Host User Agent Accept Accept Language Accept Encoding Accept Charset Connection Sec WebSocket Version Sec WebSocket Origin Sec WebSocket Protocol Sec WebSocket Key Pragma Cache Control Upgrade 304 Not Modified localhost 8080 2 7 KB 127 0 0 1 8080 304 Not Modified localhost 8080 83 8KB 127 0 0 1 8080 304 Not Modified localhost 8080 2 9KB 127 0 0 1 8080 304 Not Modified localhost 8080 586B 127 0 0 1 8080 304 Not Modified localhost 8080 2 9KB 127 0 0 1 8080 101 Switching Protocols localthost 8080 0 127 0 0 1 8080 WebSocket Upgrade DnGaoUbr8D9hzFW102xxNSwirYSc windcomm localhost 8080 Mozilla 5 0 X11 Linux 1686 rv 6 0 2 Gecko 20100101 Firefox 6 0 2 text ht
24. duplex communication channel between the server and the clients We observed latency values between 0 and 2 ms between the base stations 1 and 2 Between these two computers the network state barely affects latency and the traveling distance is very small Jetty s implementation of the WebSocket is efficient and robust We developed a web based Linux platform software for the WindSonic wind sensor that provides real time sensor data and access to subsets of previous sensor readings We used two base station computers to distribute the load and provide the user with high speed re sponses 22 How this Document was Created LaTeX 12 version pdfeTeX 3 141592 1 21a 2 2 Web2C 7 5 4 with Texmaker 13 version 3 1 on CentOS version 5 7 Figures 1 and 7 using PowerPoint 2007 on Windows 7 Figure 6 using WebSequenceDiagrams com 14 on CentOS version 5 7 Class diagrams and the rest of sequence diagrams using Dia 15 version 0 96 1 on Windows ig 23 References 1 10 11 12 13 14 15 Gill Instruments Ltd WindSonic User Manual July 2011 Issue 20 Doc No 1405 PS 0019 http www gill co uk data manuals manuals htm The Eclipse Foundation Jetty reference jetty architecture Internet accessed October 2011 http wiki eclipse org Jetty Reference Jetty_Architecture Jetty webserver Internet http jetty codehaus org jetty Rxtx wiki Internet http rxtx qbang org wiki index php Main_Page
25. e method This method assigns the input text to variable forThread that the thread checks periodically When the thread finds that variable forThread is not 14 Connector host Strin port int org eclipse jetty websocket W ebSocket javax http HttpServiet Z onTextMessage doGet req HttpServletRequest resp HettpServletResponse I WindCommWebSocket onOpen connection Connection onClose closeCode int message String onMessage data String ThreadPool HandlerCollection gt _wsFactory _clients forThread basecomm database DBrecording mode ContextH andlerCollection run handleStartCode code int ws WindConmmWebSocket AN handleStopCode code int ContextHandler U S A SessionHandler 2 SecurityHandler E SoervictHandler zescurceBase classLoader A 5 LA WebAppContext webapps WindComm index ht rm jCanvasScript js compassCanvas js grap hCanvas js dropmenu js onSocket js style css daai web xml classes com gnu org windcomm WindCommServlet class BaseCommDB class WindSonicSensor class Figure 9 Jetty class diagram and WindComm web application file structure Files followed by an were created for this project 15 null it checks if forThread contains a valid command and sends it to the sensor If the input text from the user is not a valid command the thread does not
26. ensor RS232 output cable is connected to a USB adapter 5 A 3 1 Installing the WindComm Web Application 1 Use the computer selected as the base station 1 and connect the USB adapter cable from the WindSonic RS232 output to the computer serial port 2 Open the main project directory and go to Code JettyFolders and copy the folder WindComm 3 Make sure Jetty is not running and paste the folder into JETTY_HOME webapps 4 Open the main project directory and go to Code NetbeansFolders WindComm src windcomm open the file BaseCommDB java and change the ip address part of the variable con nectionURL in line 23 with the ip address where you will install BaseComm web application and database Compile the new file and place the new BaseCommDB class under JETTY_HOME webapps WindComm WEB INF classes windcomm to replace the older BaseCommDB class 5 Go to http rxtx qbang org wiki index php Download download the binary re lease rxtx 2 1 7r2 stable and save the file in the local directory of your choice These are the files of the RXTX Java library that will be used by WindComm to communicate to the wind sensor through the computer serial port 26 6 Go to the directory where you saved the RXTX downloaded file and extract it in the directory where you want to keep the RXTX files We will refer to this directory as RXTX HOME 7 If you have a Firewall enabled and want to allow access to the web application from other computers
27. erage for real time internet communication More detailed conclusions on these tests can be found on 9 We developed the WindComm web application that can keep up with a 4 Hz sensor output rate using the WebSocket protocol Sensor measurements are delivered at a high speed and presented to the user in two graphics drawn using the Canvas element of HTML5 We worked with array sizes up to 200 The array contents were continuously changed Our Canvas interface was erased and drawn again every time the WindComm application received a new measurement from the server this happens depending on the output rate of the sensor at 1 2 or 4 Hz We observed that both Canvas graphics can keep up with continuous fast incoming data We used MySQL to create a database in which sensor data was continuously stored If the database recording is on every time the server receives a measurement from the sensor an INSERT statement is executed using the JDBC API at the database that runs in the base station 2 As with the Canvas element the INSERT statements were executed depending on the output rate of the sensor at 1 2 or 4 Hz Base station 1 is located in the same laboratory ITB 214 as base station 2 Thus they are part of the same network This can influence the high speed of storing sensor measurements received at base station 1 in the database runnin on base station 2 Jetty s implementation of the WebSocket API and protocol is very useful and provides a full
28. g i e all wind speeds are lt Q M 2011 12 13 09 12 13 72 N 0 05 m s since the start of database recording Q 216 0 11 M 00 2011 12 13 09 12 14 79 4 0 N then the database records a zero for the missing Q 214 0 14 M 00 2011 12 13 09 12 15 86 4 0 N wind direction These initial zero wind directions Q 223 0 12 M 00 2011 12 13 09 12 16 78 4 0 N are not real measurements they simply indicate a Q 239 0 08 M 00 2011 12 13 09 16 34 903 4 0 N E S Q 228 0 09 T M 00 2011 12 13 09 16 35 143 40 N missing wind direction in the observed data and Q 225 0 09 M 00 2011 12 13 09 16 35 399 4 0 N the wind direction is invalid Q 219 0 09 M 00 2011 12 13 09 16 35 655 4 0 N apee E Brian Q 189 0 07 M 00 2011 12 13 09 16 36 407 4 0 N Q 182 0 07 M 00 2011 12 13 09 16 36 647 4 0 N Export Plot New query Q 162 0 05 M 00 2011 12 13 09 16 36 903 4 0 N s Q 162 0 02 M 00 2011 12 13 09 16 37 143 4 0 L Q 162 0 03 M 00 2011 12 13 09 16 37 399 4 0 Y Export displays the queried data in a plain text Q 162 0 03 M 00 2011 12 13 09 16 37 655 4 0 Y format Columns are separated by the tab Q 162 0 03 M 00 2011 12 13 09 16 37 895 4 0 character and rows by the new line character Q 111 0 05 M 00 2011 12 13 09 16 38 151 4 0 N i making it easy to copy and paste in other Q 90 0 07 M 00 2011 12 13 09 16 38 407 4 0 N a 117 N25 T M An 2011 17 12 09 16 38 AAT AN N documents Data as displayed on the left can lt
29. is data needs to be accessed from a web application to make sensor measurements available to all connected clients We explored the feasibility of current web based protocols in delivering such data efficiently to web browsers from web servers We considered the requirement of a full duplex communication channel between users and the wind sensor The project also investigated storage of real time sensor data in a web accessible database Support for queries on date range and on range of wind direction and speed was implemented A graphical user interface was designed and implemented to provide both real time and historical measurement data This report documents this investigation and presents our findings 2 Software Architecture The project develops in two computers running CentOs The observation base station 1 com puter has a Jetty 3 server running with the WindComm web application This application provides a near real time channel for the clients that request new sensor data The database base station 2 computer has a Jetty server running with the BaseComm web application This application provides a database query channel for clients that request less recent sensor data The project architecture is shown in Figure 1 and 2 2 1 The Gill WindSonic Wind Sensor The Gill WindSonic is a robust ultrasonic wind sensor with no moving parts The sensor measures wind direction and speed We connected the WindSonic option 3 with analog plus seri
30. ml application xhtml xml application xml q 0 9 q 0 8 en us en q 0 5 gzip deflate 1S0 8859 1 utf 8 q 0 7 keep alive Upgrade 7 http Localhos t 8080 windcomm gz7kyIEfYs flav6DDmushA no cache no cache websocket 3q 0 7 a Firebug shows the HTTP requests from the client The red arrow points at the upgrade connection request from HTTP to a WebSocket connection The HTTP headers displayed correspond to the upgrade connection request on m 127 0 0 1 8080 q_________________ _ lims n Kd tm s 3 03s Request start time since the beginning Request phases start and elapsed time relative to the request start Jo lms lms DNS Lookup Connecting Sending Waiting Receiving f lms 8 2ms f 2ms t1lms b Timeline from Firebug for the WindComm web application requests shown in part a of this Figure The red arrow points at the GET windcomm upgrade request timeline Figure 8 Firebug Net panel screenshots To get the complete view add part b to the right of part a of this Figure as indicated by the A letter 13 The WebSocket protocol is a very helpful tool for this project The output rate of the sensor can be up to 4 Hz Thus a high speed communication is required to deliver near real time data to clients The sensor has configuration settings that a client can change measurement units output rate measurement mode among others Therefore a full du plex commu
31. nication between the sensor and the clients is necessary so a client can send configuration commands to the sensor and receive the response The WindComm web application was developed following Jetty specifications Figure 9 shows Jetty s components class diagram and the WindComm web application file structure The Java class WindCommServlet is the servlet that handles HTTP and WebSocket requests This class uses the BaseCommDB class to connect to the database in the base station 2 and the WindSonicSensor class to communicate with the sensor onSocket js implements the client socket methods and communicates with the server to receive sensor data The BaseCommDB class uses the Java DataBase Connectivity JDBC API 11 to com municate with the database running in the base station 2 JDBC provides access to remote and local databases from a Java program The WindCommServlet class communicates with the clients using the WebSocket proto col The servlet creates a thread to start and handle communication with the sensor while the servlet serves requests from clients The thread created by the servlet uses the RXTX Java library 4 to connect and communicate with the wind sensor Then the thread broadcasts the messages received from the sensor to all current connections If the client has selected to store current data in the database the thread executes an INSERT statement every time a sensor message is received using an instance of the BaseCommDB clas
32. onents and classes extracted from 2 2 2 0 8 Sequence diagram that shows interaction between any WebSocket client and CEE servlet m pian hake loge gt 1S Aen keds ig Mas bei og as asthe Sel TT 9 Database design to store WindSonic messages and a server timestamp 12 Firebug Net panel screenshots To get the complete view add part b to the right of part a of this Figure as indicated by the A letter 13 Jetty class diagram and WindComm web application file structure Files followed by an were created for this project 004 15 Sequence diagram that shows interaction between WindComm servlet and a client to change the sensor to configuration mode 17 Compass like graphic that shows 5 last measurements time intervals are shown 18 Two dimensional graphic showing the last 71 wind speed and direction values received ard sak wa iad an ita ret at Ooh hes PA ana te gat Pa ah A te oe Se 19 Jetty class diagram and BaseComm web application file structure Files fol lowed by an were created for this project 2 0 0 ee ee 20 Abstract This project explores different ways of accessing and delivering real time environ mental sensor data efficiently at a relatively high speed We compared average latencies between the WebSocket protocol HTTP long polling and HTTP polling in delivering real time wind sensor data at a rate of 4 Hz On average we observed that the Web Socket protocol provides
33. oping the applications lt STX gt Q 229 002 74 M 00 lt ETX gt 16 Z L WindSonic Wind Wind Units Status Check Node address direction speed sum Figure 3 Default format for a wind measurement message of the WindSonic extracted from 1 Connector ThreadPool Figure 4 Jetty is the union between connectors handlers and a thread pool extracted from 2 3 Solution Design There are many strategies for reading data from a sensor that is connected to a computer serial port However displaying this data in real time involves accessing the serial port and making the data accessible to any client efficiently The database must keep up with the continuous execution of INSERT statements while processing any possible query by any client 3 1 Wind Sensor Communication WindComm uses the RXTX 4 Java library to access the computer serial port and commu nicate with the wind sensor RXTX was chosen among three other techonologies 5 because the RXTX Java library does not involve file manipulation and can easily be accessed from a Java program This project investigates web based protocols to deliver high speed sensor data efficiently to web browsers from web servers Therefore efficient access to the serial port is very important and this can be achieved from a Java servlet using the RXTX library 3 2 Jetty Web Server Jetty is defined in Wikipedia as a pure Java based HT TP client server WebSocket client
34. receives HTTP requests can be implemented to upgrade to a WebSocket connection Besides Jetty is a pure Java based client server and servlet container which supports the use of the RXTX Java library to access the serial port to communicate with the sensor 3 3 Database Design The database was designed to store all the information from the WindSonic messages and a timestamp taken at the time the measurement was received at the server Considering that the WindSonic messages have the format presented in Figure 3 the database was designed according to the Entity Relationship ER model shown in Figure 7 The relational model corresponds to Measurement dateTime ms UTCoffset nodeID direction speed units status Measurement is the name of the only entity in the database This entity represents the sensor readings that are received by base station 1 The attribute nodeID is the node address or identifier the default value is Q The attribute direction is the wind direction reported by the sensor on the default format the units are degrees The attribute speed is the wind speed reported by the sensor on the default format the units are m s The attribute units is the units of measure for wind speed on the default format the units are m s represented with a letter M in the units attribute The attribute status is an operation code that must be 00 to indicate correct operation All these mentioned att
35. ributes are received from the sensor for each reading The next two attributes time and UTCoffset are calculated on the server before sending the information to the database The attribute dateTime is a timestamp MySQL type that displays date and time values in a YYYY MM DD HH MM SS format Microseconds cannot be stored into a column of any temporal data type However milliseconds are important when the output rate of the sensor can be up to 4 times per second Thus the attribute ms stores a three digit number that is the milliseconds part of the timestamp The attributes dateTime and ms form the compound attribute time which is the primary key of the database Measurements are always taken at different times so no two measurements can have the same time The attribute UTCoffset is the time offset from Coordinated Universal Time UTC at base station 1 when the measurement was received at the server This attribute is important when calculating latency or comparing timestamps The database was implemented in base station 2 using MySQL relational database man agement system 3 4 Experimental Design To investigate the use of the WebSocket protocol to transmit real time wind sensor data at a rate of 4 Hz we ran tests to compare one way transmission latency of the WebSocket 11 Figure 7 Database design to store WindSonic messages and a server timestamp protocol long polling an
36. s As soon as a client is connected the server sends information to announce if the sensor is in continuous polled or configuration mode and if the sensor readings are being stored in the database Once the client receives these messages the information is displayed to the user and a starting code is sent to the server This code can have three possible values 0 1 or 2 0 indicates that the client started the real time display 1 indicates that the client started the database recording 2 indicates that the client started both the real time display and the database recording When a client opens the WindComm web application the client is forced to start the real time display before starting the database recording This is done to establish the WebSocket connection first so the server can tell the client the current sensor mode and if the database recording has already been started or not Then the user can start the database recording If so the client sends to the server the starting code 1 When the server receives the starting code 1 the server starts the connection with the database If successfull the server will start storing sensor data in the database As soon as the server receives the starting code a full duplex communication has been established Thus the client can send a message to the sensor through the servlet The user interface has an input box once the input text is entered the servlet handles the message with the onMessag
37. send it to the sensor and a message is displayed to the user The sensor responds to the command and the thread sends the response to all currently connected clients The sequence diagram shown in Figure 10 describes the methods and the messages sent between a client and the servlet to start a WebSocket communication with a starting code value equal to 0 and change the sensor from continuous to configuration mode The WindSonic does not report a value for wind direction when the speed value is be low 0 05 m s To handle this the WindComm web application saves the latest nonempty reported value for wind direction This value is used when an empty direction value is re ported The most recent nonempty value for wind direction is stored in the database with a negative symbol to indicate a fake value given that the wind speed is below 0 05 m s If there has been no reported direction value since the application started i e all wind speeds are less than 0 05 m s since the application started then WindComm uses the value zero for missing wind directions These measurements are not real they indicate missing wind direction values since the application started In these cases if the database recording is on the database records the zero value for this measurements If the user wants to stop the real time display or the database recording the client sends a stop code to the server This code can have three possible values 0 1 or 2 The value 0 indica
38. server and servlet container Application server developed as a free and open source project as part of the Eclipse Foundation 6 Jetty is a server that implements the WebSocket API developed and being standardized by the W3C 7 As shown in Figure 4 Jetty is the union between three components connectors handlers and a thread pool Connector SLConnector ThreadPool HandlerCollection ContextHandler ServietHandier ContextHandlerCollection SessionHandler SecurityHandler DefaultHandler Figure 5 Jetty s detailed components and classes extracted from 1211 Connectors accept HTTP connections Handlers service requests from the connectors and produce responses The thread pool is simply the set of threads that do connectors and handlers work 3 2 1 Web Applications A web application can be configured in Jetty with sessions security listeners filters and servlets via a web xml file used as a descriptor This file is a WebbAppContext which is a derivation of a ContextHandler A ContextHandler is a handler that groups other handlers below a particular URL A WebAppContext is a convenience class that assists the construction and configuration of other handlers to achieve a standard web application configuration Figure 5 shows the relation between the classes involved 3 2 2 Implementation of the WebSocket API The WebSockets protocol has two parts The first one is called the handshake It consists in
39. shown in Figure 12 the graphic has two y axes The left y axis shows the scale for wind speed values reported in m s The right y axis shows the scale for wind direction values reported in degrees The graph plots up to 200 wind speed and direction values The most recent values received from the server are plotted at the right end of the graphic Once the client has received 200 measurements the graph behaves as a queue When the wind speed is below 0 05 m s the latest nonempty wind direction value is used in the graph 18 Speed m s Direction deg Figure 12 Two dimensional graphic showing the last 71 wind speed and direction values received 6 BaseComm Web Application BaseComm is the web application that runs in base station 2 This application uses HTTP to receive requests from clients to query the database that runs locally The BaseComm web application was developed following Jetty specifications Figure 13 shows Jetty s components class diagram and the BaseComm web application file structure The Java class BaseCommServlet is the servlet that handles HTTP requests and re sponses When the servlet is initialized connection is established with the database The user submits requests thorugh an HTML form the servlet receives the user s input and builds a query that runs in the database The client reads the response and displays the contents in a table 6 1 BaseComm User Interface A query result with negative v
40. subsets of data that can also be converted into graphics and exported for future use The user can query the database through a user friendly interface and obtain fast responses WindComm and BaseComm support multiple clients However WindComm only sup ports one WindSonic connected to the serial port of the base station 1 computer The repercussions of the actions of one client i e sending commands to the sensor changing measurement mode starting or stopping the database recording will impact the rest of the clients connected and the application will display the changes to all the users currently 21 connected WindComm and BaseComm are complementary but they can run separately Wind Comm can operate without BaseComm However if the MySQL daemon is not running in the base station 2 the user will not be able to save in the remote database the data that is being displayed BaseComm can also operate without WindComm but if there has been no data inserted in the database previously through WindComm there will not be any data available 8 Conclusions We have investigated the use of the WebSocket protocol as an improvement on the latency of the HTTP polling technique for low volume real time data communication on the internet In high traffic and high network latency conditions we observed that the WebSocket protocol was up to 534 times faster than the HTTP long polling protocol The WebSocket protocol does provide better latency on av
41. tes that the client stopped the real time display 1 indicates that the client stopped the database recording and 2 indicates that the client stopped both the real time display and the database recording 5 1 WindComm User Interface The interface implemented to display sensor data to clients consists in two graphics drawn using the Canvas element from HTML5 and JavaScript These two graphics are continuously being updated at the output rate of the sensor 5 1 1 Compass like Graphic The compass like graphic follows the approach described in the technical report 5 The graphic displays wind direction values of the measurements received from the server Every time a measurement is received it is parsed and the wind direction value is passed as an argument to a function that accesses the Canvas element of the file to display it The compass like interface shows the last 5 values received for wind direction as shown in Figure 11 The radius of the compass is divided into 5 Each segment represents a measurement reported Time increases to the center of the compass which means the most recent measurement is the one touching the compass circumference and the oldest is the one closest to the center of the compass circle With the WindSonic in continuous mode A can be 1 0 5 or 0 25 seconds that correspond to the 1 2 or 4 measuremets per second output rate A could have other values in polled mode depending on the requests made by the user 16
42. ttpServlet Java class Thus the WindComm servlet class extends javax servlet http HttpServlet class and implements the init and do Get methods Jetty manages the WebSocket implementation through a WebSocketFactory class The implementation of the doGet method should call the method acceptWebSocket from the WebSocketFactory class The acceptWebSocket method belongs to an Acceptor interface and calls another two methods checkOrigin and doWebSocketConnect The method checkOrigin must be implemented to check the origin of the incoming WebSocket handshake request The method doWebSocketConnect is called when an upgrade request is received in the server If all the conditions are met the doWebSocketConnect method must be implemented to return a WebSocket object Once the WebSocket object is returned to the server the method upgrade gets called to upgrade the connection by sending the correct message to the client This message corresponds to the server handshake and must have the 101 status code and a Sec WebSocket Accept key The WindComm servlet class contains a the WindCommWebSocket class that imple ments the class org eclipse jetty websocket WebSocket Thus the WindCommWebSocket class implements the methods that handle the socket connection such as onOpen onMes sage onClose and onError Once the upgrade response has been sent to the client the method onOpen gets called On the other side the client starts the
43. ty is installed under JETTY_HOME and you have root access to MySQL A 4 1 Installing the BaseComm Web Application 1 Select a computer to be base station 2 2 Open the main project directory and go to Code JettyFolders and copy the folder BaseComm 3 Make sure Jetty is not running and paste the folder into JETTY_HOME webapps 4 Open the main project directory and go to Code NetbeansFolders BaseComm src basecomm open the file BaseCommServlet java and change the ip address part of the variable connectionURL in line 153 with the ip address where you are installing BaseComm web application and database Compile the new file and place the new BaseComm Servlet class under JETTY_HOME webapps WindComm WEB INF classes windcomm to replace the older BaseCommServlet class 28 5 Open a terminal as root and start the mysql daemon service with the following com mand service mysqld start 6 Log into MySQL with root privileges Create a database named BaseComm and add the following table CREATE TABLE Measurement nodeaddress CHAR 1 not null direction SMALLINT not null speed DECIMAL 5 2 not null units CHAR 1 not null status VARCHAR 2 not null datetime DATETIME ms SMALLINT utcoffset DOUBLE 2 1 PRIMARY KEY datetime ms yes 7 Create the following users with the following passwords username basecomm password basecommaccess username windcomm password windcommaccess 8 Make sure yo are using the BaseComm data

Download Pdf Manuals

image

Related Search

Related Contents

Fixapart BC109C-MBR  solido 5 e-35 - Site interministériel sur l`assainissement non collectif  NEC Express5800/120Li User's Guide  SEO Scripts User Manual  DF-20206ZD7  取扱説明書 - 三和製作所  Bimar S598.EU space heater  Integral 32GB DDR3 1066MHz  SERVICE MANUAL - Wiki Karat  HD-1 Drum Tutor Manual F  

Copyright © All rights reserved.
Failed to retrieve file