Categories
HowTo's VSCP

#VSCP HOWTO: Min/max

Quite often one want to store min and max for measurement values  So of course you can do that with the VSCP server just by adding a row to the decision matrix.

The first thing you need is a remote variable to store the min/max in. You can add this remote variable to the variable xml file so it is created when the system starts or add it as a persistent variable to the database. Another way is to create the variable when the server starts right is the DM. We  use the last method here as it is makes things clearer in this how-to.

You can create a remote variable minimum and another maximum with the following two DM rows which triggers on the CLASS2.VSCPD, Type=23 Starting up  which is feed to the DM once when the VSCP server is started. .

<row enable="true" groupid="Min/max" >

<comment>
 Create variable that hold min
 when the server is started 
 ( CLASS2.VSCPD, Type=23 ).
 </comment>

<mask priority="0"
 class="0xFFFF"
 type="0xFFFF"
 GUID=" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" />

<filter priority="0"
 class="65535"
 type="23"
 GUID=" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" />

<action>0x50</action>
 <param>
 minimum;float;false;0;0x777;9999999;BASE64:test min
 </param>

</row>
 
 <row enable="true" groupid="Min/max" >

<comment>
 Create variable that hold min
 when the server is started ( CLASS2.VSCPD, Type=23 ).
 </comment>

<mask priority="0"
 class="0xFFFF"
 type="0xFFFF"
 GUID=" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" />

<filter priority="0"
 class="65535"
 type="23"
 GUID=" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" />

<action>0x50</action>
 <param>
 maximum;float;false;0;0x777;-999999;BASE64:test max
 </param>

</row>

Here the  minimum variable is created as a non-persistent variable (it will not hold its value between sessions), it is created as a float and initiated to a “very high” value (9999999), The maximum variable is also created as a float and initiated to a “very low” number (-999999).

You can read more about the store remote variable action here.

The values for the minimum and maximum variables is selected so that minimum is initiated to a value that is higher than what is expected to be a lowest value that will be received by the system and the same for the maximum but the other way around.

So no we have the two variables. Suppose we now want to check the maximum and minimums for a temperature.  This means that we will look for a measurement event  with type = 6 temperature.  I write “measurement event” here as they come in a couple of flavors.  A DM row  like the following will handle the collection of minimum data

<row enable="true" groupid="Min/max" >

<comment>
 Test for minimum
 </comment>

<mask priority="0" 
 class="0xFFFF" 
 type="0xFFFF" 
 GUID=" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" />

<filter priority="0" 
 class="10" 
 type="6" 
 GUID=" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" />

<action>0x71</action>
 <param>
 minimum;1;1
 </param>

</row>

Here we filter on CLASS1.MEASUREMENT, Type=6 temperature (class=10, type=6) from any sensor (we normally should have selected on by entering a GUID for it).  The action 0x71 is the

VSCP_DAEMON_ACTION_CODE_STORE_MIN

and it will store the temperature value of the incoming VSCP event if it is lower than the value currently stored in the remote variable minimum. The 1,1 after the variable name  in the parameter says that the measurement should have unit=1 (Celsius in this case) and originate from sensor with index=1 on the remote node,

For the maximum the DM row looks like

<row enable="true" groupid="Min/max" >

<comment>
 Test for maximum
 </comment>

<mask priority="0" 
 class="0xFFFF" 
 type="0xFFFF" 
 GUID=" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" />

<filter priority="0" 
 class="10" 
 type="6" 
 GUID=" 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" />

<action>0x72</action>
 <param>
 maximum;1;1
 </param>

</row>

The functionality is the same except that the

VSCP_DAEMON_ACTION_CODE_STORE_MAX

action is used here which compares the names variable for a highest value instead of a lowest value.

That it. We now have to variables maximum and minimum that  holds the maximum and minimum values for the temperature. We can read (and write) this value in all the interfaces, tcp/op, websocket, mqtt, REST etc and use it for other calculations or present it in a UI. With websocket this presentation is actual trivial using one of the ready-made widgets.

Also not that this work s for all measurement units (that is all SI defined and derived units)  in the same way.  No coding needed.

One last thing. Suppose you want to daily maximum/minimum instead of an all time maximum/minimum.  Easy

Add a DM row that triggers on

CLASS2.VSCPD, Type=9 Midnight

and store  the “very low”/”very high” value to the minimum. It is harder than that. In the same way you can do this on a weekly, monthly etc basis.

You can also use the escapes to  create a more dynamic variable that store the daily minimum/maximum. Try a store in variable

minimum-%isodate;float;true;0;0x777;%variable:[minimum]

which is set to trigger just before midnight. What you get here is a remote variable minimum-YYMMDD  where YYMMDD is the current date that is persistent and holds the value of the minimum remote variable collected for that date.

Try that with the rest..

 

One reply on “#VSCP HOWTO: Min/max”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.