Communicate with your Raspberry Pi via MQTT

kathrin Examples 0 Comments

2014-10-07 10.25.05

We made a simple demo application showing how you can set up communication with your Raspberry Pi via MQTT. MQTT is a publish-subscribe based messaging protocol which is among others used by Facebook Messenger.

We attached an Adafruit 8×8 LED matrix (with I2C backpack) to the Raspberry Pi. Our example shows how hitting the arrow keys on a laptop causes the Raspberry Pi to react by triggering the LED matrix to light up arrows corresponding to the arrow keys.

 

In the figure below you can see the application running on the laptop.

senddirection_system

It captures events from the arrow keys using the building block Arrow Key Controller. Each of these events triggers the creation of an MQTT message which is published with topic direction to a broker using the building block Robust MQTT.

 

The other application deployed to the Raspberry P is here:

displayarrows_system

It also uses the building block Robust MQTT. However here it is used to subscribe to messages with topic direction. When such a message is received the application extracts information from the MQTT message (block GetArrow) and displays it on the LED Matrix using the block ArrowsFor8x8Display.

 

In case you have an Adafruit 8×8 LED Matrix, running this example is straightforward:

  • Install Reactive Blocks
  • Import project Example: MQTT with Raspberry Pi and 8×8 LED Matrix (from Team Reference Systems)
  • Build and run application SendDirection locally on your laptop
  • Build the application Display Arrows and export it as runnable JAR to copy it to your Raspberry Pi and run it there.

 

You don´t have a LED Matrix? You can adjust this example with an operation which prints the direction to the console.  Replacing block ArrowsFor8x8Display by an operation will do the trick.  Have questions or need help, just contact me.

Share on FacebookTweet about this on TwitterShare on LinkedInGoogle+Email to someone

Leave a Reply