Versions Compared

Key

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


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)In this tutorial we will introduce the "browser organ" with a user interface: the drive and the viewer.

System architecture:
Image Added
Panel
titleGoal of this tutorial

Anchor
1
1

Description du systeme

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.

Image Removed

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
22


Panel
titleRequirements

For this tutorial you must have done the Basic Automate Tutorial


Panel
titleSet up the drive

Anchor
2
2

A. Installation

First we need to install the Spinalcom Drive :

Code Block
languagebash
themeDJango
~/equipment-system$ npm i -s https://github.com/spinalcom/spinal-browser-drive

B. Share the Automate file

We're going to share the file "Automate" so, as a standard user, you can access your data in your drive.

First right click on the file "Automate" and choose share.

Image Added


Then give read, write and share rights to admin in the menu that appeared.

Image Added

To access the drive just change the url to http://localhost:7777/html/drive

Go in the folder "shared_with_me" and you should see the file Automate.


Panel
titleDiscover the viewer

Anchor
3
3

Now we will install the Spinal Viewer.

You can have more informations to how to setup the Autodesk Forge account and import a 3D file (rvt, ifc, etc...) in our drive here.


Code Block
languagebash
themeDJango
$ npm install -s https://github.com/spinalcom/spinal-browser-viewer



fine-wine-system Folder organization

Image Removed

  • .browser_organs : This is your web browser folder

  • .config_env : Your env configuration

  • nerve-center : The Spinalcom nerve center

  • node_modules : npm (node package manager) & spinal-package

  • .apps.json : installed package of your spinal system

  • .config.json : spinalcom connection configuration file

  • launch.config.js : Start your hub using pm2

  • package.json : config of your package

Panel
titleInstall your first plugin

Anchor
4
4

Now that you've seen the basics, let's try to install a plugin. Download and rename this example:

Code Block
languagebash
themeDJango
~/$ mkdir button-systemsystem$ ~/$git cd button-system
clone https://gist.github.com/Diclah/2887ee1bcf1353d9615a1dcf4c6a0128
~/button-system$ npmmv init -y
2887ee1bcf1353d9615a1dcf4c6a0128 spinal-env-viewer-plugin-sample

Don't forget to rename it in its package.json.

spinal-env-viewer-plugin-sample/package.json

Code Block
languagejs
themeDJango
firstline2
linenumberstrue
  "name": "spinal-env-viewer-plugin-sample",

Now install it:

Code Block
languagebash
themeDJango
~/button-system$ npm i https://github.com/spinalcom/spinal-browser-admin.git
Launch spinal-system
-s spinal-env-viewer-plugin-sample

Edit or create .config_env/viewer.json and add your new plugin to the list of viewer plugins.

.config_env/viewer.json

Code Block
languagejs
themeDJango
linenumberstrue
{
  "spinal-env-viewer-plugin-sample": "1.0.0"
}

Now use create_viewer_env binary to configure the viewer.

Code Block
languagebash
themeDJango
~/button-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 :

Username

client ID

Password
admin168JHGgcz45JKilmzknzelf65ddDadggftIO98P
Panel
titleCreate a data model
Anchor
33
Panel
titleCreate our new virtualButton organ
Anchor
44
Panel
titleLaunch the system
Anchor
55
Panel
titleCreate our second organ : virtualButtonMonitor
Anchor
66
Conclusion
/node_modules/.bin/create_viewer_env

Reload the spinal viewer and the plugin should appear in the form of a button.

Image Added

Once you press it a small window will appear.

Image Added


Panel
titleModify your plugin

Anchor
5
5

This first plugin isn't really impressive, let's improve it. We're going to make it display the equipments from our Automate list.

To modify it, go to spinal-env-viewer-plugin-sample.

spinal-env-viewer-plugin-sample/testExtention.vue

Code Block
languagejs
themeDJango
linenumberstrue
<template>
<!-- 1: Add an md-element -->
  <md-content class="container md-scrollbar">
    <div>
      hey {{testHello}} - {{count}}
      <md-button @click="getSelection">
        TEST GET SELECTION
      </md-button>
      <md-button @click="logForgeFile">
        TEST GET ForgeFile
      </md-button>
    </div>
<!-- 2: Display the id, name, hydrometry, temperature and state of all equipments in the list -->
    <md-table>
      <md-table-row>
        <md-table-cell>Id</md-table-cell>
        <md-table-cell>Name</md-table-cell>
        <md-table-cell>Hygrometry</md-table-cell>
        <md-table-cell>Temperature</md-table-cell>
     </md-table-row>
      <md-table-row v-for="item in this.list"
                    :key="item._server_id">
        <md-table-cell>{{item.id.get()}}</md-table-cell>
        <md-table-cell>{{item.name.get()}}</md-table-cell>
        <md-table-cell>{{item.hygrometry.get()}}</md-table-cell>
        <md-table-cell>{{item.temperature.get()}}</md-table-cell>
      </md-table-row>
    </md-table>
  </md-content>
</template>

<script>
function loop(func) {
  func();
  setTimeout(() => {
    loop(func);
  }, 1000);
}

// 3: Load Automate from the drive and fill the list with its elements
function loadList() {
  this.spinalSystem.load("/__users__/admin/shared_with_me/Automate").then(
    automate => {
      this.equip = automate.sensors;
      for (let i = 0; i < automate.sensors.length; i++) {
        this.list.push(automate.sensors[i]);
      }
    },
    () => {
      console.log("error: could not load Automate");
    }
  );
}

export default {
  name: "testExtention",

  data() {
	this.spinalSystem;
	this.viewer;
    this.equip;
    return {
      testHello: "HELLO WORLD",
      count: 0,
// 4: The list array which will contain the equipments
      list: []
    };
  },
  methods: {
    getSelection: function() {
      let selection = this.viewer.getSelection();
      console.log(selection);
    },
    logForgeFile: function() {
      this.spinalSystem.getModel().then(forgefile => {
        console.log(forgefile);
      });
    }
  },
  created() {
    this.spinalSystem = window.spinal.spinalSystem;
    this.viewer = window.spinal.ForgeViewer.viewer;
  },
  mounted() {
// 5: Call to loadList
	loadList.call(this);

    let vm = this;
    loop(() => {
      vm.count += 1;
    });
  }
};
</script>

<style>
/* 6: Create the container style */
.container {
  height: calc(100% - 48px);
  overflow-y: auto;
  box-sizing: border-box;
}
</style>

Don't forget to execute ./node_modules/.bin/create_viewer_env and to reload spinal-env-viewer-plugin-sample or your changes won't show.

Image Added


Conclusion


In this tutorial you learned:

  • how to use the spinal drive
  • how to use the spinal viewer
  • how to install and modify your spinal viewer plugin


This tutorial will be continued in /wiki/spaces/DOC/pages/42926106.