= IoT swarm implementation ! Apostolos rootApostolos@swarmlab.io // Metadata: :description: Intro and Install :keywords: IoT :data-uri: :toc: right :toc-title: Πίνακας περιεχομένων :toclevels: 4 :source-highlighter: highlight :icons: font :sectnums: {empty} + == Intro .Intro IoT server **** - software use - what will be covered - etc **** We will be trying to create a swarm implementation that will allow communication between all of the members/nodes. [NOTE] ==== .Imaging a swarm image:./Swarming2.png[alt="Swarm"] To undertand this better lets look at the picture bellow and imagine that red dots are iot devices that can send and receive and black ones are clients that gather data. .Architecture of swarm communication image:./swarmlabn-1.png[alt="Swarm Gateway"] - Red Node: Sensor Node and Gateway Role - Black and Red Node: Sensor Node - Client ==== *To make our life easier at this task we will be using the following tools...* == Prepare installation === http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install.adoc.html[Install docker^] [TIP] ==== *Docker* is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels ==== === Clone IoT swarm implementation example [source.bash] ---- git clone https://git.swarmlab.io:3000/zeus/iot-swarm-example.git cd iot-swarm-example ---- ==== Webclient tree .base dir Webclient [source,bash] ---- src/browser-client/src/ ├── App.vue // <1> ├── assets │ ├── css │ │ └── themify-icons.css │ ├── fonts │ │ ├── glyphicons-halflings-regular.448c34a.woff2 │ │ ├── glyphicons-halflings-regular.e18bbf6.ttf │ │ ├── glyphicons-halflings-regular.f4769f9.eot │ │ ├── glyphicons-halflings-regular.fa27723.woff │ │ ├── themify.eot │ │ ├── themify.svg │ │ ├── themify.ttf │ │ └── themify.woff │ └── logo.png ├── components // <4> │ ├── doclive │ │ ├── AdhocView.vue │ │ └── runLlo.vue │ └── DocLive.vue ├── main.js // <2> └── store ├── index.js └── modules └── create_pipelineLLO.js // <3> ---- <1> load App <2> App config <3> Vuex and Rest calls <4> Components ==== IoT server tree .base dir IoT server [source,bash] ---- src/IoT/llo/ ├── bclient.js ├── client.js ├── iotclient.js // <2> └── iotserver.js // <1> ---- <1> IoT server <2> IoT client === Control services ==== start IoT server [source.bash] ---- cd iot-swarm-example ./start-iotserver.sh ---- ==== stop IoT server [source.bash] ---- cd iot-swarm-example ./stop-iotserver.sh ---- ==== start IoT webclient [source.bash] ---- cd iot-swarm-example ./start-iotwebclient.sh ---- ==== stop IoT webclient [source.bash] ---- cd iot-swarm-example ./stop-iotwebclient.sh ---- ==== Use webclient open in Browser: http://localhost:8080 and open Web Developer with ctrl+shift+K type text in _"Get iot Data"_ and klick on it See in - *Console* in browser - and in Linux *Terminal* == Technologies === MVC A core principle of the MVC pattern is the view layer's ignorance with respect to the model layer. Views are dumb objects. They only know how to present data to the user. They don't know or understand what they are presenting. MVC: Division across three code components only: Model, View, and Controller. ... Microservices: An app is divided into a set of specialized classes that interact with each other using APIs. This model is being used by companies like Netflix, Spotify, and eBay. Model: This part manages the data on your site. Its role is to retrieve the raw information from the database, organize, and assemble it so that it can be processed by the controller. View: This part focuses on the display. It is here where the data recovered by the model will be presented to the user. Controller: This part manages the logic of the code and makes decisions. When the user interacts with the view, the request is processed by the controller. It waits for the user to interact with the view to retrieve the request. Thus, it is the controller that will define the display logic, and display the next view on the screen. === Microservices Architecture Microservices can be defined as an improvement, a kind of refinement, of what we know as service-oriented architecture (SOA). In this architecture, a large application is made in the form of small monofunctional modules. Each microservice is autonomous. Microservices do not share a data layer. Each has its own database and load balancer. So that each of these services can be deployed, adjusted, and redeployed individually without jeopardizing the integrity of an application. As a result, you will only need to change a couple self-contained services instead of having to redeploy the entire application. == Software === Client site (PC) ==== Vue .vuejs [NOTE] ==== Vue.js is an open-source, progressive JavaScript framework for building user interfaces (UIs) and single-page applications. ==== *Library modularization* using a framework is common in frontend development. What differentiates Vue.js from other alternatives is: - its *“high decoupling”*, how easy it is to extend functionalities, and how well all parts work once more modules are included. For example, if we want to organize and render small visual components, all we need is Vue.js’s ‘core’ library. It is not necessary to include additional libraries. As the application grows, - we have libraries to manage *routes* such as *‘vue-router’*, - libraries to manage the global state such as *‘vuex’* - and libraries to build responsive web applications such as *‘bootstrap-vue’*. - Additionally, if our application needs to be optimized or needs good SEO, we can include the *‘vue-server-rendering’* library. In the following figure, we can see how the libraries we just mentioned are progressively included, from a small SPA to multi-page applications (MPA). image::./intro.png[intro] TIP: The name of the framework – Vue – is the same phonetically in English as view, and it corresponds to the traditional Model-View-Controller (MVC) architecture React and Angular are other Frameworks similar to vuejs ==== Vuex Vuex is a state management pattern + library for Vue.js applications. - It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion. - It also integrates with Vue's official devtools extension to provide advanced features such as zero-config time-travel debugging and state snapshot export / import. .What is a "State Management Pattern"? [NOTE] ==== *Let's start with a simple Vue counter app:* [source,javascript] ---- new Vue({ // state data () { // <1> return { count: 0 } }, // view template: ` // <2>