Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Panel
titleGoal

Anchor
1
1

We will create a simple IoT system that will alert us through a nice web interface whenever the temperature at our wine cellar is not between 10°C and 16°C. We will call this system FineWine.

System architecture:


This system, based on our understanding of intelligent micro-system, is composed of the following organs:

  • Nerve center: where the hub and its data are located.
  • Admin dashboard: the administration interface of your hub.
  • VirtualTemperatureSensor organ: simulate the temperature sensor of the wine cellar continuously and synchronize the samples with the hub.
  • Analytics organ: analyzes the temperature and alerts if the temperature is ok or not.
  • Monitoring interface organ: a web interface, displaying the current status of our wine cellar.


Panel
titleCreating a new Spinal System

Anchor
2
2

Install spinal-system-basic

The first step is to create the directory where the project will be stored. We will call it fine-wine-system. Then, install inside the “spinal-system-basic” template. We suggest that before running the following command you initialize an npm project (with npm init):

Code Block
languagebash
themeDJango
~/$  mkdir fine-wine-system
~/$ cd fine-wine-system
~/fine-wine-system$ npm init -y
~/fine-wine-system$ npm i https://github.com/spinalcom/spinal-browser-admin.git

Launch spinal-system

Code Block
languagebash
themeDJango
~/fine-wine-system$ pm2 start launch.config.js

PM2 will automatically start the Spinal Hub and the organs. Take care, if you have another hub running on port 7777, your new hub will not be launched ! (here is a command to see what port are used on ubuntu: sudo netstat -lp --inet)

After this installation, only SpinalHub is running on port 7777. SpinalHub containes a web server that provide his own Admin interface. Here is the architecture of the system you have after this first install:

Connect to Admin UI

As we have done in the getting started, connect to the admin dashboard to see if you hub is running :

http://127.0.0.1:7777/html/admin

The default admin account is :


Panel
titleCreate your wine cellar digital twin

Anchor
3
3

The digital twin will be defined in the libraries.

The model is very simple, since we will not manage a lot of data. It is just a JavaScript function, which we will assume it's a class, from where we can create instances and store and load data.

The three important points to follow in the creation of a model are:

  • The first instruction of the function must call the super() method passing its context as an argument. As this function will inherit from a Model class inside the SpinalCore library, we need to call the parent constructor.
  • Every argument that needs to be synchronized should be passed using the add_attr() method like in the example below.
  • To inherit from the Model class, we call the extend() method from the SpinalCore library.

Create a folder called spinal-model-wine-cellar at the root of your project and, inside it, create a file called model.js:


Code Block
languagebash
~/fine-wine-system$  mkdir spinal-model-wine-cellar

spinal-model-wine-cellar/model.js


Code Block
languagejs
themeDJango
linenumberstrue
// wineCave-model.js

function WineCellarModel() {
    WineCellarModel.super(this);

    this.add_attr({
        temperature: 0,
        danger: false
    });
}

spinalCore.extend(WineCellarModel, Model);
module.exports = WineCellarModel;



Panel
titleCreate our new virtualButton organ

Anchor
4
4


Panel
titleLaunch the system

Anchor
5
5


Panel
titleCreate our second organ : virtualButtonMonitor

Anchor
6
6


Conclusion