📜 ⬆️ ⬇️

Intel Edison. Working with the Intel IoT Analytics cloud: creating rules and sending notifications

Intel IoT Analytics

Cloud Intel IoT Analytics allows you to lay simple logic to perform a specific action. Creating rules is divided into two stages. At the first stage, you need to specify the actions to be performed . In the second stage, specify a set of conditions that must be fulfilled to perform the action. For example, a temperature value above 28 C.
Actions may be:


Consider the following scenario: when a temperature of 28 C is reached, it is required:

Rules are created in the Rules section. Each execution of the rule is accompanied by the formation of an alert in the system, section Alerts .
Take a booth from Intel Edison. Work with the cloud Intel IoT Analytics: registration and sending data .

The solution consists of the following points:
  1. Creation of commands for sending Actuation - relay
  2. Creating rules for sending notifications and on / off relays
  3. Arduino code change

1. Forming commands for sending Actuation - relay
It is required to create commands Complex command , for this purpose we will pass to the section Control .
Create a command to turn on the relay.
Select the edison habr device, the relay1 component, the action value 1 , the websocket transport, add the Add action command. Press the Save as complex command button and save the command named relay1_ON
Intel IoT Analytics
Just create a shutdown command, just select, action value 0 , name relay1_OFF
In the Complex commands section, the created commands will be displayed.
Intel IoT Analytics
')
2. Creating rules for sending notifications and switching on / off relays
Go to the Rules section, add the rule Add a rule
Fill in the fields:
Name: Higth_temp_PowerOnRelay_and_send_to_web@devdotnet.org
Description: when the temperature reaches 28 ° C, send a notification email web@devdotnet.org and turn on the relay
Priority: Medium - affects only the order of processing, the rule with the value of Higth will be executed first
Notifications type. Next, specify the type of notification.
Available:

You can create several different notifications / actions for a rule.
Choose Email . In the Email notifications section, select web@devdotnet.org from the list.
Add the second action Actuation. From the list of Actuation notifications, select relay1_ON.
Intel IoT Analytics
Go to the next page, digging Next.
In the device selection step, select - edison habr

The next step is to create the conditions.
Conditions may be several. For several conditions, a logical rule is defined:
Add Conditions

Parameter Enable Automatic Reset - affects the repeated fulfillment of the condition. If you do not mark it, then the melt will be executed once, and will switch to Archive status and will not be active in the future. Therefore, in our case, it is required to mark this item as true.
It is required to add two conditions. The first condition, the comparison of the temperature value, the expression: "> = 28" .

Monitored Measure field : temperature1 (Number) - choose the required sensor from the list
The Trigger When field contains items:

Choose - Timenased Condition
Expression: "> = 28" in the last 10 seconds
Second, the relay state must be false i.e. turned off. Otherwise, they will constantly send commands to turn on the relay, after each temperature measurement above 28 C.
Field Monitored Measure: relay1 (Boolean)
Field Trigger When: Base Condition - basic comparison
Condition Eqal "0" - equals 0
Intel IoT Analytics
Save, the Done button .

Create the second rule
Name: Low_temp_PowerOffRelay_and_send_to_web@devdotnet.org
Actuation notifications: relay1_OFF
Intel IoT Analytics
As a result, two rules will be created.

Intel IoT Analytics

3. Changing the Arduino code
In the previous example , an error was made in sending the relay state. Regardless of the command sent, the relay status always assumed to be false, the operator:
iotkit.send("relay1", 0); 


Below is the corrected version of the code:
 if ((component != NULL)) { if (strcmp(component->valuestring, "relay1") == 0) { if ((command != NULL)) { if (strcmp(command->valuestring, "RELAY.v1.0") == 0 && strcmp(value->valuestring, "0") == 0) { Serial.println("Relay Off!"); digitalWrite(9, false); //Send state Actiator iotkit.send("relay1", 0); } if (strcmp(command->valuestring, "RELAY.v1.0") == 0 && strcmp(value->valuestring, "1") == 0) { Serial.println("Relay on!"); digitalWrite(9, true); //Send state Actiator iotkit.send("relay1", 1); } } } } 


Now let's test, raise the temperature.
Temperature graph
Intel IoT Analytics
Alert
Intel IoT Analytics
Email
Intel IoT Analytics

Cool the sensor
Intel IoT Analytics
Intel IoT Analytics

The creation of the rules is over. When waiting for action, you should consider the time delay (up to 1 minute) from the moment the conditions coincide.
As can be seen from the article, a sufficiently flexible functional of forming the conditions is laid, and the main actions are present. GET HTTP request can be used to send SMS messages via HTTP sending gateways.
A small addition. The agent sending data to the cloud automatically does not start by default when Intel Edison is turned on, so it should be switched to autostart mode. Run the command:
# systemctl enable iotkit-agent
Table of contents
  1. Intel Edison. First start
  2. Intel Edison. Work with Intel IoT Analytics cloud: register and send data
  3. Intel Edison. Working with the Intel IoT Analytics cloud: creating rules and sending notifications
  4. Intel Edison. Cloud Intel IoT Analytics: sending SMS and RESTful client on ASP.NET

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


All Articles