Symbient™ Spine™ - Enterprise Service Bus (ESB) With Built-In Rules Engine


One of our core competencies at Lucus Labs is the Internet of Things, or simply "IoT" for short. According to Wikipedia, the Internet of Things "describes the network of physical objects, so known as, 'things' - that are embedded with sensors, software, and other technologies that is used for the purpose of connecting and exchanging data with other devices and systems over the Internet."

Due to the limited power and small capacity of these "things", the IoT relies on a technology typically found in larger applications for transmitting data between networks and between other "things". This technology is called an "Enterprise Service Bus" (ESB). Click here to learn more about ESB's.

In the IoT world, MQTT (Message Queuing Telemetry Transport) is one of the most popular protocols used for sharing messages between devices. But, in order for MQTT to work, you first need an MQTT Broker. This is an application that typically runs on a larger system to which all devices publish messages to, while other devices subscribe to those messages and receive them in real-time so they can act accordingly. Many ESB's can act as the MQTT Broker for exchanging messages between devices, but many ESB's are also overkill when it comes to the IoT. Plus, many ESB's are too expensive for hobbyists and other IoT enthusiasts looking for something simple to get their "things" talking to each other.

Eclipse Mosquitto is an open source MQTT Broker that is used in place of full-blown ESB's, and is one of my personal favorites. However, just like with other ESB's and MQTT Brokers, in order to perform actions based on messages being published to the Broker, you still need another application running elsewhere (could also be on the same system as the Broker) that listens for messages and performs certain actions, actions that don't necessarily always involve other devices, such as forwarding a message to an external system, or sending an email when a certain event occurs.

At Lucus Labs, we decided to simplify this architecture so that the Broker also has the ability to execute certain rules itself, therefore eliminating the need for an additional Rules Engine to run elsewhere. That's when we developed Symbient™ Spine™. As the name implies, Symbient™ Spine™ is the backbone of our technology stack at Lucus Labs. We use it for passing messages between all of our internal products, and also provide it as a commercially available product. I also personally use Symbient™ Spine™ in my Home Automation System which I'll describe briefly below.

As part of our new Pay-It-Forward program, we have decided to release a "lite" version of Symbient™ Spine™ for free. This free version doesn't come with all the bells and whistles the commercial version includes, but sometimes you don't need all the bells and whistles - you just need something that "works".

For example, I have a greenhouse that operates 365 days a year. In order for that to happen, I have to control the temperature inside the greenhouse using a combination of heaters, fans, and vents. Since I also utilize Insteon products in other parts of my Home Automation System (for controlling lights, garage doors, ceiling fans, motion sensors, cameras, etc), I also elected to use Insteon products for controlling the "things" in my greenhouse. As an example, I built a Rule in Symbient™ Spine™ that turns on my heaters when the inside temperature of the greenhouse drops below 70 degrees, and turns the heaters off when the inside temperature goes above 75 degrees. When the inside temperature goes above 80, I have another Rule in Symbient™ Spine™ that triggers the vents to open and the fans to turn on. When the temperature drops back below 75 degrees, the vents close and the fans turn off again. I have another Rule that watches for the doors to my pantry to be opened at which point the pantry light turns on. When the pantry doors are closed, the pantry light turns off.

Here is a screenshot of the Symbient™ Spine™ Rules Editor user interface, along with the above mentioned Rules.

Symbient™ Spine™ Rules Editor


As you can imagine, these simple Rules can be applied to all kinds of use cases. That's why I've chosen to provide these rules as part of Symbient™ Spine™ Lite. You can use these Rules as examples, and are invited to modify them to work with your particular use case.

To get started with Symbient™ Spine™ Lite, we have provided a pre-built executable that you can install and run on a Raspberry Pi, which you can download from https://lucuslabs.com/downloads/symbients-spine.tar.gz. Here are the exact instructions for downloading, installing, and starting Symbient™ Spine™ Lite.

Connect to your Raspberry Pi either directly using a monitor and keyboard, or remotely using SSH. Then, execute the following command to download the app and extract it to your file system:

