📄 tinydb.tex
字号:
\noindent{\tt \hspace{.5in}SELECT\index{Select} roomno, AVG(light), AVG(volume) \\\hspace*{.5in}FROM\index{From} sensors\index{sensor} \\\hspace*{.5in}GROUP BY\index{Group By}\index{group} roomno \\\hspace*{.5in}HAVING\index{Having} AVG(light) > $l$ AND AVG(volume) > $v$ \\\hspace*{.5in}EPOCH DURATION\index{Epoch Duration} 5min}\noindent TinyDB\index{TinyDB} translates this query into an efficientexecution plan\index{query plan} whichdelivers the set of occupied rooms every 5 minutes\index{epoch}. Mary simply inputs this queryinto a GUI\index{GUI} -- she writes no C\index{C} code and is freed from concerns about how to install her code, how to propagate results acrossmultiple network hops\index{hop}\index{multi-hop} to the root\index{root} of the network, how to power down sensors\index{sensor} during the time when they are not collecting and reporting data, and many otherdifficulties associated with sensor-network\index{sensor network} programming.We discuss the inner workings of TinyDB\index{TinyDB} on such queries inSections~\ref{sec:devel} and~\ref{sec:inside} below. In the remainder of this section, wepresent a high-level overview of the components\index{component} of TinyDB\index{TinyDB}. The systemcan be broadly classified into two subsystems:\begin{enumerate}\item \underline{Sensor Network\index{sensor network} Software:} This is the heart of TinyDB\index{TinyDB}, although most users ofthe system should never have to modify this code. It runs on eachmote\index{mote} in the network, and consists of several major pieces:\begin{itemize}\item {\it Sensor\index{sensor} Catalog\index{catalog} and Schema\index{schema} Manager}: The catalog\index{catalog} is responsible for tracking theset of {\it attributes\index{attribute}}, or types of readings(e.g.\ light, sound, voltage) andproperties (e.g.\ network parent\index{parent}, node\index{node} ID\index{ID}) availableon each sensor\index{sensor}. In general, this list is not identical for each sensor\index{sensor}: networks may consistof heterogeneous collections of devices, and may be able to reportdifferent properties. (SeeSection~\ref{sec:catalog} for details.)\item {\it Query Processor\index{query processor}}: The maincomponent\index{component} of TinyDB\index{TinyDB} consists of a smallquery processor\index{query processor}. The queryprocessor\index{query processor} uses the catalog\index{catalog} thefetch the values of local attributes\index{attribute}, receivessensor\index{sensor} readings from neighboring\index{neighbor}nodes\index{node} over the radio, combines andaggregates\index{aggregate} these values together,filters\index{filter} out undesired data, and outputs values toparent\index{parent}s. (See Section~\ref{sec:qp} for details.)\item {\it Memory Manager}: TinyDB\index{TinyDB} extends TinyOS\index{TinyOS} with a small, handle-based\index{handle} dynamic memory manager. (See Section~\ref{sec:tinyalloc} for details.)\item {\it Network Topology\index{topology} Manager}: TinyDB\index{TinyDB} manages the connectivity of motes\index{mote} in the network, to efficiently route\index{routing} data and query sub-results through the network. (See Section~\ref{sec:tinydbnetwork} for details.)\end{itemize}\item \underline{Java\index{Java}-based Client\index{client} Interface:}A network of TinyDB\index{TinyDB} motes\index{mote} is accessed from a connected PC through the{\em TinyDB\index{TinyDB} client\index{client} interface}, which consistsof a set of Java\index{Java} classes and applications. These classes are all stored in the {\tt {\java}/tinyos/tinydb} package in the source tree. The specific classes are described in Section \ref{sec:devel}; majorclasses include:\begin{itemize}\item A network interface class that allows applications to inject queries and listen for results (Section~\ref{sec:tinydbnet}) \item Classes to build and transmit queries (Sections~\ref{sec:tinydbquery}, \ref{sec:tinydbaggop}, \ref{sec:tinydbselop})\item A class to receive and parse query results (Section~\ref{sec:tinydbqueryresult})\item A class to extract information about the attributes\index{attribute} and capabilities of devices (Section~\ref{sec:tinydbcatalog})\item A GUI\index{GUI} to construct queries (Sections~\ref{sec:queryframe}, \ref{sec:queryfield})\item A graph and table GUI\index{GUI} to display individual sensor\index{sensor} results (Sections~\ref{sec:resultframe}, \ref{sec:resultgraph}, \ref{sec:plot})\item A GUI\index{GUI} to visualize dynamic network topologies (Section~\ref{sec:topology})\item An application that uses queries as an interface on top of a network of sensors (Section~\ref{sec:app})\index{sensor}\end{itemize}\end{enumerate}\section{Quick Start: Running Queries with TinyDB\index{TinyDB}} \label{sec:runningqueries}In this section, you will learn how to install TinyDB software, set up a network of TinyDB\index{TinyDB} motes\index{mote}, inject a queryinto the network, and collect the results of the query. \subsection{Installation and Requirements}TinyDB\index{TinyDB} requires a basic TinyOS\index{TinyOS} installation, with a working Java\index{Java}installation (and javax.comm library). %For installation instructions%on TinyOS\index{TinyOS}, see the \htmladdnormallink{TinyOS\index{TinyOS} web%page}{http://webs.cs.berkeley.edu/tos}.It is currently designed to work with the nesC compiler (next generation C-like language for TinyOS) and avr-gcc 3.3 \index{avr-gcc}\index{gcc}. To obtain these tools, download the TinyOS 1.1 release from \htmladdnormallink{http://webs.cs.berkeley.edu/tos}{http://webs.cs.berkeley.edu/tos}Click on the link for your platform (PC Linux or Windows), andfollow the installation instructions.The most recent version of TinyDB is always available from the TinyOS SourceForgerepository;%TinyDB\index{TinyDB} is not currently a part of an official TinyOS\index{TinyOS} release. To obtain%the code, you will need to check out a recent version of TinyOS from CVS; see the\htmladdnormallink{TinyOS\index{TinyOS} CVS Page}{http://sf.net/cvs/?group_id=28656}for instructions on using CVS.In addition to the standard TinyOS\index{TinyOS} distribution, TinyDB includes a number ofadditional files detailed in Appendix~\ref{app:files} of this document. The following table summarizes the software requirements of TinyDB: \par\tiny\begin{tabular}{|l|l|}\hlineRequired Software & Notes \\\hline\hlineavr-gcc \index{avr-gcc}\index{gcc} & Version 3.3 or later \\ Java SDK \index{Java} & Version 1.4 or later \\nesC compiler \index{nesC} & From the TinyOS 1.1 release \\javax.comm tools & Version 1.3 or later, from IBM \\TinyOS & From SourceForge CVS \\\hline\end{tabular}\normalsize\\\noindent To verify that your installation is working properly, do the following:\begin{enumerate}\item Compile\index{compile} and install TinyDB\index{TinyDB} on the mote\index{mote}. To do this, connect the mote\index{mote} tothe programming board\index{programming board}, then type the following:\begin{itemize}\item {\tt cd \docroot/apps/TinyDBApp/}\item {\tt make mica}\item {\tt make mica install}\end{itemize}If this fails, verify that your installation works (see the instructions on the website), and that you have all of the TinyDB\index{TinyDB} files listed above.\item Compile\index{compile} and run the TinyDB\index{TinyDB}Main java\index{Java} classes. To do this, type the following:\begin{itemize}\item {\tt cd {\java}/net/tinyos/tinydb}\item {\tt make}\item {\tt cd {\java}}\item {\tt java net.tinyos.tinydb.TinyDBMain}\end{itemize}You'll need to make sure you have the following jar files in your classpath (they should all be available in {\tt {\java}/jars}):\begin{itemize}\item {\tt JLex.jar}\item {\tt cup.jar}\item {\tt plot.jar}\item {\tt xercesImpl.jar}\item {\tt xmlParserAPIs.jar}\end{itemize}You must also have the {\tt {\java}} directory in your classpath. If you wish to take advantage of TinyDB's compatibility with the PostgreSQL\index{PostgreSQL} database system, you'll need to install and configure Postgres (see Section \ref{postgres}) and include the {\tt pgjdbc2.jar} file in your classpath.Your {\tt CLASSPATH} should now look something like this:{\tt.:{\it /path/to/java}/jre/lib/rt.jar:{\it /path/to/java}/lib/dt.jar:\\{\it /path/to/java/}lib/tools.jar:/opt/IBMJava2-13/jre/lib/ext/comm.jar:\\{\java}/jars/plot.jar:{\java}/jars/cup.jar:\\{\java}/jars/xercesImpl.jar:{\java}/jars/xmlParserAPIs.jar:\\{\java}/jars/JLex.jar:{\java}}If you installed TinyOS and TinyDBfrom the TinyOS 1.1 RPMS, your classpath should have been automatically configured to include thesefiles (as well as a number of files, which should not be a problem.)\end{enumerate}\noindent You may see warnings about ``deprecated classes'' when {\ttjavac}\index{javac} runs. These are OK, and you can ignore them. After runningthe java\index{Java} command, you should see the TinyDB\index{TinyDB} controlpanel and query interface appear.Once you have a working installation of these files, continue on to the next sectionto learn how to run queries with TinyDB\index{TinyDB}.\subsection{Setting up a Network of TinyDB\index{TinyDB} motes\index{mote}}The first step is to program a numberof motes\index{mote} with the TinyDB\index{TinyDB} software. Each of these motes\index{mote} must have a unique ID\index{ID}; recall that,in TinyOS\index{TinyOS}, you can set the ID of a mote\index{mote} when running {\tt make install} by appending {\tt .node\index{node}id}-- for example, to program a TinyDB\index{TinyDB} mote\index{mote} at ID 2, you would type:\begin{itemize}\item {\tt cd \docroot/apps/TinyDBApp/}\item {\tt make mica install.2}\end{itemize}\noindent To run TinyDB\index{TinyDB}, you will need at least twomotes\index{mote}: one to act as the basestationmote\index{basestation}, and one or more to distribute and run queriesover. You may want to place a sticker on your chosen basestationmote, since you will need to identify it visually. Allmotes\index{mote}, including the basestation\index{basestation}, runthe same {\tt TinyDBApp} application, however, {\it thebasestation\index{basestation} mote\index{mote} must be set to ID\index{ID} 0.}After programming your motes\index{mote}, connect the programmingboard\index{programming board} to your computer via the serialport\index{serial}, and place the basestation\index{basestation} mote\index{mote} in the programmingboard\index{programming board}. Turn on all of the motes\index{mote}.Figure \ref{fig:setup} illustrates the basic setup of motes and PC. \begin{figure}[h]\centering\leavevmode\includegraphics[width=3in]{setup}\caption{Two TinyDB motes set up to run a query.}\label{fig:setup}\end{figure}\subsection{Running the TinyDB\index{TinyDB}Main GUI\index{GUI}}\label{sec:GUI}The TinyDB\index{TinyDB}Main Java\index{Java} application provides a graphical interface for distributing queries over motes\index{mote} and collecting data from them. To run this application, type:\begin{itemize}\item {\tt cd {\java}/net/tinyos/tinydb}\item {\tt make}\item {\tt cd {\java}}\item {\tt java net.tinyos.tinydb.TinyDBMain}\end{itemize}Two windows should appear; one, the {\it command}\index{command} window (Figure\ref{fig:command}), allows you to send a variety of control commandsto the motes\index{mote}. The other, the {\it query} window (Figure\ref{fig:query}), allows you to build and send queries into thenetwork. We will be focusing on the operation of the query window inthe next section; the command window is fairly self-explanatory.The query window contains a {\bf Display Topology} button to show thenetwork topology. This button actually generates a particular querythat is executed by the motes, with results displayed in a specialvisualization. It is a good idea to display you network topology andmake sure that all your motes are alive and communicating.Once you see that your network of motes is operational, you canproceed to constructing queries. \vspace{.1in}\renewcommand{\baselinestretch}{1.0}\rm\fbox{\parbox{.9\columnwidth}{{\bf TIP:} If you have difficulty sending queriesinto the network, verify that the {\tt comm-string}in {\tt \java/tinydb.conf} has been set correctly;see Section \ref{sec:configfile} for more information.A common problem is the wrong setting of the UART baud rate.The correct baud rates are 19200 for mica and mica2dot,57600 for mica2.}}\renewcommand{\baselinestretch}{1.2}\rm\begin{figure}\begin{minipage}{4in}\begin{center}\leavevmode{\includegraphics[width=3in]{querywin}}\end{center}\caption{Query Window}\label{fig:query}\end{minipage}\hspace{.5in}\begin{minipage}{2in}\begin{center}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -