TC2.6 - IOT application; IOT Discovery of sensors and actuators for sending commands and notifications

×

Warning message

You can't delete this newsletter because it has not been sent to all its subscribers.

Test Case Title

TC2.6 - IOT application; IOT Discovery of sensors and actuators for sending commands and notifications

Goal

I can:

  1. Use of the IoT Directory for discovering devices, sensors, actuators, selecting them and generating the flows for modifying the values or the status of the selected sensors/actuators
  2. The Node-Red IoT Directory block allows you to select actuators retrievable from different Context Brokers (Orion, Mosquitto and Rabbit) that work on different protocols (NGSI, MQTT and AMQP)
  3. discover IOT devices on MAP located near to a point independently on their Broker and protocol
  4. on the map, it is possible to select a geographic area by using a point, a circle, a polyline or a polygon
  5. The solution is scalable may connect multiple IOT brokers

Prerequisites

Using a PC or Mobile with a web browser. You need credentials to access to the Node-Red application.

The following functionalities are available only for a specific Snap4City account with specific privileges.

Expected successful result

Generation of flows of data corresponding to the selected actuators in output for modifying their values or status. The sensors/actuators is retrieved from the context brokers in which they are registered.

Steps

 

 

In this test case two kinds of discovery are made presented for sending commands/notifications  to sensors and actuators (other modules have been developed for the discovery of devices from which observations should be read – see TC-3-1-1-a):

a. Retrieving devices (named device-based search).

b. Retrieving sensors and actuators (named value-based search).

 

Discovery of devices: device-based search

  1. Open a Flow in your cloud (TC2.1a) or local (TC2.1b) IotApplication
  • Look in the left side bar for the following two functions:

  • They are the nodeRED blocks for reading values from sensors and sending commands to actuators, respectively. Please drag and drop in the main canvas the second block.
  • You can see on the right side the help for the block.
  • All the facilities (retrieval on map/parametric retrieval, retrieve devices/retrieve values) described for the previous block are also available for this block.

3. Suppose we wish to send a command to the following four devices:

  • SemaphoreActuator_227_widgetImpulseButton2115
  • SemaphoreActuator_227_widgetImpulseButton2116,
  • Semaphore_257_widgetOnOffButton2942,
  • Semaphore_257_widgetOnOffButton2943
  • and that you deselect the “aggregate by device type” check button.

    • Once selected the four devices from the list of devices, we can click on “Done”. At this point the system automatically generates the flow that allows you to change the status of these devices. The flow is reported in an import menu as the following one:

    • The user clicks on “current flow” and then on “import”. A flow is generated and included into another tab. In the current tab, a link is reported representing all the devices to which a command/notification should be sent. The left part of the link block should be wired with the commands to be sent to the devices.

 

 

    • The associated flows (needed for communicating with the devices through the context brokers) are reported in a separated tab (notice that the flow name is the same to which the link associates in the previous image):

 

 

4. At this point, most part of the code associated with the transform block is already reported. If the developer needs to specify more details in order to control which command to be addressed to which device, he may modify this code.

 

 

  • The zoomed and full code in presented in the following:

 

var temp= msg.payload;

 

 // please check and complete the following

// attributes with the value arriving from

// the payload

var attributes={};

var js1 = {id:"SemaphoreActuator_227_widgetImpulseButton2115", type: "command", attributes};

var jsonstrg1 = JSON.stringify(js1);

 // please check and complete the following

// attributes with the value arriving from

// the payload

var attributes={};

var js2 = {id:"SemaphoreActuator_227_widgetImpulseButton2116", type: "command", attributes};

var jsonstrg2 = JSON.stringify(js2);

 // please check and complete the following

// attributes with the value arriving from

// the payload

var attributes={};

var js3 = {id:"Semaphore_257_widgetOnOffButton2942", type: "command", attributes};

var jsonstrg3 = JSON.stringify(js3);

 // please check and complete the following

// attributes with the value arriving from

// the payload

var attributes={};

var js4 = {id:"Semaphore_257_widgetOnOffButton2943", type: "command", attributes};

var jsonstrg4 = JSON.stringify(js4);



var head = {};

head["Content-Type"]= 'application/json';

var messages = [{ payload: jsonstrg1,  headers: head },{ payload: jsonstrg2,  headers: head },{ payload: jsonstrg3,  headers: head },{ payload: jsonstrg4,  headers: head }];

return messages;

 

5. Suppose we wish to send a command to the same devices  we select the “aggregate by device type” check button.

  • Once selected the device and imported the generated flows. In the current tab, the following links is generated. Note that in this case, the user is aware that need to generate commands and notifications for two device_type and can specify different values for them.

 

    • Whereas, in the tab generated automatically the following flow is reported

 

