Движок правил wb-rules/en: различия между версиями

Нет описания правки
(Новая страница: «// ========= Boilers and supply ventilation =========== // feedback by the temperature of the vegetable zone»)
 
(не показаны 23 промежуточные версии 2 участников)
Строка 3: Строка 3:
  You can write rules for the controller, for example: "If the sensor temperature is less than 18°C, turn on the heater." Rules are created via [[Веб-интерфейс Wiren Board/en|web interface]] and written in a simple language similar to Javascript.
  You can write rules for the controller, for example: "If the sensor temperature is less than 18°C, turn on the heater." Rules are created via [[Веб-интерфейс Wiren Board/en|web interface]] and written in a simple language similar to Javascript.


The complete description of the rules engine: https://github.com/contactless/wb-ruleshttps://github.com/contactless/wb-rules
The complete description of the rules engine: https://github.com/wirenboard/wb-rules




Строка 15: Строка 15:
Notes:
Notes:
#The rules files are stored on the controller as plain text files in the <code>/etc/wb-rules/</code> folder, so they [[Просмотр файлов контроллера с компьютера/en|can be edited and downloaded]] directly from your computer.
#The rules files are stored on the controller as plain text files in the <code>/etc/wb-rules/</code> folder, so they [[Просмотр файлов контроллера с компьютера/en|can be edited and downloaded]] directly from your computer.
#The rules are executed by the ''wb-rules'' service, see the service's [https://github.com/contactless/wb-rules documentation on Github].
#The rules are executed by the ''wb-rules'' service, see the service's [https://github.com/wirenboard/wb-rules documentation on Github].






== Writing the first rule==
== Writing the first rule ==


[[File:Web-scripts-rule1.png|400px|thumb|The rule for the heater control, written via the web interface]]
[[File:Web-scripts-rule1.png|400px|thumb|The rule for the heater control, written via the web interface]]
Строка 86: Строка 86:
#* on the same page below;
#* on the same page below;
#* in [http://forums.contactless.ru/t/dvizhok-pravil-primery-koda/483  a special topic on our forum(ru)].
#* in [http://forums.contactless.ru/t/dvizhok-pravil-primery-koda/483  a special topic on our forum(ru)].
#[https://github.com/contactless/wb-rules Full description of the rules engine].
#[https://github.com/wirenboard/wb-rules Full description of the rules engine].




Строка 386: Строка 386:
Some rules come with the default rule system in the wb-rules-system package.  
Some rules come with the default rule system in the wb-rules-system package.  


Full list of rules is[https://github.com/contactless/wb-rules-system/tree/master/rules in the repository.].
Full list of rules is [https://github.com/wirenboard/wb-rules-system/tree/master/rules in the repository.].


Some examples:
Some examples:
Строка 394: Строка 394:
==== The rule for the buzzer====
==== The rule for the buzzer====


[https://github.com/contactless/wb-rules-system/blob/master/rules/buzzer.js Rule] creates a virtual buzzer device with sliders to adjust the volume and frequency, as well as a button to turn on the sound.
The [https://github.com/wirenboard/wb-rules-system/blob/master/rules/buzzer.js rule] creates a virtual buzzer device with sliders to adjust the volume and frequency, as well as a button to turn on the sound.




Строка 469: Строка 469:
==== Power status rule ====
==== Power status rule ====


[https://github.com/contactless/wb-rules-system/blob/master/rules/power_status.js The rule]   creates a virtual device that reports the current power status. Two ADC channels are used as input data: battery voltage measurement and input voltage measurement.
[https://github.com/wirenboard/wb-rules-system/blob/master/rules/power_status.js The rule] creates a virtual device that reports the current power status. Two ADC channels are used as input data: battery voltage measurement and input voltage measurement.


The following logic is implemented:
The following logic is implemented:
Строка 537: Строка 537:




=== Sending commands viaRS-485 ===
=== Sending commands via RS-485 ===


For example, send a command to the device on the port /dev/ttys0 (corresponds to the hardware port RS-485-ISO on the [[Special:MyLanguage/Wiren Board 4|Wiren Board 4]]). To do this, we will use the rules engine and the ability to execute arbitrary shell commands. See [https://github.com/contactless/wb-rules#%D0%94%D1%80%D1%83%D0%B3%D0%B8%D0%B5-%D0%BF%D1%80%D0%B5%D0%B4%D0%BE%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D1%91%D0%BD%D0%BD%D1%8B%D0%B5-%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D0%B8-%D0%B8-%D0%BF%D0%B5%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D1%8B%D0%B5 documentation] for details.
For example, send a command to the device on the port /dev/ttys0 (corresponds to the hardware port RS-485-ISO on the [[Special:MyLanguage/Wiren Board 4|Wiren Board 4]]). To do this, we will use the rules engine and the ability to execute arbitrary shell commands. See [https://github.com/wirenboard/wb-rules#%D0%94%D1%80%D1%83%D0%B3%D0%B8%D0%B5-%D0%BF%D1%80%D0%B5%D0%B4%D0%BE%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D1%91%D0%BD%D0%BD%D1%8B%D0%B5-%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D0%B8-%D0%B8-%D0%BF%D0%B5%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D1%8B%D0%B5 documentation] for details.


Create a virtual device with switch type control via rules engine.  
Create a virtual device with switch type control via rules engine.  
Строка 701: Строка 701:
To enable the user to enter exact parameter values (setpoints) from the interface, you can use the [https://wirenboard.com/wiki/index.php/%D0%A1%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5_%D1%80%D0%B5%D0%B4%D0%B0%D0%BA%D1%82%D0%B8%D1%80%D1%83%D0%B5%D0%BC%D1%8B%D1%85_%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D1%82%D0%B5%D0%BB%D1%8C%D1%81%D0%BA%D0%B8%D1%85_%D0%BF%D0%BE%D0%BB%D0%B5%D0%B9_%D0%B2_%D0%B2%D0%B5%D0%B1-%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D1%84%D0%B5%D0%B9%D1%81%D0%B5 instruction].
To enable the user to enter exact parameter values (setpoints) from the interface, you can use the [https://wirenboard.com/wiki/index.php/%D0%A1%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5_%D1%80%D0%B5%D0%B4%D0%B0%D0%BA%D1%82%D0%B8%D1%80%D1%83%D0%B5%D0%BC%D1%8B%D1%85_%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D1%82%D0%B5%D0%BB%D1%8C%D1%81%D0%BA%D0%B8%D1%85_%D0%BF%D0%BE%D0%BB%D0%B5%D0%B9_%D0%B2_%D0%B2%D0%B5%D0%B1-%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D1%84%D0%B5%D0%B9%D1%81%D0%B5 instruction].


More detailed and with example - in the topic on the technical support [https://support.wirenboard.com/t/kak-na-wb5-wb6-sozdat-pole-dlya-vvoda-ustavok-i-peredat-znachenie-v-pravila/2180 portal].
More detailed and with example - in the topic on the technical support [https://support.wirenboard.com/t/kak-na-wb5-wb6-sozdat-pole-dlya-vvoda-ustavok-i-peredat-znachenie-v-pravila/2180 forum].




Строка 996: Строка 996:
   // feedback by the temperature of the vegetable  zone
   // feedback by the temperature of the vegetable  zone


   // днём работает позиционный регулятор
   // position controller works daily
   defineRule("heatersDayOff", {
   defineRule("heatersDayOff", {
     when: function() {
     when: function() {
Строка 1003: Строка 1003:
     then: function (newValue, devName, cellName) {
     then: function (newValue, devName, cellName) {
       log("heatersDayOff  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       log("heatersDayOff  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       heater1EnableInverted = !false; // инвертировано
       heater1EnableInverted = !false; // inverted
     }
     }
   });
   });
Строка 1013: Строка 1013:
     then: function (newValue, devName, cellName) {
     then: function (newValue, devName, cellName) {
       log("heatersDayOn  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       log("heatersDayOn  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       heater1EnableInverted = !true; // инвертировано
       heater1EnableInverted = !true; // inverted
     }
     }
   });
   });


   // ночью работает позиционный регулятор
   // position controller works at night
   defineRule("heatersNightOff", {
   defineRule("heatersNightOff", {
     when: function() {
     when: function() {
Строка 1024: Строка 1024:
     then: function (newValue, devName, cellName) {
     then: function (newValue, devName, cellName) {
       log("heatersNightOff  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       log("heatersNightOff  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       heater1EnableInverted = !false; // инвертировано
       heater1EnableInverted = !false; // inverted
     }
     }
   });
   });
Строка 1034: Строка 1034:
     then: function (newValue, devName, cellName) {
     then: function (newValue, devName, cellName) {
       log("heatersNightOn  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       log("heatersNightOn  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       heater1EnableInverted = !true; // инвертировано
       heater1EnableInverted = !true; // inverted
     }
     }
   });
   });




   // приточная и вытяжная вентиляция принудительно выключены
   // supply and exhaust ventilation are forcibly switched off
    
    
   defineRule("ventFrontshopAlwaysOff", {
   defineRule("ventFrontshopAlwaysOff", {
Строка 1050: Строка 1050:
    
    
    
    
   // ==================  Кассовая зона =================
   // ==================  The cash register area =================


   // в кассовой зоне в рабочее время температура поддерживается кондиционерами (позиционный регулятор)
   // in the cash area during working hours the temperature is maintained by air conditioning (position controller)


   defineRule("countersACOn", {
   defineRule("countersACOn", {
Строка 1060: Строка 1060:
     then: function (newValue, devName, cellName) {
     then: function (newValue, devName, cellName) {
       log("countersACOn  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       log("countersACOn  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       dev["wb-mir_75/Play from ROM7"] = true; // кондиционер кассовой зоны на нагрев
       dev["wb-mir_75/Play from ROM7"] = true; // air conditioning cash area for heating
     }
     }
   });
   });


   // в нерабочее время кондиционер выключен
   // after working hours, the air conditioning is off
   defineRule("countersACOff", {
   defineRule("countersACOff", {
     when: function() {
     when: function() {
Строка 1071: Строка 1071:
     then: function (newValue, devName, cellName) {
     then: function (newValue, devName, cellName) {
       log("countersACOff  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       log("countersACOff  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       dev["wb-mir_75/Play from ROM2"] = true; // кондиционер кассовой зоны выключить
       dev["wb-mir_75/Play from ROM2"] = true; // shut down air conditioning cash area
     }
     }
   });
   });


   // =============== Овощная зона ==============
   // =============== Vegetable zone ==============
   // Охлаждение овощей кондиционером только при температуре воздуха выше 18.5C  
   // Cooling vegetables air-conditioned only when the air temperature is above 18.5 C  


   defineRule("acVegOn", {
   defineRule("acVegOn", {
Строка 1084: Строка 1084:
     then: function (newValue, devName, cellName) {
     then: function (newValue, devName, cellName) {
       log("acVegOn  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       log("acVegOn  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       dev["wb-mir_76/Play from ROM3"] = true; // Охлаждение +18
       dev["wb-mir_76/Play from ROM3"] = true; // Cooling +18
     }
     }
   });
   });
Строка 1094: Строка 1094:
     then: function (newValue, devName, cellName) {
     then: function (newValue, devName, cellName) {
       log("acVegOff  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       log("acVegOff  newValue={}, devName={}, cellName={}", newValue, devName, cellName);
       dev["wb-mir_76/Play from ROM2"] = true; // выключить
       dev["wb-mir_76/Play from ROM2"] = true; // shutdown
     }
     }
   });
   });
Строка 1102: Строка 1102:




== Полное описание возможностей движка правил ==
== A full description of the capabilities of the rules engine ==


Самое полное описание движка правил: https://github.com/contactless/wb-rules/blob/master/README.md
The most complete description of the rules engine: https://github.com/wirenboard/wb-rules/blob/master/README.md






== Новые возможности последних версий ==
== What's new in the latest versions ==


* [[Special:MyLanguage/Движок_правил_wb-rules_1.7|Движок правил wb-rules 1.7]]
* [[Special:MyLanguage/Движок_правил_wb-rules_1.7/en|wb-rules 1.7 rules engine]]






== В разработке ==
== under development ==


Описание возможностей будущих версий движка правил можно прочесть здесь:
A description of the features of future versions of the rules engine can be found here:
* [[Special:MyLanguage/Движок_правил_wb-rules_2.0|Движок правил wb-rules 2.0]]
* [[Special:MyLanguage/Движок_правил_wb-rules_2.0/en|Rules engine wb-rules 2.0]]
wb_editors
33

правки