16 293
правки
(Новая страница: «=== MQTT topic value === The value from the MQTT topic specified in the '''Channel''' field is placed into the '''val''' variable.») Метки: правка с мобильного устройства правка из мобильной версии |
(Новая страница: «The option '''Stretch to full screen''' will fit the panel to the free space.») |
||
Строка 93: | Строка 93: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
For example, if the value of the MQTT topic is equal to <code>1</code> , then print the value <code>ВКЛ</code> , otherwise — <code>ОТКЛ</code> : | |||
<syntaxhighlight lang="javascript"> | |||
<syntaxhighlight lang="javascript"> | (val == 1) ? 'ON' : 'OFF' | ||
(val | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Arithmetic operations === | |||
Simple arithmetic operations can be performed on a topic received from an MQTT topic: | |||
* <code>+</code> — addition | |||
* <code>+</code> — | * <code>-</code> — subtraction | ||
* <code>-</code> — | * <code>*</code> — multiplication | ||
* <code>*</code> — | * <code>/</code> — division | ||
* <code>/</code> — | |||
For example, output the value <code>АВАРИЯ</code> if the value in the MQTT topic multiplied by 0.1 is greater than 20 and <code>НОРМА</code> otherwise: | |||
<syntaxhighlight lang="javascript"> | |||
<syntaxhighlight lang="javascript"> | (val*0.1>20) ? 'ALARM' : 'NORMAL' | ||
(val*0.1>20) ? ' | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Rounding values === | |||
== | Often, values from sensors come with several decimal places, if you do not need such accuracy in the svg panel, then they can be rounded: | ||
<syntaxhighlight lang="javascript"> | |||
<syntaxhighlight lang="javascript"> | val.toFixed(n) //round the value of the variable val to n decimal places | ||
val.toFixed(n) // | val.toFixed(2) //round the value of the variable val to two decimal places 220.238 → 220.24 | ||
val.toFixed(2) // | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<div lang="ru" dir="ltr" class="mw-content-ltr"> | <div lang="ru" dir="ltr" class="mw-content-ltr"> |