Phase 1 Java Subsystem documentation - COMMON-Sense Net ...

bossprettyingΔιαχείριση Δεδομένων

28 Νοε 2012 (πριν από 4 χρόνια και 7 μήνες)

408 εμφανίσεις



16
-
03
-
2013

9
-
1







COMMON
-
Sense
Net
rev. 1

Java Subsystem Design


Jacques Panchard (EPFL)




October 31st
, 2004


16
-
03
-
2013

9
-
2



Web server

DB

Java
Application

Base station

commands

Data

node

node

node

node

sensor

sensor

Wireless link

statistics


1

The COMMON Sense
Network architecture

The COMMON Sense
wireless
net
work

is built as a tree.

Every mote has
one single

parent, and
communicates with it. The
root of the tree is the base station, the only module which is directly linked to
the java application. Each mote collects its sensors’ informations and sends them towards the root. They
don’t exchange data between them. The packets are routed from the ori
ginating node to its parent in a
multihop fashion up to the sink (base station).


For the time being, the multihop routing protocol used is the default MultihopRouter defined in
/tos/lib/Route. The use of MintRoute should be considered.


The Java applicati
on receives data from the motes network and puts them in a database. A web server can
access these data and display them. From the web interface, commands can be sent to the motes.



































16
-
03
-
2013

9
-
3


2

Software
System design

This design is ins
pired by the TASK application design, and by the sensorscope application developed at
EPFL in the context of MICS
(
in collaboration with COMMON
-
Sense Net
)

in August
-
October 2004

[Schmid 2004]
.




Figure
1

Application Block Diagram



16
-
03
-
2013

9
-
4


3

Java Application Server design: The generaldatalogger package

NB: The SerialForwarder, which is depicted in Figure 1, is out of the scope of this document, since it is
provided as a standard library in tinyOS.


The complete package API can be consulted on
-
line at:
http://commonsense.epfl.ch/Admin/generaldatalogger.htm

If you don’t have access to this (private) site, please contact jacques.panchard@epfl.ch


3.1

Overview


The main program on the server is GeneralDataLog
ger, which acts as a central dispatcher and starts the
different subsystems. The software components are listed in
bold

hereafter, and their APIs are described:

1.

IO

SubSystem

(IOS)
: GeneraldataLogger creates a
MoteIF

(library class) for the connection with
the Serial Forwarder, a
CommandServer

to handle the commands received from GUI clients

(typically web clients)

and an
ICMonNetwork

to communica
te with the sensor network via the

MoteIF.

2.

Query Subsystem

(QS)

for access to the database: creates a
DBLogger
.

3.

N
etwork
M
anagement
S
ubsystem (NMS)
:
ICMonQuery
, which handles the generation and
reception of the commands sent to the motes (either individually or network
-
wide)


3.2

Configuration file (/projects/ICMon/etc/icmon.conf)

The configuration file contains both info
rmation relevant for the Web
-
based GUI (
images locations,
network boundaries coordinates etc.
)

and information relevant for accessing the databse. In this
subsection, we focus on the latter, since it is used by the java application when setting up the Quer
y
subsystem.


The following list reproduces exactly the structure of the configuration file. The field

names

are in bold,
and
their value is in normal font.


For more information about the database itself, see the document entitled
COMMON
-
Sense Net Databas
e

%format param:value

%postgres server settings

postgres
-
user
:icmon


% postgresql username (used at database creation, see Panchard2005)

postgres
-
passwd
:donttell

% postrgesql username

postgres
-
db
:icmondb


% database name (see Panchard2005)

postgres
-
host
:1
28.178.156.102


% host on which the posgresql database isrunning

java
-
host
:128.178.156.102


% host on which the java subsystem is running

table
-
log
-
queries
:icmon_log_queries

% table used to log queries sent by the NMS

table
-
mote
-
info
:icmon_mote_info


% tab
le used to store the individual nodes information

table
-
neighbortable
:icmon_neighbortable

% neighbour table entries of every node

table
-
statisticstable
:icmon_stattable


% statistics for every node

table
-
routing
-
parent
:icmon_routing_parent

% current network

topology (and history)

table
-
log
-
cmd
:icmon_log_cmd_msg


%

used to store the commands sent over time by the NMS


(…)




16
-
03
-
2013

9
-
5



3.3

General
DataLogger

GeneralDataLogger is invoked with 2 parameters:

1.

The network group ID (0x80)
, which is not used at the moment.

2.

The name
of the DB table used to store the sensor data information.


The GeneralDataLogger
opens

the configuration file
:
Config.init("/projects/ICMon/etc/icmon.conf")
;


Then it starts a DBLogger, a MoteIF to interface with the
sensor nodes
, a CommandServer to liste
n to the
requests from the clients (usually web
-
based clients),
and ICMonNetwork to handle incoming and
outgoing messages to the sensor nodes,
and a ICMonQuery

to generate the relevant queries from the
commands received.


Finally, the DBLogger is added as
a ResultListener to the ICMonNetwork so that

it
can receive
the
messages

