wb_editors
42
правки
(Новая страница: «=== User fields in the interface ===») |
Sikmir (обсуждение | вклад) |
||
(не показана 41 промежуточная версия 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/ | 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/ | #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/ | #[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/ | 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/ | 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/ | [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 | === 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/ | 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. | ||
Строка 699: | Строка 699: | ||
=== User fields in the interface === | === User fields in the interface === | ||
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 forum]. | |||
=== | === Complex scheduled rules === | ||
Object - grocery store. Various store systems are controlled by feedback from temperature sensors and taking into account the schedule of the store. | |||
Not cron-rules are used for schedules, but the libschedule. The libschedule enables and disables rules, which, unlike cron rules, are executed continuously when enabled. | |||
For example, we want the lighting to be on from 10 to 17h. The libschedule will follow the "turn on the lights" rule once a minute from 10 am to 17 PM. | |||
This means that even if the controller works intermittently and missed the transition time between schedules (10 am), the controller will still turn on the lighting as soon as possible. | |||
Строка 721: | Строка 721: | ||
global.__proto__.Schedules = {}; | global.__proto__.Schedules = {}; | ||
(function(Schedules) { // | (function(Schedules) { // closing | ||
function todayAt(now, hours, minutes) { | function todayAt(now, hours, minutes) { | ||
Строка 861: | Строка 861: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
An example of a rule using Schedules: | |||
<syntaxhighlight lang="ecmascript"> | <syntaxhighlight lang="ecmascript"> | ||
(function() { // | (function() { // closing | ||
defineAlias("countersTemperature", "wb-msw2_30/Temperature"); | defineAlias("countersTemperature", "wb-msw2_30/Temperature"); | ||
Строка 915: | Строка 915: | ||
Schedules.initSchedules(); | Schedules.initSchedules(); | ||
// | // signboard and facade illumination | ||
defineRule("signboardOnOff", { | defineRule("signboardOnOff", { | ||
when: function() { | when: function() { | ||
Строка 931: | Строка 931: | ||
// | // sales area illumination | ||
defineRule("lightingFrontshopOnOff", { | defineRule("lightingFrontshopOnOff", { | ||
when: function() { | when: function() { | ||
Строка 938: | Строка 938: | ||
then: function (newValue, devName, cellName) { | then: function (newValue, devName, cellName) { | ||
log("lightingFrontshopOnOff newValue={}, devName={}, cellName={}", newValue, devName, cellName); | log("lightingFrontshopOnOff newValue={}, devName={}, cellName={}", newValue, devName, cellName); | ||
dev["wb-gpio/EXT1_R3A1"] = ! dev._schedules.frontshop_lighting; // | dev["wb-gpio/EXT1_R3A1"] = ! dev._schedules.frontshop_lighting; //inverted contactor | ||
} | } | ||
}); | }); | ||
// | // backstoreroom ventilation | ||
defineRule("ventBackstoreOnOff", { | defineRule("ventBackstoreOnOff", { | ||
when: function() { | when: function() { | ||
Строка 951: | Строка 951: | ||
log("ventBackstoreOnOff newValue={}, devName={}, cellName={}", newValue, devName, cellName); | log("ventBackstoreOnOff newValue={}, devName={}, cellName={}", newValue, devName, cellName); | ||
var on = dev._schedules.ext_working_hours_15m; | var on = dev._schedules.ext_working_hours_15m; | ||
dev["wb-mr6c_81/K1"] = ! on; // | dev["wb-mr6c_81/K1"] = ! on; //inverted contactor | ||
dev["wb-mr6c_81/K5"] = ! on; // | dev["wb-mr6c_81/K5"] = ! on; //inverted contactor | ||
} | } | ||
}); | }); | ||
// | // Freezer showcase illumination | ||
defineRule("lightingCoolingshelfsOnOff", { | defineRule("lightingCoolingshelfsOnOff", { | ||
when: function() { | when: function() { | ||
Строка 965: | Строка 965: | ||
var on = dev._schedules.working_hours_15m; | var on = dev._schedules.working_hours_15m; | ||
// | // | ||
the lighting in the freezer showcases via the normally-closed relays (inverted) | |||
dev["wb-mrm2-old_60/Relay 1"] = !on; | dev["wb-mrm2-old_60/Relay 1"] = !on; | ||
dev["wb-mrm2-old_61/Relay 1"] = !on; | dev["wb-mrm2-old_61/Relay 1"] = !on; | ||
Строка 978: | Строка 979: | ||
// | //Display fridges | ||
defineRule("powerBrandFridgesOnOff", { | defineRule("powerBrandFridgesOnOff", { | ||
when: function() { | when: function() { | ||
Строка 987: | Строка 988: | ||
var on = dev._schedules.working_hours; | var on = dev._schedules.working_hours; | ||
dev["wb-gpio/EXT1_R3A5"] = !on; // | dev["wb-gpio/EXT1_R3A5"] = !on; // inverted | ||
} | } | ||
}); | }); | ||
// ========= | // ========= Boilers and supply ventilation =========== | ||
// | // feedback by the temperature of the vegetable zone | ||
// | // position controller works daily | ||
defineRule("heatersDayOff", { | defineRule("heatersDayOff", { | ||
when: function() { | when: function() { | ||
Строка 1002: | Строка 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 | ||
} | } | ||
}); | }); | ||
Строка 1012: | Строка 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() { | ||
Строка 1023: | Строка 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 | ||
} | } | ||
}); | }); | ||
Строка 1033: | Строка 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", { | ||
Строка 1049: | Строка 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", { | ||
Строка 1059: | Строка 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() { | ||
Строка 1070: | Строка 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 ============== | ||
// | // Cooling vegetables air-conditioned only when the air temperature is above 18.5 C | ||
defineRule("acVegOn", { | defineRule("acVegOn", { | ||
Строка 1083: | Строка 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; // | dev["wb-mir_76/Play from ROM3"] = true; // Cooling +18 | ||
} | } | ||
}); | }); | ||
Строка 1093: | Строка 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 | ||
} | } | ||
}); | }); | ||
Строка 1101: | Строка 1102: | ||
== | == A full description of the capabilities of the rules engine == | ||
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| | * [[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| | * [[Special:MyLanguage/Движок_правил_wb-rules_2.0/en|Rules engine wb-rules 2.0]] |