0% found this document useful (0 votes)
51 views5 pages

Lab 2 and 3

This document outlines lab exercises 2 and 3 of an IT course. The objectives are: understanding MQTT protocol for sharing information across devices; interfacing sensors and actuators with Raspberry Pi; and introducing Node-Red for creating dashboards. Students will use MQTT to connect a Raspberry Pi and laptop, interface an ultrasonic sensor and LED with the Pi, and build Node-Red flows to control an LED, send emails on button press, and create a dashboard showing ultrasonic sensor data.

Uploaded by

sasith.wickrama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views5 pages

Lab 2 and 3

This document outlines lab exercises 2 and 3 of an IT course. The objectives are: understanding MQTT protocol for sharing information across devices; interfacing sensors and actuators with Raspberry Pi; and introducing Node-Red for creating dashboards. Students will use MQTT to connect a Raspberry Pi and laptop, interface an ultrasonic sensor and LED with the Pi, and build Node-Red flows to control an LED, send emails on button press, and create a dashboard showing ultrasonic sensor data.

Uploaded by

sasith.wickrama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MSc in Information Technology

Lab Exercise 2 and 3


IT5070-2021

Lab 2 and 3: Interfacing Sensors and Introduction to MQTT and Node Red
Objectives:
• Understanding the importance of protocols such as MQTT
• Ability to use MQTT protocol for sharing information across computers
• Interfacing simple sensors and actuators with the Raspberry Pi
• Introduction to node red and its functionalities
• Employing Node Red to create a simple dashboard

Equipment:
• Raspberry Pi
• USB power supply and cable
• Monitor
• HDMI to VGA converter
• Mouse and Keyboard
• Laptop Computer
• Breadboard
• Jumper Wires
• LED
• 330Ω Resistor
• Micro Switch
• Ultrasonic Sensor (HC-SR04 or HC-SR05)

1
Background:

Background
MQTT stands for Message Queuing Telemetry Transport. It is a publish/subscribe,
extremely simple and lightweight messaging protocol, designed for constrained devices and
low-bandwidth, high-latency or unreliable networks. The design principles are to minimize
network bandwidth and device resource requirements whilst also attempting to ensure
reliability and some degree of assurance of delivery. These principles also turn out to make
the protocol ideal of the emerging “machine-to-machine” (M2M) or “Internet of Things”
world of connected devices, and for mobile applications where bandwidth and battery
power are at a premium. MQTT was invented by Dr Andy Stanford-Clark of IBM, and Arlen
Nipper of Arcom (now Eurotech), in 1999. TCP/IP port 1883 is reserved with IANA for use
with MQTT. TCP/IP port 8883 is also registered, for using MQTT over SSL.

Part 1: Initializing connection across multiple computers through MQTT


MQTT protocol is a versatile tool that can be used to share information across multiple computers.
This information can then be used to receive information from sensors and control actuators. In the
first part of this lab, we will initiate a connection between a raspberry pi and a personal computer
(laptop or desktop computer). In the second part we shall use the same communication channel.

Note: All codes can be found in the Appendix A.

On Raspberry Pi

Step 1-Raspberry Pi- Open a terminal and install paho-mqtt library using pip

pip install paho-mqtt

Step 2-copy the provided python script mqtt_client.py to the Desktop and run it.

2
cd Desktop

python mqtt_client.py

If successful, the terminal would display the message Connected with result code 0

On Laptop/Desktop computer

Step 3- Open the command line and install the paho-mqtt library using pip

pip install paho-mqtt

Step4- Open your favorite python IDE and run the given mqtt_publisher.py script

Step 5- Observe the terminal of the Raspberry Pi for received message

Part 2: Interfacing basic sensors with raspberry Pi


Step1- Connect the ultrasonic sensor and the led as shown in the schematic (use the schematic given
in lab 1 to connect the led)

Step2- Run the code Utlrasonic.py and observe the functionality

Part 3: Introduction to Node-Red


1. Open Node-RED app on your RPi through

Start Button -> Programming -> NodeRed

2. Copy the IP address given and open it on a browser

3
For instance: http://192.168.1.7:1880

You will be taken to the node red site which is hosted on your Raspberry Pi

Subtask 1- Identify design area, palette, information and debug windows

Subtask 2- Create a Hello world program using inject and debug modules

Subtask 3- Setup a configuration to turn on and off a LED through node red

Subtask 4- Implementing logic to control I/O devices

Expand the previous setup to turn on a LED through switch connected to raspberry pi

Subtask 5- Sending email through Node Red

4
Expand the previous setup to send an email every time the button is pressed

Subtask 6- Create simple dashboard to control a LED

Take home assignment:


Interface the ultrasonic sensor with the raspberry pi and create a simple dashboard to show
the distance variation

You might also like