Top Downloads News Highlights

Join us for the free Webinar What Makes A Database System 'In-Memory'? on Thursday, February 16th!

Perst embedded DBMS on Windows Phone 7 gains synchronization with Microsoft SQL Server. Get details.

McObject's new eXtremeDB version 4.5 embedded database adds speed, scalability and developer tools. Read the press release.

NSE.IT slashes latency in algorithmic trading with the eXtremeDB In-Memory Database System (IMDS)! Learn more.

Printable Version

Automatic Weather Stations (AWS) Explorer.

Download the demonstration now!

Introduction

This sample application  demonstrates a communication session between the eXtremeDB database runtime running in the context of an embedded Web Server and a Windows-based client running in the context of a web browser (AWS Explorer). The eXtremeDB database keeps the data collected by the automatic weather station (AWS), and communicates its XML representation  to the Windows client via SOAP.  Multiple AWS servers can be monitored from the AWS Explorer. Each AWS is assumed to operate independently. The following diagram shows the essential parts of the application's architecture:

                                          
The Database

Data collected by each weather station is stored in the database in the eXtremeDB native format (optimized for in-memory storage). The database resides in main memory of the AWS and is controlled by the eXtremeDB runtime. There are two types of data stored in the database: weather-related data acquired by weather sensors, such as wind direction and speed, pressure, humidity, etc.; and diagnostics data collected during the AWS self-diagnostic tests. Self-diagnostics are run periodically and verify the well-being of the sensors and the battery power. The following eXtremeDB database schema is used to describe the AWS database:

/*
* meteo.mco
*/
#define uint8 unsigned<8>
#define uint4 unsigned<4>
#define uint2 unsigned<2>
#define uint1 unsigned<1>

declare database meteo;    /* database declaration */

/* Date and time */
struct Datetime {
    uint2 year;
    uint2 month;
    uint2 day;
    uint2 hour;
    uint2 minute;
    uint2 sec;
};


/*
* Class Diag keeps self-diagnostics event objects, such as  a temperature gauge status,
* current battery status
*/
class Diag {

    Datetime dt;    /* date& time of the self-test */

    /* sensor diagnostics */
    uint1 sensor1;    /* 0 to 1 */
    uint1 sensor2;    /* 0 - ok, 1 not-ok */
    uint2 charge;     /* current charge */
    /* objects in this class are ordered by the test date/time */
    tree <dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.sec> IAlarms; 
};

struct Position {
    uint2 degree;
    uint2 min;
    uint2 sec;
};

/* Class Config is used to store current configuration for the AWS. Note that some
*  of these parameters are changeable, and some are not
* /
class Config
{
    string name;              /* station name */
    Position latitude;        /* station location */
    Position longitude;
    uint2 altitude;             /* meters over sea-level */

    uint2 rate;                 /* sampling rate - how often the samples are taken */
    uint2 selfdiag;            /* self-diagnistics frequency */
    uint2 min_charge;      /*minimum battery charge in percents */

    list;
};

/* Wind parameters */
struct Wind {
    char<3> direction;               /* NE,E,SE, NW,W,SW, NNE */
    uint2 speed;                        /* km/hour */ 
};

/* Class Data is used to store weather measurements */
class Data {
    Datetime dt;

    uint2 temp;                        /* temperature */    
    Wind wind;                        /* wind */
    float pres;                         /* pressure */
    float ptrend;                     /* pressure trend */
    uint2 humid;                     /* humidity */
    uint2 dew;                        /* dew point */
    float rf;                             /* rainfall */

    /* there are two indexes defined for the class:
     * ITemp provides sorted retrieval by the temperature values
     * Idt provides sorted retrieval of measurements by date/time 
     */
    tree <temp> Itemp;
    tree <dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.sec> Idt;
};

When the embedded web server is started, it starts two threads: the updateData_thread()updateDiag_thread() that periodically "checks" on sensors and creates Diag objects. The implementation of these functions are in the file dbupdate.c. There are a number of queries that could be executed against the database, initiated by the client's request:
that "reads" sensor values and writes new Data objects and also performs some cleanup, erasing older data from the database, and the

