Tuesday, June 24, 2014

(#12) ESP 

And not the whacko stuff JB Rhine wrote about - but Event Stream Processing. From now on, when I type ESP, I mean Event Stream Processing and not Extrasensory Perception.



I've been taking a long, leisurely path to this point - a good home automation system should make inferences. An inference is a conclusion based on data and reasoning.  So let me be direct - a good home automation system should make inferences.

There.


Oh hell, one more time: a good home automation system should make inferences. That's Point #1.

An inference is a conclusion ("some one is home!") based on data ("the garage door opened, then the house door opened and closed -- all within a few minutes.").

Point #2, we've talked about how the rules that drive the conclusion could change over time. So they shouldn't be hard-coded as some sort of Finite State Machine in the application.

Point #3, tools exist that allow you to draw conclusions based on the appearance of data (in my case, specifically, MQTT event message). 

And these tools allow you to express the event sequence easily.  
At run time.

I know, right?
It's almost as cool as when Smuckers put peanut butter and jelly in the same jar!

Esper estas programaro por okazaĵo rivereto prilaborado.
(I slay myself...)  Esper is an open source, Java based, Event Stream Processor.  Event Stream Processing is a subset/superset/cousin/sibling of Complex Event Processing which we introduced earlier.

You can learn more about Esper from their website: http://www.espertech.com/esper/

Pulled right from their homepage:




Drawing Conclusions in 3, no 5, Easy StePs!


For you Emergenetics Greenies, here's the recipe

  1. Have your Home Automation Sensors publish events on the network. I'm using MQTT
  2. Download and install Esper (You can code Java, right?)
  3. Write Java code
    1. You'll need a main() that instantiates and runs the Esper Engine
    2. You'll need a POJO that represents your Events
    3. Write code to subscribe the the MQTT event stream
    4. Write a handler object, that you want triggered when Esper makes an inference
    5. Write the EPL that represents the event sequence you're after
    6. Tell Esper to associate the handler code and the EPL statement
  4. Run
  5. Debug, lather rinse repeat
See? Five steps.


Esper's a cool tool.  And it comes with (as of this blogging) 733 pages of documentation. Esper's the brain child of a genius, and unfortunately, the documentation assumes you're a genius too.

There are few of the obligatory Hello World examples out there.  Esper comes with plenty of examples, but they're source files.  What mere mortals, like you and me, need are pretty simplistic step-by-step examples.

That's what I'll do next. I'll post my code.
Oh, I use NetBeans. So you JetBrains and Eclipse users will just have to suffer along.





No comments :

Post a Comment