Difference between revisions of "Edge reasoners"
(→Context) |
|||
(11 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | Allows to configure reasoners to be executed by M2MBrigdes of an [[M2MBridge_network|M2MBridge Network]] | + | =Edge Reasoners= |
− | + | Allows to configure reasoners to be executed by M2MBrigdes of an [[M2MBridge_network|M2MBridge Network]]. A reasoner consists of two fundamental parts: | |
− | + | * An observer | |
− | + | * A list of one or more actions to execute | |
− | [[File:erSelectObservation.png| | + | |
− | + | ==Observer== | |
− | + | The observer is the conditional part. It's the condition that must be met in order to trigger the execution of actions associated to the reasoner. It starts by selection a type of observation among the types of observations configured in the [[Observations_production_and_consumption|observation production configuration]] of the bridge. When you decide to create a reasoner you will be asked for the type of observation that this reasoner will act on. Later on you will be allowed to also add constraints on this type of observation. | |
− | + | [[File:erSelectObservation.png|850px|thumbnail|center|Select observation type]] | |
− | + | ||
− | + | ===Constraints=== | |
− | ## | + | The constraints that can be specified for the observer in an edge reasoner are very similar to those explained in [[Observers#Filter_criteria|this section]]. However, some kind of constraints are not allowed in this context. That's the case, for example, of ''proximity area'' based constraints. There are also some additions like '''isRequired''', which is a new constraint that allows you to require the presence of a certain property in the observation. |
+ | [[File:erSetObservationFilters.png|950px|thumbnail|center|Select observation type]] | ||
+ | [[File:erSetObservationFilters2.png|950px|thumbnail|center|Select observation type]] | ||
+ | |||
+ | ==Actions== | ||
+ | Regarding actions you will be allowed to create two types of actions: | ||
+ | * Send command | ||
+ | * Custom action | ||
+ | |||
+ | ===Send command=== | ||
+ | For the action send command you will be asked for several properties: | ||
+ | * The target M2MBridge instance | ||
+ | * The target plugin (thing instance) that will receive the command | ||
+ | * The command (observation type) to be sent | ||
+ | [[File:erSendCommand.png|950px|thumbnail|center|Select observation type]] | ||
+ | To fill the properties of the command to be sent, you will be able to specify bindings in a way that is very similar to the specification of [[Binding|bindings for cloud reasoners]]. | ||
+ | [[File:erBindingActionsProperties.png|950px|thumbnail|center|Select observation type]] | ||
+ | |||
+ | ===Custom action=== | ||
+ | A custom action is a very powerful tool that allows you to build an action for the execution of custom code in a controlled environment. Once you decide a name for the action you will be able to write a code based on the observation that was generated in the bridge and met the observer's filters. This code will be written in the scope of a function with the following signature: | ||
+ | |||
+ | function(observation, context) { | ||
+ | ... | ||
+ | } | ||
+ | |||
+ | The observation is a javascript object with all the properties of the observation that was received. The context will be explained in the next section. The function doesn't need to return any value and even if it's not explicitly specified, it's an async function. It means that in its evaluation is changed to <code>async function(observation, context) {...}</code> | ||
+ | |||
+ | ====Context==== | ||
+ | |||
+ | The context is a helper for storing data in global scope. It's injected every time you create a custom action and it's a mean to share information among different executions of the same reasoner or even among the executions of different edge reasoners. This is the list of available functions: | ||
+ | |||
+ | # Asynchronous functions | ||
+ | #* <code>store(key, value) => promise</code> | ||
+ | #: Stores a pair (key, value) in the persistent dictionary of the context | ||
+ | #* <code>get(key, omissionValue) => promise</code> | ||
+ | #: Retrieves a value by its key in the persistent dictionary | ||
+ | #* <code>remove(key) => promise</code> | ||
+ | #: Removes an entry from the persistent dictionary by its key | ||
+ | # Synchronous functions | ||
+ | #* <code>sendObservationToCloud(observation)</code> | ||
+ | #: Queues an observation for it to be sent to the cloud | ||
+ | #* <code>scheduleSendObservationToCloud(observation, timeout)</code> | ||
+ | #: Schedules an action to send an observation to the cloud after the given timeout (in milliseconds) has passed | ||
+ | #* <code>sendObservationLocal(observation)</code> | ||
+ | #: Generates an observation in the edge subject to the processing of existing edge reasoners | ||
+ | #* <code>scheduleSendObservationLocal(observation, timeout)</code> | ||
+ | #: Schedules an action to generate an observation in the edge subject to the processing of existing edge reasoners after the given timeout (in milliseconds) has passed | ||
+ | #* <code>sendCommand(observation, bridgeTemplate)</code> | ||
+ | #: Sends a command to all bridges that resulted from a clone of the given bridgeTemplate (@id) in the current bridge network | ||
+ | #* <code>scheduleSendCommand(observation, bridgeTemplate, timeout)</code> | ||
+ | #: Schedules an action to send a command to all bridge that resulted from a clone of the given bridgeTemplate (@id) in the current bridge network after the given timeout has passed |
Latest revision as of 21:41, 18 August 2019
Contents
Edge Reasoners
Allows to configure reasoners to be executed by M2MBrigdes of an M2MBridge Network. A reasoner consists of two fundamental parts:
- An observer
- A list of one or more actions to execute
Observer
The observer is the conditional part. It's the condition that must be met in order to trigger the execution of actions associated to the reasoner. It starts by selection a type of observation among the types of observations configured in the observation production configuration of the bridge. When you decide to create a reasoner you will be asked for the type of observation that this reasoner will act on. Later on you will be allowed to also add constraints on this type of observation.
Constraints
The constraints that can be specified for the observer in an edge reasoner are very similar to those explained in this section. However, some kind of constraints are not allowed in this context. That's the case, for example, of proximity area based constraints. There are also some additions like isRequired, which is a new constraint that allows you to require the presence of a certain property in the observation.
Actions
Regarding actions you will be allowed to create two types of actions:
- Send command
- Custom action
Send command
For the action send command you will be asked for several properties:
- The target M2MBridge instance
- The target plugin (thing instance) that will receive the command
- The command (observation type) to be sent
To fill the properties of the command to be sent, you will be able to specify bindings in a way that is very similar to the specification of bindings for cloud reasoners.
Custom action
A custom action is a very powerful tool that allows you to build an action for the execution of custom code in a controlled environment. Once you decide a name for the action you will be able to write a code based on the observation that was generated in the bridge and met the observer's filters. This code will be written in the scope of a function with the following signature:
function(observation, context) { ... }
The observation is a javascript object with all the properties of the observation that was received. The context will be explained in the next section. The function doesn't need to return any value and even if it's not explicitly specified, it's an async function. It means that in its evaluation is changed to async function(observation, context) {...}
Context
The context is a helper for storing data in global scope. It's injected every time you create a custom action and it's a mean to share information among different executions of the same reasoner or even among the executions of different edge reasoners. This is the list of available functions:
- Asynchronous functions
-
store(key, value) => promise
- Stores a pair (key, value) in the persistent dictionary of the context
-
get(key, omissionValue) => promise
- Retrieves a value by its key in the persistent dictionary
-
remove(key) => promise
- Removes an entry from the persistent dictionary by its key
-
- Synchronous functions
-
sendObservationToCloud(observation)
- Queues an observation for it to be sent to the cloud
-
scheduleSendObservationToCloud(observation, timeout)
- Schedules an action to send an observation to the cloud after the given timeout (in milliseconds) has passed
-
sendObservationLocal(observation)
- Generates an observation in the edge subject to the processing of existing edge reasoners
-
scheduleSendObservationLocal(observation, timeout)
- Schedules an action to generate an observation in the edge subject to the processing of existing edge reasoners after the given timeout (in milliseconds) has passed
-
sendCommand(observation, bridgeTemplate)
- Sends a command to all bridges that resulted from a clone of the given bridgeTemplate (@id) in the current bridge network
-
scheduleSendCommand(observation, bridgeTemplate, timeout)
- Schedules an action to send a command to all bridge that resulted from a clone of the given bridgeTemplate (@id) in the current bridge network after the given timeout has passed
-