Recipe Management in Opto22 groov View - Part 2

In part one of this series, we configured Node-RED to communicate with a MySQL database. Then, we set up a Node-RED dashboard and inserted some records into the database.

In part two (this post) we will update the Node-RED flow to use Opto22’s groov View platform to handle our user interaction. Here we can create, update, and manage recipes, as well as select which recipe we want to run on our production line. Once we have bidirectional data integration with Node-RED, we will build out a recipe management screen in the next post. In the final post in this series, we will configure the PLC side of things to actually run the recipe once we have selected it from the groov View interface.

Configure Node-RED and groov View Communications

The first step in configuring groov View and Node-RED is to install the node-red-contrib-groov package in the Manage Palette menu. This will give you access to the read and write nodes for a bidirectional connection to groov View from Node-RED.

node-red-contrib-groov package in the Node-RED palette manager after it has been installed.

Once you have installed the node-red-contrib-groov package, we can begin the process of setting up a link to groov View.

First drag a “groov read” node on to your flow.

The groov Read node in the node menu, and a configured version on a Node-RED flow.

Double click on the node in the flow, then click the pencil (edit) icon next to the “Data Store” property to select the Groov Project we will use. Then, click the pencil icon next to it to create a new groov project. In the project node properties, enter the IP address of your groov View server, the API key for your user. If you need a certificate, enter the path to it. Once you have entered this information click “Update”. On the data-store-node you will enter the data store name. We will name ours “Recipe” and set it up in the groov View project. Click “Update” again, and enter the Tag Name. Ours is “Name” for the name of the recipe. Click “Done” to save your work.

groov authentication in Node-RED.
groov Project configuration in Node-RED.
Data store configuration in Node-RED.

Finally, to trigger a read, we will use an inject node. To display the tag value in the debugger, we will use a debug node.

A groov Read node in Node-RED used to read in the recipe name from groov View.

To find the API key for the groov credentials property configuration, you can either go into groov Manage -> Accounts, then choose the user you want to connect and copy it from there. Or you can go into build mode in groov View -> Configure -> Accounts and copy it from there. Yes, the API keys are different in these screenshots, one is from a groov RIO, and the other is from a Windows server hosting groov View for this post. If you are using a groov EPIC PLC with groov View and Node-RED on the same device, they would use the same key. We are using the API Key from groov View in this configuration.

User account in groov Manage used to find the API key Node-RED will use to connect to groov View.
Menu to access user accounts in groov View.
User account in groov View with the API key displayed.

A Note About groov View Certificates

If like us, you are hosting Node-RED on a different device than groov View, you will need to install a certificate from the groov View server. In our example case we have a groov RIO running Node-RED and a Windows server hosting groov View.

On the Windows machine, you will want to run the groov SSL Certificate program to generate a certificate. Once you start the program, answer the prompts with your information to generate the certificate.

The groov SSL Certificate application in the windows start menu.
Results of the groov SSL Certificate application.

Once you have the certificate file (in our case groov.cer), you will want to install this on the groov RIO. Go into groov Manage -> Security -> Client SSL, and upload the groov.cer file there.

Uploading the groov View certificate to our groov RIO.
A configured groov View certificate in our groov RIO.

Once you have installed the certificate, restart Node-RED and you will be good to go.

Restarting Node-RED on our groov RIO after adding our groov View certificate.

Configure a groov View Data Store

In groov View, go into Build Mode. In the tag browser pane, select “Configure Devices and Tags” then select “Data Store” from the “Add New Device” dropdown menu.

groov View tag device dropdown to add a new Data Store.

Give the data store a name, in our example, we’ve using Recipe.

Setting the name of our data store in groov View.

Select the newly added data store and click “Configure Tags”

Our newly created data store in groov View

Next, we’ll add tags to the data store, and select the relevant data type. We will be adding four tags: Name, Atmosphere, Time, and Temp. These will use the following datatypes of String, Boolean, Integer, and Integer respectively.

We will also set up for tags with the “Table” checkbox selected and a table length of ten for reading in a list of recipes from the database. This will allow us to read in an array of ten values from the database. See the complete list below.

Tag configuration dialog in groov View.
Recipe tags configured in groov View.

Next you can save changes.

Save all changes menu in groov View.

Now, we will create a simple page to test functionality. On this page we will add a Value Input gadget, select the “Name” tag for the value, and then go into View Mode to enter a value for this tag, in this case “Recipe Name”.

groov View Build Mode screen with a textbox used to enter the recipe name value into groov View.
groov View window with a text box used to enter a recipe name value into the system

Read Data from groov View into Node-RED

To test our communication integration, we will go back to Node-RED, deploy the flow. We’ll click the “Inject” button on the flow leading into our Name read node we configured earlier. Watching the debugger window, we will see our value “Recipe Name” displayed.

Debugger showing a single tag value from groov View.

We can now read data into Node-RED from groov View. Now that we have this in place, we can begin to remove the Node-RED dashboard components from our flow and replace them with groov View reads. As you may recall from Part One, here is our flow using a Node-RED dashboard to populate the values:

Example flow from the previous post with Node-RED dashboard nodes used to enter recipe data.

We will now re-write this flow to use groov Read nodes and add a button we can trigger from groov View to execute the flow to write a recipe to the database.

To start, let’s add the rest of the recipe values to our groov View screen, and wire them up in Node-RED to make sure the values come across when we click the inject button.

A basic screen with our recipe data in groov View.
Node-RED flow to read data from groov View with manual operator intervention.
Debugger in Node-RED showing our values read from the groov View system

If you have a groov EPIC or groov RIO set up, you can use the groov I/O Input Node to read in an input value either from a physical input to the device, or you can configure an MMP value groov View that can write to (and then read) this value in Node-RED to execute part of your flow.

If you don’t have a groov EPIC or groov RIO—or you want to use a polling based approach—you can also use a timer function on an inject node to periodically read your values, then trigger parts of your flow based on the values you are reading. In our tutorial here, we will keep things simple and use an MMP address in our groov RIO. However if you want more information on how to use a timer in Node-RED read this excellent forum post.

To configure an MMP address in our groov RIO, go to groov Manage then the I/O Tools menu. We will then go into the MMP Calculator. At the top of this page select “Scratch Pad - 32-bit Integer (Section 1)”.

groov Manage scratchpad space in the MMP calculator

Click the “Open area in Generic MMP Page” link and you will see the addresses for each value in this MMP area. You can also look at different values if you desire, such as 8 Bit Integers and get a different address space as needed.

32 Bit Integer address space in our MMP memory area.

We will use the first address in this space for our tag to trigger a database insert in Node-RED. Copy the F0D81000 from here and go to groov View.

Go to “Configure Devices & Tags” and add in an Opto22 I/O Unit. We’ll give it a name of “MMP” and set the IP Address to that of our groov RIO.

Add new device dropdown in groov View with Opto22 I/O Unit selected.
Opto22 I/O Unit configuration pointing to our groov RIO device.

Once our Opto22 I/O Unit shows up in the device list, click on it and then click on “Configure Tags”.

Our MMP address space added to our devices and tags list in groov View.

Click the + button on the upper left to add a new tag. We will call it Trigger for now, and paste in the F0D81000 address we copied in from groov Manage for the offset.

groov View configuration for our MMP tag used to trigger actions in our Node-RED flow.

Next, go back to Node-RED and replace our inject statement with a groov I/O Input Read node and a switch statement.

Within the switch statement, we will add a rule to check if the value is equal to one. We will wire this up to the nodes to read in our four recipe tags and display their values to the debugger.

Then, we will configure the groov I/O Input Read node to look at the same F0D81000 address, this time on localhost since we are running Node-RED on the groov RIO itself.

groov i/o input node configuration to read our MMP address to trigger actions in our flow from groov View.

For reference, here is the switch statement’s configuration:

Switch node configuration with one rule to read data from groov View

These settings will trigger the output of this switch statement when the tag value at address F0D81000 is equal to 1, and will write the values of the tags from the groov read nodes to the debugger.

Node-RED debugger with data displayed after it has been read from groov View.

Node-RED debugger with data displayed after it has been read from groov View.

We can then change this value either in the MMP page or from a gadget on the screen, and when it has a value of 1 it will trigger our flow.

Insert Records Into the Database

We can now take the rest of the flow from part 1 and insert records into the database. We will combine the set value nodes with the groov read nodes, and add a second value to the switch statement to execute the database call. We can now write a value of 1 to our MMP tag to write the values to Node-RED, then a 10 to the MMP value to store them in the database.

Our Node-RED flow used to read data from groov View and insert the values into the database.
Switch node configuration from Node-RED with a rule to read data from groov View and a rule to write data to the database.

The function and database connection are copy-pasted from the button action in part 1.

Example flow from the previous post used to insert data into the database with a button press.

Writing a value of 1 to our trigger tag will update the flow values, then writing a value of 10 will trigger the database insert and add a row to the table.

groov View screen with data entered and the trigger value set to 1 to write the data to Node-RED.
groov View screen with entered data and the trigger set to 10 which will write data to the database using Node-RED.
Database row with the newly inserted records

Write Data to groov View from Node-RED

We can repurpose the SELECT statement from the previous post to write data back to groov View. We’ll take the function containing the SELECT query and the database connection node from before. For this post, we will hardcode the value of the ID to select a specific record from the database. We will make this dynamic in the next post (part three) when we work through the recipe management interface.

The section of the Node-RED flow used to query recipe data from the database and write it to groov View.
SELECT query in a Node-RED function node used to query recipe data from the database

After the database connection node, we will add a second function node to map the tag values in the msg object. Then we will pass those to the groov Write nodes.

Function to map data from the SELECT query into the Node-RED msg object

The groov Write nodes will be configured similarly to the groov Read nodes from earlier.

groov Write node configuration to write values to groov View from the database in Node-RED

Finally, we will add another case to our switch statement. It will go below the other rules for ease of adding it to our existing flow. It will execute the SELECT query and groov Write nodes when the value of the MMP tag is 2.

Node-RED switch statement with 3 rules, one to read data from groov View, one to insert data into the database, and one to read data from the database.

Here is the final flow with the groov Reads, INSERT query, and SELECT query all tied into the switch statement:

The complete Node-RED flow for this post including an MMP read, groov Read nodes, database insert and select queries, and groov Write nodes to write data to our groov View system.

Below is the data we pull from the database shown in our groov View screen:

groov View screen with tags populated from a Node-RED flow querying a recipe from a database.

Wrapping Up

You can now use groov View to read and write recipe data to/from a database and to/from data store tags when integrated with Node-RED. Yes, it is a more involved process than using an Ignition gateway along with system.db function calls in a script, however this gives us a huge amount of flexibility when working with Opto22 hardware because we can use their built-in groov View software which is free on a groov EPIC processor.

These simple types of solutions are popping up more and more, and we have plenty of interesting ideas on the horizon for projects where Opto22’s platforms will be a tremendously powerful tool in our arsenal.

If you have any ideas or needs we can help you solve with Opto22, Node-RED, and groov View please let us know!

Previous
Previous

Ignition 101 - Time of Day Based Triggers

Next
Next

Migrating Ignition Gateways