TOUCHBERRY PI 3 10″ SOFTWARE MOCKUP CONTEST ON IOT SOLUTIONS WORLD CONGRESS BARCELONA

TOUCHBERRY PI 3 10″ SOFTWARE MOCKUP CONTEST ON IOT SOLUTIONS WORLD CONGRESS BARCELONA

On this post it is showed how it was programmed the Interface of the Touchberry Pi 3 in the mockup contest on IoT Solutions World Congress Barcelona.

This software has been programmed in Python 3 using de PyQt library. Apart from the interface it has been stablished an UDP protocol to interact with the PLC via Ethernet using a ThreadSocket. The software has been divided in two files. The first one is called MainWindow, it is the interface configuration and the UDP configuration. The other is the application that runs the program.

MainWindow.py

from PyQt4 import QtGui, QtCore
 
 import time
 
 import socket                      #pyhton library to stablish the TL layer#              
 import threading                   #python library for stablish a thread      
 
 from pymongo import MongoClient    #python library to interact with a pymongo db.
 
 
 class ThreadSocket(threading.Thread):
     """
     This class configurates a SocketThread and defines the run operation that is called when 
     the ThreadSocket starts
     """ 
     def __init__(self,mw):
         threading.Thread.__init__(self)
 
         self.__mw = mw
         self.__sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) #configuration of socket
         self.__sock.bind(('10.10.10.101', 10001))   #binding with an IP/PORT

     def run(self):
         while True:
             try:
                 result = ""
                 data, _ = self.__sock.recvfrom(50)
                 if (data[:1] == b'B'):
                     if (data[-1:] == b'E'):
                         result = data[1:-1]
 
                 self.__mw.label.setText(result.decode("utf-8"))
             except:
                 break;
 
 
 class MainWindow(QtGui.QWidget):
     """
     It defines the interface of the app
     """
     def __init__(self):
         """
         Initialization of the graphic interface
         """
         QtGui.QWidget.__init__(self)
 
         #MongoClient is used for saving the interface configuration in a database.
         self.__client = MongoClient()
         self.__db = self.__client.mess
 
         #Speed parameter
         self.speed = QtGui.QLabel(self)                   #stablish property of the label
         self.speed.setGeometry(QtCore.QRect(150, 100, 250, 50)) #Shape
         self.speed.setObjectName("speed")                       #Name of the parameter
 
         #Label parameter
         self.label = QtGui.QLabel(self)
         self.label.setGeometry(QtCore.QRect(420, 100, 435, 40))
         self.label.setObjectName("label")
 
         #email parameter
         self.email = QtGui.QLabel(self)
         self.email.setGeometry(QtCore.QRect(150, 180, 250, 50))
         self.email.setObjectName("email")
 
         #editable text1 parameter
         self.edit1 = QtGui.QLineEdit(self)
         self.edit1.setGeometry(QtCore.QRect(420,180,200,40))
         self.edit1.setObjectName("edit1")
 
         #at(@) parameter 
         self.arr = QtGui.QLabel(self)
         self.arr.setGeometry(QtCore.QRect(623, 180, 25, 40))
         self.arr.setObjectName("arr")
 
         #editable text2 parameter
         self.edit2 = QtGui.QLineEdit(self)
         self.edit2.setGeometry(QtCore.QRect(650,180,200,40))
         self.edit2.setObjectName("edit2")
 
         #button parameter
         self.button = QtGui.QPushButton('Send >>>', self)           # action when push
         self.button.clicked.connect(self.handleButton)              # action when clicked          
self.button.move(420,260)                                            # Position of the button
         self.button.resize(435,60)                                  # Size of button
         self.button.setObjectName("button")
 
         self.speed.setText(">>> Max. speed:")                       #Text of Max.Speed 
         self.email.setText("E-mail:")                               #Email text
         self.arr.setText("@")                                       #email text
 
         ThreadSocket(self).start();                                 # Call of run() function
 
     def handleButton(self):
         """
         It defines the behaviour of the program after clicking the button
         It prepares an email to send the information via electronic mail.
         """
         if (self.edit1.text() != "" and self.edit2.text() != ""):
             address = self.edit1.text() + "@" + self.edit2.text()           
             self.__db.addresses.insert_one({"address":address,"speed":self.label.text()})
             self.edit1.setText("")
             self.edit2.setText("")
             self.label.setText("")

app.py

#!/usr/bin/python3
 
 import os
 import signal    #Python library for asynchronous events
 import sys
 from PyQt4 import QtCore, QtGui      #Python library for the Gui
 
 from gui.MainWindow import MainWindow
 
 myDir = os.path.dirname(os.path.realpath(__file__))
 
 if __name__ == "__main__":
     signal.signal(signal.SIGINT, signal.SIG_DFL)     #Configuration of an event

     app = QtGui.QApplication(sys.argv)
 
     # Set stylesheet
     with open(os.path.join(myDir, "css/app.css")) as css:
         app.setStyleSheet(css.read())
 
         # Init main window widget
         mainWindow = MainWindow()
         mainWindow.setWindowFlags(QtCore.Qt.FramelessWindowHint)
         mainWindow.setGeometry(0, 0, 1280, 600)
         mainWindow.setWindowTitle("Industrial Shields")
         mainWindow.setObjectName("mw")
         # Show the main window
         mainWindow.show()
         ret = app.exec_()
         sys.exit(ret)

See also:

INDUSTRIAL SHIELDS MOCKUP CONTEST ON IOT SOLUTIONS WORLD CONGRESS BARCELONA

AN INTRODUCTION TO NODE-RED

TOUCHBERRY B3 Pi 10.1″ TECHNICAL SPECIFIATIONS

 

 

 

Comments are closed.