Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Install the feature “Wrapper Feature” that includes additional libraries to access sensor data from different devices and protocols. After that we can create a new Odysseus Project by issuing the “New” command under the “File” entry or by just pressing “CTRL-N”. After creating a new project we create a new Odysseus Script. A script includes the data source definition and the processing query for our data source. Our first script will be written in the CQL language, so select CQL Basic as a template during the Odysseus Script dialog. The template already includes three lines defining our parser, the transformation configuration, and a “RUNQUERY” command:

 

Code Block
languagesql
linenumberstrue
#PARSER CQL 
#TRANSCFG 
Standard 
#RUNQUERY

 

The CQL language is based on the SQL language used in databases like MySQL or PostgreSQL, so it is the perfect starting point when you worked with databases before. Later, we will also take a look at the PQL query language for more advanced stream processing. The transformation configuration sets different parameter for the used data model and metadata. However, the standard configuration should fit our needs right now. The last line tells the parser that we want to run the next lines as a query. Additional Odysseus Script commands can be found here.

...

Now that we have a source, we can perform our processing on that source. To do so, we start a new processing block and write down our processing query. For the sake of simplicity, our first query should just select both attributes so we can use them for, e.g., visualization.

 

Code Block
languagesql
linenumberstrue
#RUNQUERY 
SELECT * FROM Arduino;

...

OK, let’s do some real processing now. To do so, we change our query a little bit to continuously produce the average of the temperature of the last hour. This is done using the AVG keyword and the definition of the window we want to calculate the average on. In this case we use a sliding time window with a size of one hour and an advance of one millisecond:

 

Code Block
languagesql
linenumberstrue
#RUNQUERY 
SELECT AVG(temperature) FROM Arduino [SIZE 1 HOUR ADVANCE 1 TIME];

...

So fare, we have seen how Odysseus can be used to process measurements from an Arduino device in just a few lines of CQL code. Now we want to make some more advance processing including a pattern matching on the data and the transmission of processing results. To do so, we first have to install the “CEP and Pattern” feature using the “Install new feature” entry from the menu. This feature includes additional operator to perform so-called complex event processing. To use the new operators we will switch the query language to PQL. The PQL language allows connecting operators directly instead of describing a query in a declarative language like CQL. Also, we will now transfer processing results the same way we received the data from our Arduino. First, we create a new Odysseus Script like before, but select the PQL Basic. Thus, our first three lines change to:

 

Code Block
languagesql
linenumberstrue
#PARSER PQL 
#TRANSCFG Standard 
#RUNQUERY

...

Next we define our source as before, but now in PQL using the ACCESS operator:

 

Code Block
languagejs
linenumberstrue
Arduino := ACCESS({ SOURCE = 'Arduino', 
TRANSPORT = 'RS232', 
DATAHANDLER = 'Tuple', 
WRAPPER = 'GenericPush', 
PROTOCOL = 'CSV', 
SCHEMA = [['temperature', 'DOUBLE'], ['humidity', 'DOUBLE']], 
OPTIONS = [['port', '/dev/ttyACM3'], ['baud', '9600']] })

...

You see that there is no big difference in the definition of a source. Now we come to our processing query. This time, we will use the SASE operator to detect a pattern in the stream. The pattern itself should match a situation when the temperature drops more than 20% compared to some value during the last 60 seconds, i.e., someone opened a window in the room.

 

Code Block
languagejs
linenumberstrue
match = SASE({schema=[['temperature','Double']], 
type='Result', 
query='PATTERN SEQ(Arduino+ a[]) WHERE skip_till_any_match(a[]){ 
  a[1].temperature >= 0.8 * a[a.LEN].temperature 
 } WITHIN 60 seconds RETURN a[a.LEN].temperature' 
}, Arduino)

...