The Brain

At the center of the Smarthome2 system is the brain. This is a C++ CORBA server with an embedded SWI Prolog engine. The C++ code implements three CORBA interfaces: x10react, x10send, and agentreact, and when a notification call is made to any of these interfaces, the C++ code spawns a thread to handle the notification and then returns immediatly. The thread then requests a mutex and then calls the Prolog predicate that handles the notification and decides on any action to take.
Currently all calls to the Brain are notifications - the notifier does not expect or wait for any response while the Brain decides what if any action to take. Eventually I'm sure I'll add function that will allow components of the system to ask the Brain questions and expect an answer.
Before I implemented the Brain, all the smarthome servers in the system operated autonomously and their reaction logic was hard coded in the Visual Basic. There was no facility to coordinate the activies across servers. Now the behavior of the system is centrally controlled by the Brain and the smarthome servers are becomming "dummer" and simply provide MS Agent, Video Capture, X10 interface, or 1-wire device facilities to the system.
One of the really nice things about having an Embedded Prolog engine controlling the reaction logic of the system is that the rules are dynamic - not only do I no longer have to recompile anything when I add new rule functionality, I don't even have to restart the Brain itself! The rules can be reloaded on the fly simply by selecting a command from the MS Agent interface.

  • X10react

  • This reactor is notified when the X10 interface detects any X10 activity not sent by the Smarthome system. This could be as a result of motion detectors, pressing buttons on control panels, or X10 signals sent by the HomeBase to announce door activity.

  • X10send

  • This interface is called by all Smarthome system components as well as JSP web pages to send X10 commands to control devices in the house. Having all of these events handled by the Brain allows it to keep track of the state of all X10 controlled devices.

  • AgentReact

  • This interface is called by the Smarthome servers when any events are generated by the Microsoft Agents (such as selecting a menu command.) This interface is also in charge of loading and changing the menu items presented by the MS Agents. When each MS Agent starts up it asks the AgentReact interface to send it any initialization (which it does asynchronously.)

  • Weather

  • The big reason for having a Prolog engine in the first place is its usefulness in interpreting data and decision making. The first area I am applying this is decision making based on the weather inputs (both National Weather Service forecasts as well as conditions measured from the rooftop weather station.) One fun feature of the Smarthome system is the ability to press a control panel button and have Peedy (the MS Agent character) read the weather forecast. I am working on using the Prolog rule base to interpret the foecast and current conditions and provide more of a commentary than a dry word for word reading of the forecast.
    With an interpretation of the weather conditions and forecast the system can be more useful in lots of ways. Peedy can even provide advice to bring an umbrella when leaving in the morning because of bad weather forecasted for later in the day.

Back to the Smarthome page