The basic concept is as follows:
- Only one Brick (the gateway) needs to connect directly to Wi-Fi.
- All other Bricks use ESP-NOW to send/receive messages via the gateway.
- Each Brick is pre-programmed with unique "skills" (ie "blink an LED", "play a sound" etc).
To illustrate how it works, this simple example will allow pressing a button Brick to turn on/off an LED Brick.
The example uses:
- 3 x LOLIN D1 Minis
- 1 x LOLIN Button Shield
However, basically any combination of ESP8266/ESP32 boards and capabilities will do, and you can modify the existing examples or write your own as needed.
One board will act as the Gateway Brick.
The gateway receives messages from other Bricks via ESP-NOW and converts them into MQTT and vice versa:
Once you have a gateway running, you can use something like Node-RED or other client that speaks MQTT to easily control any number of Bricks and how they interact with each other:
The gateway is the only Brick that connects to WiFi + MQTT and can be configured by editing secrets.h
:
cd examples/gateway
cp include/secrets.sample.h include/secrets.h
vi include/secrets.h
pio run
Make a note of the gateway's MAC address output on the serial monitor, as this is needed to configure the other Bricks.
Initialized [82:7d:3a:79:14:79]
Note: Bricks currently requires a WiFi network that uses channel 1.
The LED Brick example defaults to using the built-in LED, allowing it to
be turned on/off by sending set
messages with payloads of 1
or 0
.
export PLATFORMIO_BUILD_FLAGS="'-DBRICKS_GATEWAY_MAC=\"82:7d:3a:79:14:79\"'"
cd examples/led
pio run
The Button Brick example assumes a button attached
to GPIO 0, and will send pressed
and released
messages.
export PLATFORMIO_BUILD_FLAGS="'-DBRICKS_GATEWAY_MAC=\"82:7d:3a:79:14:79\"'"
cd examples/button
pio run
Bricks announce themselves and their MAC addresses when they come online:
bricks/in/00:11:22:33:44:55/awake: Button - external system reset
bricks/in/aa:bb:cc:dd:ee:ff/awake: LED - external system reset
Use these MAC addresses to send/receive messages to/from specific Bricks.
For this example, a Node-RED solution could be as simple as: