📜 ⬆️ ⬇️

IoT and ViaLatM. Automation of sending commands to Internet of Things objects



This article describes how to automate the sending of commands to objects from the Internet of Things area using the scripting language built into the VIALATM service. Basic information about the scripting language has been given in previous articles.


A description of the latest version of the scripting language (new commands, operators, procedures added) will be published soon. For the time being, you can get acquainted with the scripting language at ViaLatM .
')

Sending commands to objects


In the current implementation, the scripting language program is executed when receiving messages from an object (in the next version, the scripting language will allow calling programs using more advanced algorithms: according to a schedule, at specified intervals, in the absence of messages from the object for a specified time).

The system has two operators of sending commands: unconditional and conditional.

Unconditional statement format:

COMMAND (UNIT.ZTEMPER_SETTER, 12);

Using this operator, the command to set the ZTEMPER_SETTER attribute to value 12 is sent to the current object (for which the script is running).

Conditional statement format:

COMMANDIF (UNIT.ROOM_TEMPER> 20, UNIT.ZTEMPER_HEATER, OFF);

With the help of this operator, a command to turn off the heater (OFF) is sent to the current object if the room temperature sensor (ROOM_TEMPER) is more than 20 degrees.

All numerical values ​​in the above examples can be defined as constants or pre-calculated variables. Objects must publish corresponding attributes to the service and be subscribed to command processing (ZTEMPER_SETTER, ZTEMPER_HEATER).

Commands for working with multiple service objects


The most interesting feature of the scripting language is working with several objects.
Suppose the service is connected to the vehicle and the object that provides heating at home. In this case, you can create a sending command to turn on the heat when your vehicle has approached it at a specified distance. An example of such a script:

CONST HEAT_ON = 1;
CONST HEAT_OFF = 0;
CONST NEAR_HOME = 20000 # 20km
DIST_TO_HOME = DISTANCE (L, UNIT ("IOT_HOME"). L);
COMMANDIF (DIST_TO_HOME <NEAR_HOME, UNIT ("IOT_HOME"). HEATER, HEAT_ON);

Comment:
At the beginning of the script are defined constants that set the heater on and off. And the constant that determines at what approach the object to the house should send a command.

The script is executed for the object - a vehicle that must be equipped with GPS tracking (car or personal tracker) and connected to the service. When a message arrives from this object, the distance to the house is calculated.

Further, depending on the calculated distance, the conditional operator of sending the command to the object is applied.

Objects that are outside the executable script are specified by the UNIT function (“OBJECT_ID”). For trackers, IMEI should be set as OBJECT_ID, for Internet of Things objects the root theme (HOME) and for these objects the subject must always be preceded by the prefix “IOT_”.

Conclusion


In addition to working on the scripting language extensions mentioned above, the work on simplifying the language is the most important. An add-in is created in the form of working with macros that will allow people far from programming to use the language.

The next article will explain how to create notifications on events and states of objects from the Internet of Things area.

Source: https://habr.com/ru/post/305414/


All Articles