Digital Notice Board Using Raspberry Pi and MQTT Protocol

license

Introduction: Digital Notice Board Using Raspberry Pi and MQTT Protocol

Sabari Kannan_M

By Sabari Kannan_M Follow

More by the author:

15 Minutes SMS Security System Using <a href=Texas Instruments CC3200 (TI CC3200) Launchpad" width="" />

Autodesk Tinkercad Simulation of Arduino UNO Ping Pong Game V2.0:

Guiding Robot With Voice Recognition Feature

About: I'm a B.E.Mechatronics Engineering Student. I love to make things with microcontroller development boards and single board computers. More About Sabari Kannan_M »

Notice Boards are almost used everywhere, such as office, schools, hospitals, and hotels. They can be used over and over again to display important notices or advertise forthcoming events or meetings. But the notice or advertisements have to be printed on a paper and pinned on the notice boards.

In this Instructable let's learn to build our Digital Notice Board with Raspberry Pi to save lots of papers and toner!

Step 1: How Does Digital Notice Board Works?

Step 2: Things Required:

  1. Raspberry Pi with Rasbian OS
  2. Display with HDMI port
  3. Windows PC
  4. Internet Connection
  5. CloudMQTT account

Step 3: GUI Design for Displaying Notices:

We have to design 2 GUIs, one for Raspberry Pi to display the notice on the HDMI Display and another for Windows PC to publish the notice to Raspberry Pi via CloudMQTT broker.

The GUI design depends upon the place where you are going to place the Digital Notice Board. For example, let me design a GUI for Instructables Office to display forthcoming events and meetings so that the employees can be updated with the latest information.

It is easy to design a GUI in a Windows PC, so let us design the Digital Notice Board GUI in the Windows PC and copy the code to the Raspberry Pi.

Software required:

  1. Anaconda (which includes python 2.7, Qt Designer package and Spyder IDE).

Qt Designer is the tool used to design GUIs. The output of the Qt Designer will be a .ui file, later it can be converted to .py for further process.

What is happening in the video?:

installation_directory\Library\bin\pyuic5.bat -x RPi_UI.ui -o RPi_UI.py
C:\Anaconda2\Library\bin\pyuic5.bat -x RPi_UI.ui -o RPi_UI.py

this command will convert the Rpi_UI.ui file to Rpi_UI.py file and place it in the same directory.

Next, let us set up the CloudMQTT account.

Step 4: Set Up a CloudMQTT Account:

pip install paho-mqtt

Step 5: Raspberry Pi Final Code Explained:

Here, let me explain the way I combined RPi_UI.py file with the CloudMQTT.py and saved it as RPi_UI.py.

import paho.mqtt.client as mqtt import urlparse from PyQt5 import QtGui, QtWidgets, QtCore from PyQt5.QtCore import QTimer, QTime from threading import Thread import sys import re from google_drive_downloader import GoogleDriveDownloader as gdd import os
pip install googledrivedownloader
icon = "instructables-logo@2x.png" contestImg = "black" meeting1 = "Meeting1:" venue1 = "Time and venue1." meeting2 = "Meeting2:" venue2 = "Time and venue2." meeting3 = "Meeting3:" venue3 = "Time and venue3."
class Ui_MainWindow(object): def setupUi(self, MainWindow): . def retranslateUi(self, MainWindow): . def _update(self): .
self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.timer = QTimer() self.timer.timeout.connect(self._update) self.timer.start(3000)
def on_message(client, obj, msg): print(str(msg.payload) ) if(str(msg.payload) ): noticeReceived = str(msg.payload) result = re.search('%1(.*)%2(.*)%3(.*)%4(.*)%5(.*)%6(.*)%7(.*)%8', noticeReceived) global contestImg global meeting1 global venue1 global meeting2 global venue2 global meeting3 global venue3 fileId = ""+result.group(1)+"" path = "/home/pi/Desktop/Instructables/RPi UI/ContestImages/"+result.group(1)+".jpg" gdd.download_file_from_google_drive(file_id = fileId, dest_path= path) contestImg = result.group(1) meeting1 = result.group(2) venue1 = result.group(3) meeting2 = result.group(4) venue2 = result.group(5) meeting3 = result.group(6) venue3 = result.group(7)
rc = mqttc.loop()
sys.exit(app.exec_())

In order to run these loops simultaneously, I have used the Threading concept

def sqImport(tId): 
if tId == 0: while 1: rc = 0 while rc == 0: rc = mqttc.loop() print("rc: " + str(rc))if tId == 1: while 1: app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_()) threadA = Thread(target = sqImport, args=[0]) threadB = Thread(target = sqImport, args=[1]) threadA.start() threadB.start() threadA.join() threadB.join()

Cool, we have completed the Raspberry Pi set up, next let us design GUI for Windows PC to publish the message to the Raspberry Pi.

Attachments

Step 6: Windows PC GUI:

Step 7: Windows PC Final Code Explained:

self.pushButton.clicked.connect(self.publish)

Attachments

Step 8: Set Up the Digital Notice Board:

Hints: