Improvements to our Node-RED package

Improvements to our Node-RED package

Today, we discuss Node-RED again, as this platform is more and more popular among our customers and we recently implemented some modifications to our node-red-contrib-yoctopuce package. Here are the new features of the package.





Let's start by the improvements we've made to our package.

The YSensors node


The largest modification concerns the YSensors node. You can now configure the type and the frequency of the published messages directly from the node configuration panel.

The default mode is live value. In this mode, the node sends a message as soon as the value of the sensor changes. This enables you to react as soon as possible, but if the value of the sensor doesn't change, no message is sent.

In some cases, in particular if you want to draw a graph, it is better to have a message sent at a fixed interval. This is what the periodic value mode does. As its name indicates it, a message is sent at a fixed interval, whether the value changed or not. You could already use this mode before, but you had to configure the Yoctopuce module manually from the VirtualHub or YoctoHub interface and the process was more complex. Now, you can configure the frequency as well as the published information directly from the node configuration panel.

You can configure the frequency and the type of the periodic notifications
You can configure the frequency and the type of the periodic notifications



When the node sends periodic values, you can select which data is assigned to the payload field of the message. Indeed, you can send the average, minimal, or maximal value which was measured in the period. In these three cases, the payload of the message is a numerical value. The fourth option "all" sends all these measures at the same time as well as the time stamps for the beginning and the end as a JavaScript object:


{
    "min":20.943,
    "max":20.954,
    "avg":20.949
    "start":1542838377000,
    "stop":1542838378000,
}
 


The later option is very useful for advance uses, but requires a function or template node in output to convert these raw data into another format, as very few nodes accept structured data.

The YSQLHelper node


We also added a YSQLHelper node enabling you to generate SQL queries to add and retrieve data from a Yoctopuce sensor into a data base.

There are several nodes which allow you to interact with a data base, for example node-red-node-sqlite or node-red-node-mysql, but you must always use a function node and format the SQL query manually. The YSQLHelper node is here to simplify this task.

As an example, let's take the sqlite node which enables you to interact with an SQLite data base. It accepts SQL queries which are passed to it through the message topic field. The YSQLHelper node enables you to create the SQL query which allows you to insert the sensor data in a table. You can thus connect a YSensors node to a YSQLHelper node and to connect the later to an sqlite node.

This node has three main parameters:

  1. the table name
  2. the operation to be performed
  3. a message field which must contain the SQL query


The YSQLHelper node has three parameters
The YSQLHelper node has three parameters



The table name allows you to specify the name of the table in which the data are stored. This table has three columns: hwid, timestamp, and value.

Table example

hwidtimestampvalue
METEOMK1-63E02.temperature154283837700020.9
METEOMK1-63E02.temperature154283837800021.2
METEOMK1-63E02.temperature154283837900022
METEOMK1-63E02.temperature154283838000022.4



Supported operations are: Insert, Select, Create, and Drop.

The Insert operation enables you to add a record to the table. If the table doesn't exist, it is automatically created. Concretely, here is the diagram which allows you to add the values of the METEOMK1-63E02.temperature sensor to a "yoctopuce_sensors" table in an SQLite data base:

The insert operation enables you to add a line to the table with the measured value
The insert operation enables you to add a line to the table with the measured value



You can also create or delete the table. To do so, simply send any message to trigger the operation on the specified table.

You can also simply create or delete the table
You can also simply create or delete the table



The Select operation enables you to retrieve data that you stored in the table. You can specify filters to obtain only part of the records. You can for example specify that you want only the latest 100 records of the METEOMK1-63E02.temperature sensor:

You can specify filters to obtain only part of the records
You can specify filters to obtain only part of the records



Select operation example
Select operation example



When using a Select, the sqlite node returns a JavaScript array with all the records of the table which correspond to the filters.

The DbSplit node


As we have just seen it, data bases return all the records in a single message. If you want to split this large message with x values into a series of x messages each one containing a single value, you can use our new DbSplit node.

The advantage of using this node is that each message has the time stamp which was recorded in the data base, which is very useful if you want to display these values on a graph:

The DbSplit node enables you to more easily transfer the data to a graph
The DbSplit node enables you to more easily transfer the data to a graph



Other improvements


We also improved the configuration panel page layout. We fixed an incompatibility with the node-red-contrib-iiot-opcua package. Finally, if you haven't specified the name, the nodes now display the hardware ID of the module instead of the node type. In a word, details but which ease the use of our package on a daily basis.

Getting node-red-contrib-yoctopuce

To use these new features, you must install the latest version (1.1.0) of our node-red-contrib-yoctopuce package. You can do so very easily from the "Manage palette" menu of the Node-RED interface.

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.