1. Trang chủ
  2. » Luận Văn - Báo Cáo

Development of iot gateway based on web services

56 14 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

VIET NAM NATIONAL UNIVERSITY HO CHI MINH CITY HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY FACULTY OF COMPUTER SCIENCE AND ENGINEERING GRADUATION THESIS DEVELOPMENT OF IOT GATEWAY BASED ON WEB SERVICES MAJOR: COMPUTER ENGINEERING COUNCIL: COMPUTER ENGINEERING INSTRUCTOR: Dr LE TRONG NHAN REVIEWER: Assoc.Prof PHAM QUOC CUONG Student: Tran Hoang Nam 1651070 Ho Chi Minh City, December 2021 - - KHOA:KH & KT Máy tính KHMT ình MSSV: 1651070 CLC NGÀNH: Develop IoT Gateway Based on Web Service 01/10/2021 01/12/2021 1) Ngày 01 tháng 02 2022 _ _ _ _ KHOA KH & KT MÁY TÍNH -Ngày 27 tháng 12 2021 Hoàng Nam MSSV: 1651070 Ngành (chuyên ngành): Development of IOT gateway based on web servives 46 25 :1 - The thesis is successfully to implement the behavior of a gateway based on a new approach Specifically, a web based application is deployed at the gateway This structure provides a flexible design for the gateway in term of update the functionalities Moreover, the User Interface is friendly as it is a webpage design Student is successful to apply this design to a simple Internet of Things application with a sensor node to monitor some sensing data ThingsBoard server is used in this thesis to design the front end and also the backend of the system Communications are mainly based on the MQTT protocol The communication protocol between nodes is simple and need to improve in a network having many nodes a Currently, the gateway and sensors are connected through a cable, can wireless connection can be applied? b Is there any encryption algorithm used for data communication? 8/10 TRƯỜNG ĐẠI HỌC BÁCH KHOA KHOA KH & KT MÁY TÍNH CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM Độc lập - Tự - Hạnh phúc -Ngày 26 tháng 12 năm 2021 PHIẾU CHẤM BẢO VỆ LVTN (Dành cho người phản biện) Họ tên SV: Trần Hoàng Nam – 1651070 – Ngành Kỹ thuật Máy tính Đề tài: Develop IoT Gateway based on Web services Họ tên người hướng dẫn/phản biện: Phạm Quốc Cường Tổng quát thuyết minh: Số trang: Số chương: Số bảng số liệu Số hình vẽ: Số tài liệu tham khảo: Phần mềm tính tốn: Hiện vật (sản phẩm) Tổng quát vẽ: - Số vẽ: Bản A1: Bản A2: Khổ khác: - Số vẽ vẽ tay Số vẽ máy tính: Những ưu điểm LVTN: - Students proposed architecture and successfully implemented a Web services-based IoT gateway - The gateway can handle sensors and communicate with a server - Users can control devices through a web-based interface Những thiếu sót LVTN: - The demonstration is quite simple when only one device is used as a sensor - The designed and implemented web service is quite simple and not professional enough - The student should carefully revise the report with high-quality figures and a formal writing style Đề nghị: Được bảo vệ o Bổ sung thêm để bảo vệ o Không bảo vệ o câu hỏi SV phải trả lời trước Hội đồng: a Currently, the gateway and sensors are connected through a cable, can wireless connection can be applied? b Is there any encryption algorithm used for data communication? 10 Đánh giá chung (bằng chữ: giỏi, khá, TB): Điểm: 8.0/10 Ký tên (ghi rõ họ tên) Phạm Quốc Cường Thesis COMMITMENT My name: Tran Hoang Nam, a student majoring in Computer Engineering, class CC16KTM, at Ho Chi Minh City National University Ho Chi Minh - University of Science and Technology I hereby declare that the following statements are true: (i) This research work is entirely my own work; (ii) The documents and citations in this thesis are referenced from real, reputable and highly accurate sources; (iii) The data and results of this work are independently and honestly produced by me Sincerely, Tran Hoang Nam i Thesis ACKNOWLEDGEMENT First and foremost I would like to express my special thanks of gratitude to my supervisor Dr Le Trong Nhan for giving me invaluable helps and instructions with my graduation thesis, the research would have been impossible without the aid and support of him Secondly I would also wanted to thank Assoc.Prof Pham Quoc Cuong for giving me a lot of helpful and constructive advices Last but not least, I would like to thank my parents and friends who helped me a lot in finalizing this thesis Finally, I would like to wish you good health and success in your noble life ii Thesis ABSTRACT Nowadays, IOT plays a very important part of our lives which lead to the development of IOT applications But there is an area where developers have been constantly dealing with – UPGRADE Most IOT embedded uses an already installed Gateway to run the programs, the problem is every time there is an update, they must be manually modified by the developer which is very time consuming and labor intensive, the users also depend on the developer to modify their gateway based on their own specifications The goal of this thesis is introduce the Development of IOT Gateway based on web services so that the developers can update the program on the server and all the IOT devices will automatically update at the same time without any hustle and customize their gateway based on their own needs This thesis contains nine chapters to explain our work obviously Each chapter has informed particular segment of the project Our final result allows the users to monitor and interact with the sensors through a web application and n native application on the embedded board Keyword for my work: Raspberry Pi, Unbuntu, Python, PyQy5, Thingsboard, Microbit iii CONTENTS Chapter INTRODUCTION 1.1 Introduction 1.2 Thesis introduction 1.3 Thesis overview 2 Chapter IOT GATEWAY 2.1 Introduction 2.2 Basic concepts of IOT gateway 5 Chapter SYSTEM ARCHITECTURE 3.1 Introduction 3.2 State machine 3.2.1 State description 3.3 Conclusion 7 8 9 10 11 13 14 16 18 18 19 19 20 Chapter HARDWARE CONFIGURATION 4.1 Raspbian operating system 4.2 Raspberry Pi 4.2.1 Raspberry Pi model B plus 4.2.2 Raspberry Pi 4.2.3 Raspberry Pi Zero W 4.3 Microbit sensor 4.3.1 Programming Microbit Chapter LIBRARIES AND TOOLS 5.1 Thingsboard 5.1.1 Architecture 5.2 PQt5 5.3 Paho-mqtt iv Thesis 21 21 21 22 22 23 23 24 25 27 27 28 28 31 32 37 Chapter RESULT AND DISCUSSION 7.1 System performance on each platform 7.2 Full implementation evaluation 7.2.1 IOT Gatway 40 40 41 41 Chapter CONCLUSION 8.1 Advantages 8.2 Disadvantages 8.3 Development 43 43 43 43 REFERENCES 45 5.4 5.3.1 Known limitations 5.3.2 Usage API PySerial 5.4.1 Features 5.4.2 Requirements Chapter IOT GATEWAY USING PYTHON 6.1 Introduction 6.2 Thingsboard Information 6.3 Project on PyCharm 6.4 Install library 6.5 Implementation 6.5.1 Import library and initialize 6.5.2 Functional implementation 6.5.3 Configuration for Gateway 6.5.4 Programming GUI 6.5.5 Demo v LIST OF FIGURES 2.1 IOT Gateway graph 3.1 State machine 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 Raspbian platform on Raspberry Pi Raspberry Pi 3B plus Raspberry Pi Linpack Benchmark of Raspberry Pi versions Raspberry Pi Zero W Microbit sensor Microbit Components Microbit code 10 11 13 14 15 16 17 5.1 5.2 5.3 LED control Dashboard interface PyQt5 interface example Paho-mqtt 19 20 20 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 4-level architecture in IoT Check information of Feed Name of accessed Feed PyCharm IDE Create a project on Pycharm Create a project at the current window of PyCharm Gateway connect and subscribe successfully Microbit response GUI 23 24 25 26 26 27 37 38 39 vi Thesis 17 getDataSerial () 18 print ( " Sending data " ) 19 client publish ( ’ v1 / devices / me / telemetry ’ , json dumps←֓ ( collect_data ) , 1) time sleep ( INTERVAL ) 20 21 22 except Ke yboard Interr upt : pass 23 24 25 client loop_stop () 26 client disconnect () 27 # serialControl stop () At the end of the program, we need an endless loop so that the program does not terminate Thus, it listens to the information sent back from the Thingsboard server and automatically calls the message function for us Since in this endless loop, we don’t need to perform any function yet, so the pass command is added to correct the syntax in the Python language The program in this article is shared at the following link: https://github.com/namtrhg/thesis/connect.py 6.5.4 Programming GUI We will also implement an GUI for the embedded board itself using the PyQt5 library, first we created the main.py file then the implementation is as bellow by using PyQt5 modals and components: Listing 6.4: Programming GUI # importing required libraries from PyQt5 QtCore import * from PyQt5 QtWidgets import * from PyQt5 QtGui import * from PyQt5 Q tW eb En gi ne Wi dg et s import * from PyQt5 QtPrintSupport import * 32 Thesis import os import sys 10 # creating main window class 11 class MainWindow ( QMainWindow ) : 12 13 # constructor 14 def init ( self , * args , ** kwargs ) : 15 super ( MainWindow , self ) init (* args , ** kwargs ) 16 17 18 # creating a QWebEngineView 19 self browser = QWebEngineView () 20 21 # setting default browser url as google 22 self browser setUrl ( QUrl ( " http :// thingsboard - iot tk←֓ :9090/ dashboard / f4c15b60 -4 e9c -11 ec -8577 -077 bd963cf86 ?←֓ publicId =902 c2da0 -51 a9 -11 ec -8577 -077 bd963cf86 " ) ) 23 24 # adding action when url get changed 25 self browser urlChanged connect ( self update_urlbar ) 26 27 # adding action when loading is finished 28 self browser loadFinished connect ( self update_title ) 29 30 # set this browser as central widget or main window 31 self setCentralWidget ( self browser ) 32 33 # creating a status bar object 34 self status = QStatusBar () 35 36 # adding status bar to the main window 37 self setStatusBar ( self status ) 38 39 # creating QToolBar for navigation 40 navtb = QToolBar ( " Navigation " ) 33 Thesis 41 42 # adding this tool bar tot he main window 43 self addToolBar ( navtb ) 44 45 # adding actions to the tool bar 46 # creating a action for back 47 back_btn = QAction ( " Back " , self ) 48 49 # setting status tip 50 back_btn setStatusTip ( " Back to previous page " ) 51 52 # adding action to the back button 53 # making browser go back 54 back_btn triggered connect ( self browser back ) 55 56 # adding this action to tool bar 57 navtb addAction ( back_btn ) 58 59 # similarly for forward action 60 next_btn = QAction ( " Forward " , self ) 61 next_btn setStatusTip ( " Forward to next page " ) 62 63 # adding action to the next button 64 # making browser go forward 65 next_btn triggered connect ( self browser forward ) 66 navtb addAction ( next_btn ) 67 68 # similarly for reload action 69 reload_btn = QAction ( " Reload " , self ) 70 reload_btn setStatusTip ( " Reload page " ) 71 72 # adding action to the reload button 73 # making browser to reload 74 reload_btn triggered connect ( self browser reload ) 75 navtb addAction ( reload_btn ) 76 34 Thesis 77 # similarly for home action 78 home_btn = QAction ( " Home " , self ) 79 home_btn setStatusTip ( " Go home " ) 80 home_btn triggered connect ( self navigate_home ) 81 navtb addAction ( home_btn ) 82 83 # adding a separator in the tool bar 84 navtb addSeparator () 85 86 # creating a line edit for the url 87 self urlbar = QLineEdit () 88 89 # adding action when return key is pressed 90 self urlbar returnPressed connect ( self navigate_to_url ) 91 92 # adding this to the tool bar 93 navtb addWidget ( self urlbar ) 94 95 # adding stop action to the tool bar 96 stop_btn = QAction ( " Stop " , self ) 97 stop_btn setStatusTip ( " Stop loading current page " ) 98 99 # adding action to the stop button 100 # making browser to stop 101 stop_btn triggered connect ( self browser stop ) 102 navtb addAction ( stop_btn ) 103 104 # showing all the components 105 self show () 106 107 108 # method for updating the title of the window 109 def update_title ( self ) : 110 title = self browser page () title () 111 self setWindowTitle ( " % s - Thesis Application " % title ) 112 35 Thesis 113 114 # method called by the home action 115 def navigate_home ( self ) : 116 117 # open the google 118 self browser setUrl ( QUrl ( " http :// thingsboard - iot tk←֓ :9090/ dashboard / f4c15b60 -4 e9c -11 ec -8577 -077 bd963cf86 ?←֓ publicId =902 c2da0 -51 a9 -11 ec -8577 -077 bd963cf86 " ) ) 119 120 # method called by the line edit when return key is pressed 121 def navigate_to_url ( self ) : 122 123 # getting url and converting it to QUrl object 124 q = QUrl ( self urlbar text () ) 125 126 # if url is scheme is blank 127 if q scheme () == " " : 128 # set url scheme to html 129 q setScheme ( " http " ) 130 131 # set the url to the browser 132 self browser setUrl ( q ) 133 134 # method for updating url 135 # this method is called by the QWebEngineView object 136 def update_urlbar ( self , q ) : 137 138 # setting text to the url bar 139 self urlbar setText ( q toString () ) 140 141 # setting cursor position of the url bar 142 self urlbar set Cursor Positi on (0) 143 144 145 # creating a pyQt5 application 146 app = QApplication ( sys argv ) 36 Thesis 147 148 # setting name to the application 149 app se tA pp li ca tio nN am e ( " Geek Browser " ) 150 151 # creating a main window object 152 window = MainWindow () 153 154 # loop 155 app exec_ () The program in this article is shared at the following link: https://github.com/namtrhg/thesis/main.py 6.5.5 Demo Now, we will execute the file connect.py and main.py to test its functionality Once launched, the Gateway will connect to the Thingsboard IO server and then subscribe to the Feed LED channel The following information will be printed to the screen if successful: Figure 6.7: Gateway connect and subscribe successfully Now, you can reopen their Dashboard and interact on the push button to illustrate sending the On/Off command Almost immediately, this command will be passed down to the IoT Gateway 37 Thesis Figure 6.8: Microbit response 38 Thesis Figure 6.9: GUI Obviously, all of this data is saved on the Data Feed, which you can check easily 39 CHAPTER RESULT AND DISCUSSION 7.1 System performance on each platform I have implemented my Gateway on different embedded devices: Raspberry Pi 4, Raspberry Pi 3B+ and Raspberry Pi Zero W Raspberry Pi has the best performance, followed by Raspberry Pi 3B+ In case of Raspberry Pi Zero W, processing speed is quite slow and the system is unstable due to the weak RAM and power Since Raspberry Pi Zero has to use converter to connect to the Microbit Platform Image Price CPU Speed RAM GPU Core Type Wifi Raspberry Pi Raspberry Pi 3B+ Raspberry Pi Zero W 45$ 1.5GHz 35$ 1.4GHz 2GB VideoCore VI Cortex-A72 (ARM v8) 64-bit 2.4GHz and 5GHz 802.11n wireless LAN 1GB 512MB VideoCore VI VideoCore VI Cortex-A53 64-bit ARM1176JZF-S 10$ 1GHz 2.4GHz and 5GHz 2.4GHz 802.11n 802.11n wireless wireless LAN LAN 40 Thesis USB ports Audio support I/O control support Power Gateway response speed 2x USB 3.0 + 2x USB 2.0 3.5mm analogue audio-video jack RX/TX UART 4x USB 2.0 1.25A 5V 0.1s 1.13A 5V 0.07s x micro OTG 3.5mm analogue HDMI audio audio-video jack RX/TX UART Not Support 180mA 1.2s Table 7.1: System performance comparison between three platforms: Raspberry Pi 3B+, and Zero W 7.2 Full implementation evaluation The full implementation fundamentally affords the requirements of this project on some signature summary: • The Raspberry Pi standout the most due to its power and capability to install PyQt5 to create GUI • If we only using the gateway then the Raspberry Pi can be consider to be the best options because of the price • The latency of the data transferring between all the embedded boards will not affect the performance much due to the timeout of Thingsboard server of 15 seconds • The Raspberry Pi Zero is considerable un-workable because it can’t install the nessesary libraries 7.2.1 IOT Gatway Firstly, I created a gateway and run it on the Raspberry Pi and the GUI will automatic follow an run afterward, the gateway will provide con41 Thesis nections between the embedded board and the Thingsboard server Secondly, I connected the MICROBIT sensors to the responsding ports and they are already pre-configured on the gateway, the gateway will automatic check whether the sensors are connected or not Last but not least, I run the Gateway on the Thingsboard server and check the connections in the client dashboard, the temperature data will be automatically sent to the server every 15 seconds, the reason for the delay is due to the limitations of the Thingsboard server cannot handle too much request at the same time 42 CHAPTER CONCLUSION At present, the gateway has been successfully implemented in which the sensors are connected to the embedded boards and received and sent signals successfully through Thingsboard server In general, the application of this gateway would contribute great impact on the development of web services into the world of IoT Our project intends to extend the applicable range of the project to commercial purpose and research Further application has been mentioned in development section 8.1 Advantages The gateway can be implemented on many embedded devices The system can be access through a web url or a GUI the system can be update very fast and low latency 8.2 Disadvantages The system is currently the first demo version containing some bugs that is fixing The system can operate but only on Internet connection When receiving continuous data there is a time out of 15 seconds 8.3 Development I search on how to implement a gateway on multiple platform 43 Thesis The system has’t support wireless connections The demo right now contains gate ways on one embedded board but it can be increase to multiple gateways Reset I/O controller could be developed in case of I/O external error Power save mode could be implemented in case of sleeping state 44 REFERENCES [1] ”IOT Gateway on Thingsboard” — Github [2] “PyQt5 documentation” — Pyqt5 Official [3] “Paho-mqtt — Paha-mqtt official” [4] “What is MICROBIT — Microsoft Docs” 45 Thesis STUDENT INFORMATION Thesis author: Tran Hoang Nam - ID: 1651070 • Phone number: (84)918.628.660 • Personal Email: 1651070@hcmut.edu.vn 46 ... ngành): Development of IOT gateway based on web servives 46 25 :1 - The thesis is successfully to implement the behavior of a gateway based on a new approach Specifically, a web based application... users also depend on the developer to modify their gateway based on their own specifications The goal of this thesis is introduce the Development of IOT Gateway based on web services so that the... Python program executed 6.3 Project on PyCharm Now, we use PyCharm IDE to create functionality program for Gateway IoT on PC PyCharm is one of the most application for Python developer because of

Ngày đăng: 02/06/2022, 20:18

TỪ KHÓA LIÊN QUAN