GPS Event [12] – Coral8

Let’s see what does it take to send a message to Coral8. The latest available version on the website is 5.5 and I have 5.1 installed, so it is time for an upgrade.

The upgrade (installation) went smooth. There is a good "getting started guide" available too.  Coral8 Server is the engine of the application and Coral8 Studio is a developer’s GUI. I have installed both on a Windows Server 2003 for Small Business — 2.53GHz, 2.5GB RAM — which also runs a developer version of MS SQL Server 2005. The average CPU usage seems to be below 5% when idle, not bad.

Coral8 has quite a few adapters included, but none of them seems to fit my GPS example; I will have to find another way. There is a SDK for several languages — including Python — so this seems a way to go. Now I can sketch a road map:

  1. Create a simple Coral8 project;
  2. Study the Python SDK and figure out how to send a message to Coral8;
  3. Test;
  4. If it works, continue with the GPS example.

Step 1 – a simple Coral8 project

Coral8 CCL (Continuous Computation Language) is SQL like, so I have created two streams (think one-row tables) with just two columns: Entity and Val. Imagine a measurement device (Entity) sending a number (Val) each measurement. Streams are connected by a query which copies data from the input to the output.

-- Input
CREATE INPUT STREAM StreamIn
SCHEMA (
    Entity STRING
    ,Val INTEGER
);
 
-- Output
CREATE OUTPUT STREAM StreamOut
SCHEMA (
    Entity STRING
    ,Val INTEGER
);
 
-- Pass Through
INSERT INTO StreamOut
SELECT * FROM StreamIn;

This is how it looks in the Coral8 Flow View.

If I manage to insert data into the input stream, the same data should show up in the output stream.

Step 2 – the Python SDK

The SDK has an example which sends and receives data, and also includes Python multitasking. After some tinkering I have decided to simplify it a bit:

"""
c8_test_1.py
Test sending data to Coral8
"""
import time
from coral8 import Coral8
 
uri = 'ccl://damir5:6789/Stream/Default/'
uri += 'TestPythonInAdapter/StreamIn'
 
col_names = ['Entity','Val']
 
def send_to_c8(j):
    pb = Coral8.Publisher(uri)
    tp = Coral8.Tuple(col_names)  
    tp.setvalue('Entity', 'DS_1')
    tp.setvalue('Val', j)
    pb.write_tuple(tp)
 
if __name__ == '__main__':
    for j in range(10):
        send_to_c8(j)
        time.sleep(0.2)

The program is supposed to send ten numbers (0-9) to Coral8 Server. Note the uri variable, I got that one by inspecting the StreamIn properties and substituting “localhost” with the server name (damir5).

Step 3 – Test

Guess what, it works; just like that. Here is a screen capture of both stream viewers.

Step 4 – Continue

Now I can add service and template modules for Coral8 to my GPS Event example. I still have to figure out what to do with events inside the server. Maybe I can use it to write events to a database and send notifications when the GPS starts loosing satellite signals — we’ll see.

To be continued.

Disclosure:

Everything I write about Coral8 is my own opinion and experience.
There is no contract nor any kind of active business relationship between Coral8 and me (Damir Systems Inc).

GPS Event [11] – Blogger

Blogger is probably the most popular blogging platform around, well depends on who you talk to. Hosted and owned by Google, it takes just a few minutes to get going — if you happen to have a Google email it will take the same login and the password. I have created a new blog for this example.

Google provides API libraries for their services, so it was fairly easy to get going. As you can see, the simple and clean layout is almost perfect for this type of reporting. The template is the same as for the WordPress example, so I only had to add service and authorization modules:

To select the service in the main gps_event.py module:

# select service: none, aws, rc, tweet, email, gtalk, coral8, wp, blog
use_service = 'blog'
  
# define sampling delay in seconds
sample_delay = 25
  
# map templates to services
format_list ={'none':'json', 'aws':'xml', 'rc': 'rcxml',
              'tweet':'tweet', 'email':'email', 'coral8':'coral8',
              'gtalk':'gtalk','wp':'wp', 'blog':'wp'}

The format_list dictionary contains ‘service’:’template’ pairs; note how the ‘wp’ and the ‘blog’ services are both mapped to the ‘wp’ template.

GPS Event [10] – WordPress

This small series of moving event around, would not be complete without WordPress as a event-notification target. WordPress is a neat content-management system, ideal for any type of periodic reports.

The template accepts html tags, so I have formatted  event data as a table and added an icon.

"""
gps_template_wp.py
Wordpress template for GPS event
"""
 
# 0=empty, 1=ok, 2=info, 3=question, 4=warning, 5=error
img_id = 2 
 
def template(pretty = False):
    """
FieldValue
Entity$entity_here$
Type$type_here$
Time$time_stamp_here$
ID$id_here$
Latitude$latitude_here$
Longitude$longitude_here$
Altitude$altitude_here$
Speed$speed_here$
Course$course_here$
Valid$valid_here$

 

""" return compress_template(template.__doc__) def compress_template(s): """ Compress template """ rli = {'{ ':'{', ' }':'}', ', "':',"', '> <':'><'} st = ' '.join(s.split()) for (k, v) in rli.items(): st = st.replace(k, v) st = st.replace('$image_id_here$', str(img_id)) return st if __name__ == "__main__": print template(True)

The service and the authorization modules:

To select the service in the main gps_event.py module:

# select service: none, aws, rc, tweet, email, gtalk, coral8, wp
use_service = 'wp'
 
# define sampling delay in seconds
sample_delay = 60

The previous post is the result .