$ cd ~
$ wget https://lucuslabs.com/downloads/symbient-spine.tar.gz
$ tar -xf symbient-spine.tar.gz
$ cd symbient-spine

From here, we need to install the app as a background daemon which we can do using the following:

$ sudo cp ./symbient-spine.service /lib/systemd/system/symbient-spine.service
$ sudo chmod 644 /lib/systemd/system/symbient-spine.service

Next, we need to install and start the service:

$ sudo systemctl daemon-reload
$ sudo systemctl enable symbient-spine.service
$ sudo systemctl start symbient-spine.service

We can now check that the Symbient™ Spine™ service is running:

$ sudo systemctl status symbient-spine.service

If everything is working correctly, you should see something that resembles the following:

symbient-spine.service - Symbient Spine MQTT Broker + Rules Engine
Loaded: loaded (/lib/systemd/system/symbient-spine.service; enabled; vendor present: enabled)
Active: active (running) since [your current timestamp here]
Process: xxxx ExecStart=/home/pi/symbient-spine/SymbientSpine > /home/pi/symbient-spine/spine.log 2>&1 (code=, status=0/SUCCESS) MainPID: xxxx (SymbientSpine)
CGroup: /system.slice/symbient-spine.service
|___xxxx /home/pi/symbient-spine/SymbientSpine > /home/pi/symbient-spine/spine.log 2>&1
------ systemd[1]: Starting Symbient Spine MQTT Broker + Rules Engine…
------ SymbientSpine[xxxx]: process id of child process xxxx
------ spine[xxxx]: : 0.0.0.0:1883
------ spine[xxxx]: : 0.0.0.0:0
------ systemd[1]: Started Symbient Spine MQTT Broker + Rules Engine.

If you have any trouble starting the app or don't see anything that resembles the above, check the included "spine.conf" file. You may need to change the "iface" values to match those of your Raspberry Pi hardware. You can also update this file to set the port of the built-in HTTP server, set up user authentication credentials for your MQTT clients/users, and even configure Spine™ to pass and store messages in a MySQL database.

Further, you can use the following to get additional details about the background service:

$ sudo journalctl -u symbient-spine.service

With the Symbient™ Spine™ service running, open a web browser on another computer and navigate to the IP address of your Raspberry Pi, along with the port (8080 unless you changed it in "spine.conf"). Example: http://192.168.0.5:8080. Here you should see the Rules Editor similar to the screenshot above. However, at this time the editor will be blank. So, to load the example Rules mentioned above, simply click the "Rules Editor" drop down at the top and click "Load". You can also create your own Rules by selecting from the objects on the left and dragging them onto the Editor on the right. Once you have completed your Rules, click the "Rules Editor" drop down at the top and click "Deploy". This will update the Rules in Symbient™ Spine™ and will tell Spine™ to now perform those Rules whenever messages are published on the ESB. You can also export your Rules to a JSON file, manually edit them by hand in a text editor, and re-import them into Spine™ using the Import/Export menu options under the "Rules Editor" drop down.

If you want to see incoming MQTT messages in real-time, click the "Messenger" link at the top-right of the rules editor. This will open a new tab which contains a client page where you can connect to Spine™, subscribe to topics, publish your own messages, and see all incoming messages on the topics which you've subscribed.

Note: You don't have to use Spine™ just for IoT projects. You can use it for anything you want. I'm just using IoT as a real-world example of one of the many places where we use Spine™ every day.

If you don't have devices that publish MQTT messages to Spine™, you can find plenty of apps out there for mobile devices and laptop/desktop computers, or you can develop your own using any of the many frameworks available for all of the programming languages. Eclipse Paho is an MQTT SDK that's available for several of the most popular programming languages and supports most of what you would ever do with MQTT. You can also contact us for example code that shows how to connect, subscribe, & publish data to/from Spine™ using Paho.

You're also encouraged to engage with us on Twitter @LucusLabs to ask questions, to share your experience with using Spine™, and to show others (and us) how you use Symbient™ Spine™ in your projects. We can't wait to see what you come up with!