intended to be logged to the database.

3.4

IO Subsystem

This subsystem is connected to the Serial Forwarder via a
MoteIF
.

ICMonNetwork

handles the reception of the messages from the motes

and the emission

of the commands
from the NMS. It u
ses query results to dispatch the results to the DBLogger, and to send to the
CommandConnection objects the results of commands that need to be displayed on the corresponding
terminal. The time stamping o
f the incoming message is done at this point.

3.4.1

ICMonNetwork

This class has two roles:

1.

Listens to the serial forwarder and dispatches packets.

2.

Sends
to the motes
over the UART the
queries

resulting from the commands

formatted by
CommandConnection.


MessageRe
ceived(int addr, Message m)
: called when a message is received from the Serial Forwarder.
Typically formats a query result and
introduces

in the database.
This can be done in two ways:

1.

For data messages, a QueryResult object is created, then it is added to

the DBLogger, by adding it
to a ResultListener list (DBLogger implements a ResultListener)

2.

For SpecificMsg messages, a MoteInfo object is created, which handles directly the creation or
update of DB tables

by using

its own DBLogger.

SendQuery(ICMonQuery q
)
: Used to send a query out

to the motes via MoteIF
.

The query was built by
CommandConnection based on the command received from its client (typically the web application)


3.5

Network Management Subsystem

CommandConnection
: handles the commands sent by a clie
nt to the sensor network. Each
CommandConnection is associated with a different communication socket. It formats the packet
corresponding to a given command and gives it to ICMonNetwork, which sends it to the sensor network
over the UART (through MoteIF).

CommandServer
: It opens a server socket that waits for incoming clients. For each client, it spawns a
new CommandConnection process for a command to be sent to the motes. The CommandConnection
waits until the expected response is received from the sensor n
etwork. The Commandserver is typically


16
-
03
-
2013

9
-
6


invoked by the web interface (createSocket command in the php code) and returns results to the results
where it got them from.


3.5.1

CommandConnection (Thread)

This class s
s created with an ICMonNetwork as parameter on a p
articular socket.

The method

run()

o
pens a BufferedReader to process an input streams of commands (StringTokenizer).
Based on the command, it creates a ICMonQuery that formats the message to be sent. Then, it passes the
query as a parameter to
ICMonNetwork

in oder to send the commands (ICMonNetwork.sendQuery()).

messageReceived(int addr, Message m) : relays back to the web interface the responses of the commands
received from the sensor network.

It doesn’t deal with the DB, since this is done in ICMonNetwor
k.

3.5.2

CommandServer (Thread)

Listens on a server socket for client connections and opens a new socket for every client connection.


3.5.3

ICMonQuery

This class is used to format the message corresponding to a command

(ICMonCmd
Msg

message)


3.6

DataBase subsystem

3.6.1

DBLog
ger

It uses the java.sql primitives to connect to the database and insert, update or delete tables and rows.

MoteInfo
.

It implements a ResultListener, which it uses to retrieves the motes’ data

from ICMonNetwork.

initDBConn()

: Initializes the connection t
o the Database Subsystem

logQuery(ICMonQuery queryToLog)

: Does the setup work for starting to log a query

createTableStmt(ICMonQuery query, String tableName)

: Returns a query string which can create a
table

insertStmt(QueryResult qr, String tableName)

:
returns a query string which can insert a new element
in the DB.



3.6.2

MoteInfo

Using a

DBLogger, it updates

into the database

the information relative to the individual motes and the
network (not the sensor data)

3.6.3

Database


The database is a PostgreSQL.


The l
ogged tables with their parameters are listed below:


--

table to log command messages

create table icmon_log_cmd_msg (


id SERIAL PRIMARY KEY,


seqno INT NOT NULL,


time TIMESTAMP NOT NULL,



16
-
03
-
2013

9
-
7



cmd VARCHAR(255) NOT NULL,


addr INT,


value INT


);

--

tabl
e to store information about motes

create table icmon_mote_info (


nodeid INT PRIMARY KEY,


location_x INT,


location_y INT,


type varchar(30),


location VARCHAR(255),


comment VARCHAR(1000),


lastbatchange TIMESTAMP


);


--

table to store parent statis
tics

CREATE TABLE icmon_routing_parent (


id SERIAL PRIMARY KEY,


time TIMESTAMP NOT NULL,


nodeid INT REFERENCES icmon_mote_info ON DELETE CASCADE ON UPDATE CASCADE,


parent INT NOT NULL,


quality INT DEFAULT
-
1,


depth INT DEFAULT
-
1,


occupancy INT DEFA
ULT
-
1,


);

--

table to store neighbor information



CREATE TABLE icmon_neighbortable (


id SERIAL PRIMARY KEY,


time TIMESTAMP NOT NULL,


nodeid INT REFERENCES icmon_mote_info ON DELETE CASCADE ON UPDATE CASCADE,


neighborid INT NOT NULL,


missed INT NOT
NULL,


received INT NOT NULL,


lastSeqno INT NOT NULL,


hop INT NOT NULL,


receiveEst INT NOT NULL,


sendEst INT NOT NULL

);


