00:03
In this video we're going to show you how to configure a gateway device in the
00:08
IBM Watson IOT platform and upload SNAP Pac tags through Node-RED. Now to follow
00:15
this video you're going to have needed to create an account on the internet of
00:19
things IBM cloud. You actually do this through the IBM Bluemix console. You'll
00:25
also need an Opto 22 SNAP PAC controller that has the RESTful API client enabled
00:31
and configured. You'll also need a groov box running the
00:36
latest version of node-RED. Now from a high-level what we're going to be doing
00:41
is we're going to create a gateway device on the IBM Watson platform then
00:46
taking those gateway credentials we're going to configure a flow in Node-RED
00:51
that takes the PAC controller data and sends it at a set interval to the IBM
00:56
platform where each piece of data can be viewed under the Gateway. The big
01:02
advantage of this configuration is that you can push your data up to the cloud
01:06
and this means we don't have to make any changes to any of the settings on the
01:11
corporate firewall. Once your data is in the IBM Watson cloud there's a whole
01:16
host of different services that you can channel your data into things like time
01:21
series databases, machine learning and even predictive maintenance analytics so
01:27
let's get started. First we have to log in to our IBM account enter your
01:34
username and your password. Now select your organization. The default
01:44
view here is the cards but because we want to configure a device let's go over
01:50
and select devices from the tab on the left and here's our devices. We've got
01:55
none configured at this stage so let's go up and click on add device. Ok we're
02:02
going to create a new device and the device type is a gateway device. Here's
02:07
where we enter a name for that gateway device and we can also put in a
02:12
description for it. Go ahead and click Next.
02:19
Now here we can set up a few different fields and it helps us organize our
02:25
gateway devices but to keep the video moving we're just going to jump on here.
02:28
We're going to click Next. We can add any metadata if we want. Again I'm just going
02:33
to skip over that and click Next. Now we actually go ahead and configure the
02:37
device so we get a device ID. I'm going to call this thing SNAP PAC. Okay go
02:46
ahead and click Next. Again we can add some metadata for this device. Now at
02:51
this point we need to generate a unique token. So we can type one in but it has
02:56
to be unique or I'm just going to click Next and let big blue generate it for us.
03:00
Here's our last chance to review those settings. We go ahead and click Next. Now
03:05
this step is really really important. This is the only time that we're going
03:09
to see all these credentials including the token. So you really want to cut and
03:14
paste all of this information here and put it and save it to your hard drive.
03:18
Now cut paste is much better than say a screenshot because you've got to type
03:22
out all this information. I'm just going to throw it here in Notepad ++.
03:26
Alright so I'm sure I've got that data. We're happy with it. Let's go ahead
03:31
and click the X up in the top here. Alright there's our gateway device. Now
03:36
what we're going to do is we're going to flip over to Node-RED. So I'm going to
03:42
click on the the tab here. I'm going to log in to my Node-RED console and click
03:50
sign in. Okay this is the groov AR1 Node-RED console. It all looks good so I'm
03:58
going to click on the Node-RED editor and here we go. Alright ok here's a flow that's
04:04
actually getting the data from Weather Underground. I'm going to keep that flow
04:08
so I'm going to click on plus. I'm going to create a new flow. I'm going to rename
04:12
it. I like to keep all my flows organized so I can see what they are on the tab
04:15
and click done. Right now the very first thing we have to do is drag over an
04:20
inject node. And this is what fires off the data at the at the interval. So I'm
04:26
going to select an interval and I'm going to select every 5 seconds here. And I
04:30
like to put in the node name, how often it is so that I can just tell how fast
04:35
it's going to be doing all right there. We going we're injecting every 5 seconds.
04:39
Now what I'm going to do is I'm going to grab the SNAP PAC read node. This is what
04:43
restfully gets the data from Node-RED out of the PAC controller. For more
04:48
information on how to set this node up check out developer.opto22.com. I'm going
04:55
to quickly fill out the IP address here and also the credentials of my
05:01
controller. All right so you just have to fill out those parameters this one time.
05:05
Now I'm going to go down here and select my float variable. Where do I get this
05:10
float variable from? Well let's alt tab over here to a program called PAC
05:15
control. Now PAC control is the software that you use to program your SNAP PAC
05:19
controller. And the program, or as we call it the strategy, is a series of
05:24
flowcharts. And in this particular case they're emulating a convenience store
05:28
which is based around our SNAP PAC Learning Center.
05:31
So by going directly to the program we're going straight to the source.
05:35
I'm going to cut and paste those tags to make sure that we get them set up
05:39
correctly here in Node-RED. So let's go over and I'm in my numeric variables
05:45
here. And I'm just going to double click on the first one we want. There's that
05:49
regular fuel level reading. Copy that and I'll tab back over to Node-RED and paste
05:55
that in. Ok now what I'm going to do here is I'm going to set the message payload
06:01
to be the same as the tag name and that helps separate each variable in Node-RED.
06:06
Ok so let's go ahead and get the next one. There's our float variable. So now
06:11
we're going to add our analog input which is going to be this potentiometer
06:15
here emulating the the gas tank level. So let's go over here. We've already
06:20
configured the controller so we just come down here and we can grab our
06:26
analog input. I'll tab over. Let's come down now to our I/O tree. Because we're
06:32
going to read it directly from the i/o. Copy and ok. I'll tap back over and we're
06:39
going to paste this in store temperature. Same deal here. Node-RED we set the
06:44
message payload to be the same message.store_temperature. OK done that. And I said
06:50
that we were going do a digital point as well. It's going to be the switch here. So we go up
06:56
to our digital input. I'll tab over, get it again out of our strategy tree. I'm going
07:02
to get the photo sensor which is emulating the light here. We'll tab back
07:05
over. And on the tag name we paste that guy in and set the message payload to be
07:11
the same as the tag name. All right click done and that's got that
07:16
part of that set up. So the next thing now is we're going to add a function
07:19
block. And what we're going to do is we're going to put the tags into a bit
07:27
of JavaScript here. And all the JavaScript is doing - this is just plain
07:30
JavaScript here nothing fancy - we're just putting them into an array. So
07:36
I've already prepared the JavaScript here in my notepad so I'm just going to
07:39
copy/ paste that over. And what I'm doing is I'm just building an array with those
07:44
three tags in it, getting them from the message and ultimately assembling it, and
07:50
putting it into our final tag here. So now what's going to happen is instead of
07:55
getting each piece of data I'm just going to be sending all the data up as
07:59
one chunk. It's a lot more efficient, it's a lot faster. Okay so there's our
08:04
JavaScript. Click done. Okay so let's go up and give this a name. Here we go, build array.
08:13
Okay back to done.Now we're going to
08:21
just join all these nodes together here. Okay so click, drag, click, drag. Alright
08:30
now we're ready for the IBM IoT node. Now it's not here in my palette so how do we
08:35
add nodes to the palette? Well I've got a forum here, a forum post that I did on
08:41
forums.opto22.com under the Node-RED category. Just scroll down here and there
08:47
it is. Adding new nodes to your palette. And we've got a nice little bunch of
08:52
screenshots here that show you how to add nodes to your palette.
08:57
So it's a really handy reminder. So let's go ahead and do that. I'm going to click
09:01
on the menu, manage palette. I'm going to click on install. And I'm just going to
09:05
type in Watson. Okay and there it is the second one we want. I'm going to click
09:10
install. And just wait a few seconds here for the
09:15
node to install. Alright there we go - all installed. Okay click done. Now when
09:22
we scroll down there we go there's our node. So we can click, drag and drop
09:28
that guy over. Alright let's double click on it and open up the
09:31
configuration for this. Now this where we need all of that information that we
09:35
copied/ pasted in the notepad. So first of all we need our organization. Let's alt
09:41
tab over to my notepad and highlight the organization. And we're going to copy
09:46
that. I'll tab back and we're going to paste
09:49
that in. Leave the the gateway where it is because that's the URL at IBM needs
09:55
and let's grab the device type. I'll tab over drop that in. And now we need the
10:02
device ID. So let's copy that, alt tab and go back to device ID. Paste that in.
10:13
Alright now we need that token. And this is why you copy/ paste instead of a screenshot
10:16
because imagine having to type that out from a screenshot. And control-v that in,
10:21
click add. Ok now we just need to change from device to gateway here. Drop that
10:29
down. Alright there we go. Now we've got our device type again so I'll tab back
10:34
over, copy that, tab, paste it back in. Ok and same with
10:42
the device ID. Control-c, alt-tab, control v. Alright there we go.
10:50
That's now configured so we click done. And we just got to connect there to
10:55
there. Alright we're ready to go. You can open up the debug tab, click deploy.
10:59
We've now deployed that flow to Node-RED and then we are connecting and connected.
11:05
That's it. We're sending our data up to the cloud. Let's take a look at that.
11:09
Let's go back now to our IBM tab. Here in the browser select it there.There it is.
11:19
You can see the data is coming up. We got a nice signal strength to say that
11:22
it's connected. To see the data we simply click on the Gateway,
11:26
and we have to wait up to a maximum of five seconds here because it refreshes
11:30
every time the data comes in so sometimes I find it helps to click on
11:34
refresh. Just wait a second here for - there it - there it is. Boom there's
11:40
everything. All our data is now coming from our SNAP-PAC controller from our
11:44
i/o system, through Node-RED, up into the IBM cloud. Now from here what
11:49
we can do is we can add rules, we can build dashboard cards, or we can upload
11:54
our data to other IBM cloud services. For more information check out
12:00
developer.opto22.com
12:02
cheers mate