Panel | ||||||
---|---|---|---|---|---|---|
| ||||||
In the previous tutorial we created a list of 2 equipmentssensors. In this tutorial we're going to create an organ which will make equipments sensors for us and 2 two automates to handle this new list. System architecture: |
Panel | ||
---|---|---|
| ||
To follow this tutorial you must have done the Basic Equipment Tutorial. |
Panel | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||
In this part we will create another model a new model, named an "automate", that will be in charge of a group of equipmentsensors. This model needs 2 attributes:
We're going to add an empty array named automates as property of the equipementList model SensorListModel and create a model automate which has a name and a array of equipement as Automate with the two previously described attributes. spinal-model/model Take care of SensorListModel, an automate as been added to the model. spinal-models/models.js
|
Panel | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||
Before we can use our new model we're going to need equipments sensors for them to handle. The createEquipment createSensor organ will create 10 equipments virtual sensors in a new list stored as in the file "automateAutomate". createEquipmentCreate a folder called createSensor and add a file called index.js inside. createSensor/index.js
Install spinal-core-connectorjs from GitHub. You can test it to see if it is working fine. Code Block | | |||||||||||||||
|
Panel | |||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||||||||||
We are now going to create 2 automates. Each one will be in charge of 5 equipment sensors from the list. Both will periodically choose one of their equipment sensors and change its hydrometry hygrometry and temperature. Automate 1Create a new organ named "automate1". Create two folders, called automate1 and automate2 and inside, create a file index.js. Don't forget to install spinal-core-connectorjs from GitHub, inside the two folders. Automate 1automate1/index.js
automate1/index.js
Automate 2Automate2 will be almost identical to automate1 so I suggest you start by copying automate1 and modify the file as follow.
There are very few changes to make to index.js so I will point them out instead of explaining everything again.
|
Panel | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||
Don't forget to add all this new organs to your .apps.json if it isnyou wan't already doneto use pm2 to launch them. .apps.json
2 new automates with 5 equipment sensors each should have appeared in your list. You can compare the equipments sensors in the equipments array and those in the automates to verify that they correspond. |
Panel | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||
We now have 2 automates that change the data of equipmentstheir sensors. Let's add analytic to the press function to catch those modifications. We will change the press function in both so that when the hydrometry hygrometry exceeds 70% or the temperaturetemperature exceeds 20°, it will create a alert log. automate1/index.js
automate2/index.js
automate2/index.js
Now use pm2 restart and pm2 log to see when an equipment is in dangerunder alarm.
You should see something like this. |
Conclusion
In this tutorial you learned how to:
- Automatically created equipments create sensors using an organ
- Created 2 automates to handle the equipmentssensors
- Made those automates display warnings if a problem occurs
This tutorial will be continued in Get your Automate in the viewer.
...