6. The aggregation by device_type has simplified the work of the developer because it is grouped now by device types, which means the correspondent command is sent automatically to the required devices (of same type).

 

TRANSFORM 1 tRANSFORM2

var temp= msg.payload;

 

 // please check and complete the following

// attributes with the value arriving from

// the payload

var attributes={};

var js1 = {id:"SemaphoreActuator_227_widgetImpulseButton2115", type: "command", attributes};

var jsonstrg1 = JSON.stringify(js1);

 // please check and complete the following

// attributes with the value arriving from

// the payload

var attributes={};

var js2 = {id:"SemaphoreActuator_227_widgetImpulseButton2116", type: "command", attributes};

var jsonstrg2 = JSON.stringify(js2);



var head = {};

head["Content-Type"]= 'application/json';

var messages = [{ payload: jsonstrg1,  headers: head },{ payload: jsonstrg2,  headers: head }];

return messages;

var temp= msg.payload;

 

 // please check and complete the following

// attributes with the value arriving from

// the payload

var attributes={};

var js1 = {id:"Semaphore_257_widgetOnOffButton2942", type: "command", attributes};

var jsonstrg1 = JSON.stringify(js1);

 // please check and complete the following

// attributes with the value arriving from

// the payload

var attributes={};

var js2 = {id:"Semaphore_257_widgetOnOffButton2943", type: "command", attributes};

var jsonstrg2 = JSON.stringify(js2);



var head = {};

head["Content-Type"]= 'application/json';

var messages = [{ payload: jsonstrg1,  headers: head },{ payload: jsonstrg2,  headers: head }];

return messages;

 

Discovery of devices: value-based search

Another facility offered by this nodered block  is the retrieval of single values to which commands and notifications can be delivered. This retrieval capability is activated by means of the second tab of the block setting interface: “Value-based search”. In a similar way as we have shown for the device-based search, it is possible to search values relying on the map or on parametric search. Moreover, the generated flow is aggregated for value_type. The approach is similar to the one discussed at the device level and allows to aggregation of values relying on the single sensor/actuator value_type.

1. By using the “Value-based search” tab, unselect the “Aggregated by value types” option and use the label: “Retrieval” for selecting sensors/actuators according to the parametric search. Once selected “Parametric search”, filter on Value type with "Actuator_canceller" and select “TrafficLight_227_widgetTrafficLight2117” and “Semaphore_257_widgetOnOffButton2944” as depicted in the following figure:

 

  • Once selected, we can click on “Done”. At this point the system automatically generates the flow that allows you to change the status of these devices. The flow is reported in an import menu as the following one:

 

2. The user clicks on “current flow” and then on “import”. A flow is generated and included into another tab. The purpose of the flow is to send commands/notifications to different actuators. The flow starts with an output link block. It receives values from the link in block that is placed in the same tab where the IoT Directory block is located, as shown in the following figure.

 

3. In a real setting, this operation makes sense only in the case the two actuators respond to the same set of commands. A node function is included also in the canvas for dispatching the commands to the appropriate device.  Some code has been already reported that need to be fixed by the Developer depending on the meaning of the receiving values. Relying on the selection of the Developer, a message is constructed and customized depending on the protocol of the receiver (which is a simple string for MQTT/AMQP and a JSON value in the case of NGSI). Double click on the block "function". You can see the code that is automatically generated:

 

The full code is:

var temp= msg.payload;

 

 // please check and complete the following

// attributes with the value arriving from

// the payload

var attributes={};

attributes["actuator_canceller"]="val"; //Semaphore_257_widgetOnOffButton2944



var js1 = {id:"Semaphore_257_widgetOnOffButton2944", type: "command", attributes};

var jsonstrg1 = JSON.stringify(js1);

 // please check and complete the following

// attributes with the value arriving from

// the payload

var attributes={};

attributes["actuator_canceller"]="val"; //TrafficLight_227_widgetTrafficLight2117



var js2 = {id:"TrafficLight_227_widgetTrafficLight2117", type: "command", attributes};

var jsonstrg2 = JSON.stringify(js2);



var head = {};

head["Content-Type"]= 'application/json';

var messages = [{ payload: jsonstrg1,  headers: head },{ payload: jsonstrg2,  headers: head }];

return messages;

 

  • Starting from the command that needs to be applied on the selected actuators it allows forwarding the command in the format required by the Context Broker (JSON for NGSI and CSV for MQTT/AMQP) involved.  The Developer has to update the automatic generated code depending on the specific actuators that are used.

4. Suppose now to select the same values, but to keep selected the “Aggregated by value types” option. In this case the following flow is loaded in the current tab

 

  • And the following one is included in the tab automatically generated.

 

In this case no further operations should be conducted by the user. Indeed, the value actuator canceller is directly associated with the value_name associated with the physical devices.