Chocolate Box – Infrastructure / Logic

As mentioned previously, the central part of the project is represented by the Infrastructure and Logic, both performed on a Raspberry Pi 3, powered by Raspbian.

The two pieces of software that I’m using are Node-RED for the automation and Mosquitto for the signaling.

Let’s see them in details:

Node-RED

Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.

It allows representing every piece of your automation system with a node, configuring its behavior, and connecting it with all the other elements of your system. It also allows to program functions, manipulate the messages, set delays, and so on.

There are a ton of libraries to operate with many different devices and services. For this project I used just a handful of them:

Let’s see how they are interconnected and configured:

Alexa-local node

The configuration of this block is trivial. It’s just enough to give a name to the node, and it will be the name that Alexa will list in the discovered devices. After this node is deployed it’s necessary to give an “Alexa, discover devices” command to make it appear in the smart home section of your Alexa as a new device.
You can find the Alexa-local node on GitHub or in the install palette on Node-RED.

Function “Open” node

This function takes the message coming from Alexa and manipulates the payload to control the opening of the box.

The function is extremely simple:

Delay node and Close Template node

The first node introduces a 20-second delay before triggering the close template.

The close template is defined as follows:

Once again, this is nothing fancy.

MQTT-out node

As you might have understood, the only two messages that this node receives are true, when it’s time to open the box, and false, 20 seconds later, when it’s time to close it.

These messages are sent to an MQTT broker with the topic box_open as follows:

And that’s all it’s needed on Node-RED to make it work. Let’s now see how to tell the Arduino board to open and close the box.

Mosquitto

To interface Arduino to Node-RED I went for the most appropriate protocol: MQTT. This protocol requires a broker, a piece of software that receives signals from the many different agents, and dispatches them to the appropriate recepients.

And this is all you need to know to make it work on our Raspberry Pi. You simply install Mosquitto and make sure it’s configured as your MQTT broker on Node-RED and on the Arduino sketch. Voila!

Downloads and resources

You can find the Node-Red Flow, and all the rest of the resources on this GitHub repository.

It’s all released under GPL!

That’s all for today, in the next posts I’ll show you how to configure Alexa, how to build the box, the circuit board, and configure Arduino.

Stay tuned, and feel free to contribute!

One thought on “Chocolate Box – Infrastructure / Logic

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s