Node-RED on the Raspberry Pi

Goal: Learn how to work on the Raspberry Pi with the Sense HAT.

Tips:

  • Node-RED documentation is here.
  • You need to install npm. Search for “npm install linux”. (Or see below)
  • The browser on the Raspberry Pi is not good for using Node-RED. Therefore, run Node-RED on the Raspberry Pi, but log into it via a browser from your laptop. (Via the Pi’s IP address…)

Here are the lines to install NPM:

sudo apt-get install npm

Securing Node-RED

By default, Node-RED is accessible to anyone from the network. You should therefore first protect access, with the steps described here.. For what we do today, the steps listed under Editor & Admin API security until Generating the password hash is enough. (Use a hard-coded user.)

Your First Flow

Create a simple flow, only consisting of an inject node and a debug node. Configure all nodes so that when you click on the inject node, a text is written to the Node-RED debug console.

For the Report: Of course, include a screenshot of the flow and describe how it worked.

Node-RED for the Sense HAT

Check if these flows for the Sense HAT are already installed. Otherwise, install them via the command line.

Task: Build a simple application that uses some input from the Sense HAT (via flow rpi-sensehat in) and produces some output (via flow rpi-sensehat out).

For the Report: Of course, include a screenshot of the flow and describe how it worked.

Create a Slack Robot

Goal: You should build a very simple Slack chat robot With the API of Slack, the Sense HAT and the Raspberry Pi.

First, create a new Slack domain. (You can delete it again after this course.) It’s enough if one of you has a user, but its maybe more fun when you can experiment with several users.

  • Read Getting Started With Custom Integrations about how to create a chat robot.
  • Find the green button Set up a bot user, and login into the Slack account you created earlier.
  • Select Add Configuration…, select a name for the bot, and create it.
  • Copy the API token for later.

Milestone: You have now created a robot in Slack. It now waits for instructions. They can come from different applications that you can build in the following.

Slack Robot with Node-RED

Install these Node-RED flows for an integration with Slack. After the installation, you should get two new flows, slackbot-listen and slackbot-reply.

Tip: It is necessary to install nodes globally, with the -g option:

npm install -g node-red-contrib-slack

Combine the slackbot-listen and slackbot-reply with other nodes. Stepwise explore what you can do with this API:

  • Just send an empty reply whenever you contact the chat bot from within Slack.
  • Can you print the message sent to the chat bot to the Node-RED console?
  • Deliver the current temperature as a reply to any message.

Challenge: Try to build a (more complex) Node-RED flow so that you send the current temperature to any message that contains the word “temperature” to the chat bot. When the message contains “humidity” send the current humidity.

For the Report: Of course, include a screenshot of the flow and describe how it worked.