A Sensor Network for the Internet of Things Integrated with a Bidirectional Backend
Total Page:16
File Type:pdf, Size:1020Kb
Degree Project Electrical Engineering July 2014 A sensor network for the Internet of Things Integrated with a bidirectional backend Linus Hobring Philip Söderberg Department of Communication Systems (DIKO) Blekinge Institute of Technology 371 79 Karlskrona Sweden This thesis is submitted to the Department of Communication Systems at Blekinge Institute of Technology in partial fulfillment of the requirements for the degree of Master of Science in Electrical Engineering with emphasis on Telecommunication Systems. The thesis is equivalent to 20 weeks of full time studies. Contact Information: Authors: Linus Hobring and Philip Söderberg E-mail: linus{dot}hobring{at}gmail.com and philip{dot}soderberg{at}gmail.com External advisor: Ruwan Lakmal Silva University advisor: Markus Fiedler Department of communication Systems Department of Communication Systems Internet : www.bth.se Blekinge Institute of Technology Phone : +46 455 38 50 00 371 79 Karlskrona Fax : +46 455 38 50 57 Sweden ii ABSTRACT Internet of Things is rapidly evolving. This thesis includes a study of single-board computers suitable for machine-to-machine communication together with the developing process of a sensor network integrated with a bidirectional communication platform. Raspberry Pi was selected as the single-board computer used in the proposed system. The Message Queuing Telemetry Transport protocol was selected as main communication protocol to handle all exchange of information between the network and the bidirectional communication platform. It was selected because of its reliability, low bandwidth and publish/subscribe architecture. Decision-making procedures were implemented to work with both local sensor data and data from different Message Queuing Telemetry Transport streams, such as GPS data, used to calculate the distance between the user’s smart phone and the office to prepare the workstation, temperature sensors and ambient light sensors controlling Philips HUE light bulbs. The finished sensor network was design to work within office environments to prepare workstations and monitor the work climate. The number of sensors connected to the single- board computer has a major impact in the CPU usage. Measurements and calculations show that 17 connected physical sensors will cause a CPU usage of 96%. Keywords: IoT, M2M communication, MQTT, Sensor network and single-board computers. ACKNOWLEDGEMENTS This thesis work has been carried out at a large software company, which has chosen to remain anonyms, in Karlskrona Sweden in cooperation with Department of Communication Systems, Blekinge Institute of Technology (BTH), Karlskrona Sweden under supervision of Prof. Dr. Ing Markus Fiedler (BTH) and Ruwan Lakmal Silva. We especially want to thank Lakmal for his supervision and guidance during the thesis work. He has helped us to reach our goals and shown a great interest during all phases of the project. We would also like to thank Markus for his tutoring and expertise. Thank you, Linus Hobring, Philip Söderberg ii TABLE OF CONTENTS ABSTRACT ............................................................................................................................................ I ACKNOWLEDGEMENTS ................................................................................................................. II TABLE OF CONTENTS ................................................................................................................... III TABLES OF FIGURES ..................................................................................................................... IV NOTATION ........................................................................................................................................... V 1 INTRODUCTION ........................................................................................................................... 1 1.1 AIMS AND OBJECTIVES ............................................................................................................... 1 1.2 CONTENT OF THE THESIS ............................................................................................................ 3 2 BACKGROUND ............................................................................................................................. 4 2.1 INTERNET OF THINGS ................................................................................................................. 4 2.2 SINGLE-BOARD COMPUTERS ....................................................................................................... 5 2.2.1 Operating systems .............................................................................................................. 7 2.2.2 Programming language ...................................................................................................... 8 2.3 MESSAGE QUEUING TELEMETRY TRANSPORT ........................................................................... 9 2.4 MESSAGE QUEUING TELEMETRY TRANSPORT – SENSOR NETWORKS ......................................... 9 2.5 HTTP ......................................................................................................................................... 9 2.5.1 HTTP URL ......................................................................................................................... 9 2.5.2 GET .................................................................................................................................. 10 2.5.3 POST ................................................................................................................................ 10 2.6 API ........................................................................................................................................... 10 3 RELATED WORK ....................................................................................................................... 11 3.1 INTERNET OF THINGS ............................................................................................................... 11 3.1.1 IoT in the building domains ............................................................................................. 11 3.1.2 IoT in the health care domain .......................................................................................... 12 3.2 SENSOR NETWORKS .................................................................................................................. 12 3.2.1 Using Arduino and Raspberry Pi ..................................................................................... 12 3.3 MQTT QOS LEVEL .................................................................................................................. 13 3.4 SINGLE-BOARD COMPUTERS AND CLOUD SERVICES ................................................................. 14 4 RESEARCH METHODOLOGY ................................................................................................ 15 5 FUNDAMENTALS ....................................................................................................................... 16 5.1 GENERAL PURPOSE INPUT OUTPUT ........................................................................................... 16 5.2 INPUT/OUTPUT INTERFACES ..................................................................................................... 16 5.2.1 Inter-Integrated Circuit .................................................................................................... 16 5.2.2 One-wire ........................................................................................................................... 17 5.3 THREADED PROGRAMS ............................................................................................................. 17 5.3.1 Threads ............................................................................................................................. 17 5.3.2 Multithreading .................................................................................................................. 17 5.4 ADD-ON SOFTWARE ................................................................................................................. 17 5.4.1 PIGPIO ............................................................................................................................. 17 5.4.2 Mosquitto .......................................................................................................................... 18 5.4.3 Wiring Pi .......................................................................................................................... 18 5.4.4 Linux Apache MySQL PHP .............................................................................................. 18 5.4.5 Round Robin Database tool ............................................................................................. 18 5.4.6 Adafruit Python Library ................................................................................................... 18 5.4.7 I2C Detect ......................................................................................................................... 19 iii 6 SYSTEM ARCHITECTURE ....................................................................................................... 20 6.1 SYSTEM OVERVIEW .................................................................................................................. 20 6.1.1 Main Python script ........................................................................................................... 23 6.1.2 Threads ............................................................................................................................