The table
used to store the sensor data is created at the first invocation of the java application.

3.7

Queries Subsystem

The DBLogger

logs the results of the queries to the database. It communicates with the IO subsystem and
with the NMS through a Listener.


3.8

Helper Classes

3.8.1

Config.java

Used to load and access general configuration information.

3.8.2

Entry.java

This class is created for accessi
ng the values from the hash table where parameter

and its corresponding
values. Config.java uses this class to perform the operation.



16
-
03
-
2013

9
-
8


3.8.3

QueryResult.java

3.8.4

Table.java (and extensions NeighborTable and StatTable)

This abstract class is a parent for {@link StatTa
ble} and {@link NeighborTable}. It is used to handle the
database objects that correspond to table entries on the individual motes (the table of neighbors for each
mote, and the table of networking statistics)


4

Message Exchange specification

Here are a few

types useful to identify the type of message that is being sent:


enum {


ICMON_TYPE_SENSORREADING = 0,


ICMON_TYPE_ROOTBEACON = 1,


ICMON_TYPE_SETRATE = 2,


ICMON_TYPE_SLEEP = 3,


ICMON_TYPE_WAKEUP = 4,


ICMON_TYPE_SETSENSING = 5,


ICMON_TYPE_GETP
ARENT = 6,


ICMON_TYPE_SETPOWER = 7,


ICMON_TYPE_GETPOWER = 8,


ICMON_TYPE_GETROUTING = 9,


ICMON_TYPE_MANUALROUTEUPDATE = 10,


ICMON_TYPE_GETNEIGHBORTABLE = 11,


ICMON_TYPE_GETSTATTABLE = 12,


ICMON_TYPE_SETLPLSTATUS = 13,


ICMON_TYPE_GETLPLSTATUS

= 14,


ICMON_TYPE_SETLOSSYPREAMBLEDETECTION = 15,


ICMON_TYPE_GETLOSSYPREAMBLEDETECTION = 16,


ICMON_TYPE_SETPACKETCOMBINING = 17,


ICMON_TYPE_GETPACKETCOMBINING = 18,


ICMON_TYPE_SETSENSORFLAGS = 19,


ICMON_TYPE_GETSENSORFLAGS = 20

};


The sensor f
lags are used to discriminate between different types of data messages
(CSN_TYPE_SENSORREADING in previous enum). Since they can overlap, we define them as bit
arrays rather than incrementing integers. It is to be noted that to each type of data (or sensor
) corresponds
one fixed ADC port (this is used to detect what data to send during the set
-
up phase, when the node
detects which port is active and which is not). The rule is that the SENSOR_BIT defined hereafter is 2 at
the power ADC_PORT_NUMBER:


enum {



SENSOR_VOLTAGE = 1,


SENSOR_HUMIDITY = 2,


SENSOR_TEMP = 4,


SENSOR_LIGHT = 8,


SENSOR_PRESSURE = 16,


SENSOR_MOIST1=32,


SENSOR_MOIST2=64
};



The data message structure is as follows:


typedef struct ICMonMsg {


uint8_t type;



16
-
03
-
2013

9
-
9



uint8
_t sensorfl
ags;


uint16_t temp
;


uint16_t humid1
;


uint16_t humid2
;


uint16_t moist1
;


uint16_t moist2
;


uint16_t rain
;


uint16_t voltage;

} __attribute__ ((packed)) ICMonMsg;


The command messages (from the base station) have the following structure:


typedef

struct ICMonCmdMsg {


uint8_t type;


uint16_t addr;


uint32_t newvalue;

} __attribute__ ((packed)) ICMonCmdMsg;


The alarm message (to the base station) has the following stgructure:


typedef struct CSNAlarmMsg {


uint16_t type;


uint16_t addr;


uin
t32_t value;

} __attribute__ ((packed)) CSNAlarmMsg;


Finally, we define a health
-
status message used to update the server on the mote’s condition:

typedef struct CSNHealthStatusMsg {


uint16_t type;


uint16_t addr;


uint16_t parentA
ddr;


uint32_t volt
age
;


uint32_t parentRSSI
;

} __attribute__ ((packed)) CSNHealthStatusMsg;



5

Bibliography



Rao 2004

PR Seshagiri Rao, Madhav Gadgil, Ramakrishnappa, M Gangadhar,

Report of user
requirement survey
, CES, CAOS, IISc. BANGALORE, 2004

Schmid 2004

Thomas Schmid
,
Sensorscope
, MICS Summer Internship, EPFL, 2004,
http://sensorscope.epfl.ch

Panchard 2004

Jacques Panchard,
COMMON
-
Sense Net System Requirements and High
-
Level Design
,

EPFL

Technical Report
, 2004

Panchard 2005

Jacques Panchard,
COMMON
-
Sense Net
Database,

EPFL

Technical Report, 2004


CEDT2004

CEDT
, COMMON
-
Sense Net, Working draft for MICA2 motes (Phase 1)
, Technical
Report,
November 17, 2004