Video and Sensor Data Stream with Web Socket on Raspberry Pi 3

Internet of Things (IOT) and communication between machines (M2M), has emerged as an important concept in conjunction with the use of Internet technology in embedded systems. Thus, programmable remote control and the need for people with microcontrollers, it becomes possible to use the system are minimized. Given this device's web server hardware capabilities, also allows the use of technologies such as web sockets. In this study, a mini computer featuring Raspberry Pi 3 moving images, temperature and pir motion data received, transmitting in real time with clients via the web browser and the ability to monitor the place where you have displayed to clients at the same time is designed as a system. The goal of this system, image processing and artificial intelligence methods using a remote place / region to create a hardware and software infrastructure for monitoring or monitoring. The target for the operating system that offers performance from the device with the use of minimal resources, non-graphical interface and development environment ARM-supported Debian Linux as the Node.js installation is preferred. Socket servers and HTTP server software made by users of a particular program without the need for mobile phone environment is installed the device in any environment with a computer or web browser to monitor in real-time, data retrieval, and has obtained the ability to check. Created this is the system to be monitored spaces regardless of the number of users, thanks to the web connector technology in the software encoded on the device in real time without requiring an additional operation in the browser monitoring displays alerts (voice, text, etc.) situation can be produced.


Introduction
Embedded systems, machines and the Internet of objects (IOT) communication (M2M) systems in the exercise, one of the problems is the ability of hardware and software of the card used. The card will be developed, based on powerful hardware of software capabilities and data directly to the success. Unlike the device used to this point Iot Raspberry Pi 3 stands out. Raspberry Pi 3 reminds of a small computer with its specifications [1], [2]. The features of the card:  Broadcom bcm2837 armv7 quad core cpu,  1 ghz cpu speed,  1 gb sdram,  10/100 ethernet rj45 jack,  4 usb connector,  Hdmi video output,  Audio and video output,  Micro sd card slot,  45 gr weight,  CSI camera link ports,  DSI display connector,  General purpose input and output 40 pins,  Micro usb power input  Internal wi-fi,  Internal bluetooth Raspberry Pi founded on the route that the operating system capabilities of the card and depending on the desired programming engine performance can be created. Thus, microcontroller's language dependency, and programing language is a dynamic development environment which removes the version dependency is obtained. Therefore, the performance of the operating system to be installed on the card the Raspberry Pi card directly. Card will be selected according to the work to be done on the programming language of the work performed is a direct impact on the success and performance. Similarly in this study; Raspberry Pi 1 used to monitor traffic [3]. Raspberry Pi 1 Model B used for home automation system in another work [4]. performance of the card. According to their intended use these operating systems, you will need to the shaped and user programs have been included in the operating system. In addition, 17 December 2012 Raspberry Pi Foundation, in cooperation with IndieCity and Velocix companies open Pi Store for users download application programs. Users located in the official distribution operating system an application using it is possible to download various categories of applications. In addition, users can also be installed on the application developed and can be made available to other users after approval. Apart from these operating systems that are not developed by the Foundation, Raspberry Pi Raspberry Pi announced operating systems are also available. Raspberry Pi cards that can be installed on these operating systems is mostly Linux-based operating systems. On the Windows platform is Windows 10 has started to be supported by Pi card IoT version of Raspberry. In this study; Raspberry Pi used highly efficient and compatible running Debian Linux [5]. Selected operating system is written directly using the appropriate SD card program. Raspberry Pi 3 version does not contain any key to open and close power is transferred to the device SD card operating system searches for and finds the bootloader want to run. The card slot SD card prepared with Raspberry Pi is used.

Node JS
Node Js in 2009 Joyent company by Google's V8 JavaScript engine is produced with a typical run-time environment to be run by the server. Node Js is scalable, event-driven event-driven asynchronous, non-blocking I/O uses working model [6]. This also allows you to run with high performance. LinkedIn mobile server side after passing to Node Js Server dropped the number from 3 to 30 and up to 20 times faster in some operations in masterminding. Node Js are modular. As a module each Node Js library and shrink the size of the nucleus so that it allows applications to run faster [7]. Downloaded the file from the official website of Node Js platform is easy to install. According to other programming languages is the biggest advantage is the package manager Node Js NPM. Ask if you want to do what you want probably as module. NPM is located and easily the desired with the search over the package is used by adding to the project. This package is one of the Socket IO this work was used in the acquisition of data with the web socket.