GetCurrentConfig(); Reads the current Config object and returns an XML representation of it.
GetWeather(); Looks up the Data object based on the the date and time passed in. The closest Data object is retrieved as an XML document and returned to the server. The server puts a SOAP envelop around the XML and sends the the document to the client. Internally, this and all other Get...() functions call classname_xml_get() to obtain the XML representation of the database object.
GetMinWeather(); Looks up the Data object with the minimum "temperature" value.
GetMaxWeather(); Looks up the Data object with the maximum "temperature" value.
GetDiagnostics(); Looks up the Diag object based on the date / time.
SetConfig(); This function accepts an XML representation of the Config object, and updates the current Config object with the data extracted from it. The XML is sent in a SOAP package from the client application, the Web Server strips the SOAP envelop before passing the XML to SetConfig(). Set Config() simply calls the eXtremeDB runtime function Config_xml_put() to store the data.

    

Installation and how to run this demonstration program

The following files are installed:

/root_installation_directory/host/bin/mcocomp.exe  - eXtremeDB DDL compiler
/root_installation_directory/host/bin/gencontent.exe  - a utility that captures the directory image into a C file.
/root_installation_directory/host/content  - demo web site content
/root_installation_directory/host/gencontent  - source code for the gencontent utility
/root_installation_directory/host/include  - eXtremeDB header files
/root_installation_directory/host/meteo  - this demonstration program source code files
/root_installation_directory/target/bin/mcolib.lib  - eXtremeDB runtime library
/root_installation_directory/target/bin/server.exe  - demo server executable

The server program is currently available for Microsoft Windows 32-bit platforms, Linux and QNX 6.1.x. The only browser that is currently supported is Microsoft Internet Explorer. We have tested this demo with IE version 6, but it should be fine with 5.0 as well. If you are interested in running the server on some other platform, please contact us, we will try to accommodate you. We also will be glad to support different browsers. We are currently looking to supporting Netscape, Mozilla and the QNX Voyager.

To run the server from the console window, change directories to target\bin, then simply type

     server port_number.

The Web Server will start listening for HTTP requests on the specified port. Multiple servers could be run on the same machine. For example, in order to run two server instances, one on port 80 and another on port 82, type:

    server 80
    server 82

If port is not specified, the server will be listening on port 80.

In order to access the website, point your browser to 

    http://localhost:port_number/meteo.html

If the server is running on a remote machine, and for example, the IP address on the remote machine is 192.168.1.103, point the browser to

   http://192.168.1.103/meteo.html

The "Stations" screen lists all connected AWS. By default there is one station connected to the AWS explorer: localhost:80/meteo. Additional stations could be easily connected to the Explorer, just type in the station URL in the "URL" edit box and click the "Add" button. For example, to add a station running on the remote computer with the IP address 192.168.1.103 on port 82, type:

   http://192.168.1.103:82/meteo

The Explorer will try to communicate with the server running on the remote machine, and add the new station to the list of stations on the left-hand side of the screen. Each station status is shown on the right-hand side of the screen. You may push the "Refresh" button and the Explorer will send an XML/ SOAP request to the selected server and obtain the configuration data for the server. It is possible to change some configuration settings:

Sampling rate the rate (in seconds) at which weather measurements are taken
Diagnostics rate the rate (in seconds) at which self-diagnostics are run
Minimum charge is the minimum battery charge (in percents)


After a change to these parameters is made, push the "Save" button. The XML document will be sent to the server and the server will use the eXtremeDB XML interface to write the new settings to the database. 

The "Weather" screen is used to display weather measurements from all connected stations. To read weather updates, set up the time and push the "Request" button. Checking the "Auto" check box will cause the Explorer to request weather updates automatically. Again, each request to the server and each response from the server are in the form of XML documents.

The "Diagnostics" screen allows requesting of the self-diagnostics data from each AWS. Simply set the time and push the "Request" button.

The "Soap" screen displays the last Soap request and last Soap response. The entire session is recorded  and is displayed in the pop-up window activated when the Explorer is started. Session information contains all SOAP requests sent to each AWS server and all SOAP responses for them.