Web Socket
When the HTTP protocol, web browser (client) from the server (web-server) an HttpRequest, HttpResponse from the server in return gets, the connection is closed. Again, for a new data exchange, a new connection must be created and a new request. HTML5 browsers that support Java Script language is created with the "Web Socket" objects with which to initialize the client-to-server, server-to-client-sided with a low-cost, persistent connections are created. In Java Script web socket technology used with a very available in the library [8]. One of them; "Socket IO" and "SockJs" libraries. In enterprise applications, has become widely used in the Java Spring Framework, STOMP protocol support with SockJs library. In this study , it has been the preferred socket IO library.

Socket IO
The socket IO's with almost every browser in real time (including mobile devices) in spite of different communication protocols to communicate study is preferred. On servers that have been created on the node Js platform Socket IO is used with ease. The socket IO library created from object is set to the specified port on the server is made ready for use by the rest.

Real Time Event Model
The Socket IO creates web socket objects. Sockets are created when request by client to the web server-side on the port opens a channel between the client and service (Fig 2).

Figure 2. The socket IO client/server connection model
Connecting to a socket request pop-up web posted by all clients through data communications same channel (Fig 3). Depending on the socket, exchanging data between clients and the server, you can open the channel room performed. Data communication materializes "Unicast", "Multicast" or "Broadcast" in channel (Fig 4).
Multicast, the message to be sent to clients only is desired. Unicast, exchange of messages between client-server only pointto-point. Broadcast, the message is sent to all clients in the channel.

Implementation of Web Socket on Raspberry Pi 3 Video and Sensor Data Stream
The prepared implementation of the model split into two layers. Layers named "Hardware" and "Software" (Fig. 5). Raspberry Pi 3, Raspberry Pi Noir Camera, dht11 humidity and temperature sensor and hc-sr501 pir motion detection sensor used in hardware layer. Debian Linux OS, Node Js, Socket Io and Html 5 used in software layer. Dht11 and pc-sr501 sensors plug into to Raspberry Pi 3 via gpio pins. Dht11 and pc-sr501 use 3 or 5 volt, therefore its suitable for Raspberry Pi 3. The important thing is that dht11 sensor must be used with a pull up resistor. The design is modeled using Fritzing (Fig. 6). The PiNoir camera plugs into to Rasberry Pi 3 via csi port and hardware implementation is completed (Fig. 9). All software development process is completed using Node JS platform installed on the Raspberry Pi 3.The data received from camera and sensors is transmitted to all clients in real time via the html view with the developed application. All the data communication is transmitted on Socket IO web socket objects. (Fig. 8). Written applications are listening for requests from port 8080. To access the application Raspberry Pi card is assigned a static "192.168.1.10" ip address. When you want to access the generated web application: between the client browser and the server establish socket connection called from a channel called "/jsws". After the "connected" message is received from the web socket, the application automatically activates the camera and sensors. The data received from the camera and sensors are sent simultaneously to all users. Using the web socket in the system brings up performances. The sensors and the data from the camera are taken once and sent to all users, which ensures that the device serves many clients.

Conclusions
This project can easily be applied to places that need constant monitoring because Raspberry pi forms the basis of the project. Raspberry is cheap, offers a lot of technical possibilities and can be supplied from many locations. It works to simultaneously monitor the contents, temperature, and humidity of a room where it is installed. Many places, such as a cold food storage facilities, children's rooms, and summer homes can be monitored. No special program is required and the web browser on a mobile phone or computer is sufficient. A missing feature of the project is that it does not have a database. The system cannot save the data that receives from cameras or sensors and it does not offer a means to fetch data history. This problem should be resolved by adding a NOSQL database like Cassandra or Mongo to the system.