Ni Intern Demo Labview Aws

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

NI Intern Demo

Connecting LabVIEW to
Industrial IoT platforms
Connect myRIO to Amazon Web Services (AWS)
Version 1.0, January 2018

Developer Contact Information

Name: Angga Wardana

Email: [email protected]
Connect myRIO to cloud platforms 2018

Table of Contents
REQUIRED HARDWARE ................................................................................................................................ 2
MYRIO DEMONSTRATION KIT ........................................................................................................................................ 2
Demonstration Kit Components Used ............................................................................................................... 3
REQUIRED HARDWARE COMPONENTS .......................................................................................................................... 4
REQUIRED SOFTWARE.................................................................................................................................. 4
DESCRIPTION ................................................................................................................................................... 5
GOAL OF DEMONSTRATION ............................................................................................................................................. 5
KEY CONCEPTS DEMONSTRATED ................................................................................................................................... 5
DEMO PART 1 - SETTING UP THE AWS SQS ENVIRONMENT............................................................ 6
CREATE AN AWS ACCOUNT ............................................................................................................................................ 6
SETUP SECURITY AND ACCESS CREDENTIALS ............................................................................................................... 6
CREATE QUEUE IN AWS SQS.......................................................................................................................................... 9
DEMO PART 1 - SETTING UP LABVIEW AND MYRIO FOR AWS SQS............................................. 10
DEMO PART 2 – CONNECT LABVIEW TO AWS IOT SERVICES ........................................................ 13
SETTING UP THE AWS ENVIRONMENT....................................................................................................................... 13
SIGN UP WITH AWS IOT ............................................................................................................................................... 14
Create an IoT Thing ............................................................................................................................................... 14
Now we need to create an Certificate and IoT policy. ............................................................................... 15
SETUP A RULE AND ACTION ......................................................................................................................................... 18
DEMO PART 2 – SETTING UP LABVIEW AND MYRIO FOR AWS IOT ............................................ 21
SETUP THE DASHBOARD PAGE ON S3 ................................................................................................... 23
CREATE A BUCKET IN AWS S3 .................................................................................................................................... 23
MODIFY THE HTML PAGES ............................................................................................................................................ 25
UPLOAD INDEX.HTML AND REFRESH.JS TO S3 ....................................................................................................... 26
TROUBLESHOOTING STEPS......................................................................................................................... 0
NETWORK ISSUES: ............................................................................................................................................................ 0

1
Connect myRIO to cloud platforms 2018

REQUIRED HARDWARE

MYRIO DEMONSTRATION KIT

2
Connect myRIO to cloud platforms 2018

DEMONSTRATION KIT COMPONENTS USED

 Waveshare GSM/GPRS/GPS module


o Wire TX, RX and GND pin from module to RX, TX and GND pin in myRIO

3
Connect myRIO to cloud platforms 2018

 LED
o Positive pin to A/DIO 7
o Negative pin to GND
 Button
o Wire the pin to A/DIO 0 and the other to GND in myRIO

REQUIRED HARDWARE COMPONENTS


 Internet access (wireless – see also troubleshooting steps for details) Commented [SKW1]: Jelaskan koneksi internetnya
bagaimana? Dalam demo setup lo

REQUIRED SOFTWARE
 LabVIEW 2017 or Newer
 LabVIEW FPGA
 LabVIEW Real-Time
 NI-RIO
 myRIO toolkit
 LabVIEW Cloud Toolkit for AWS
o http://www.ni.com/gate/gb/GB_EVALTLKTNILVAWS/US
 Ensure all software on myRIO is installed, included the Secure HTTP for Clients (SSL) package

4
Connect myRIO to cloud platforms 2018

DESCRIPTION
The session has one demo that consists of two parts:

1. Data Storage with AWS SQS and S3 services


2. Connecting over HTTP with AWS IoT services

Please note that the demo requires additional setup at the cloud providers and this may take more time than
expected (for first time users allow 4 hours for full setup). In the demo, we will take measurements (in our case
measure digital I/O state) and store these measurements in the cloud as message in queue.

In the second part of the demo you will use a myRIO to get location from GPS module and input this to the AWS
cloud. This is especially important if there are many edge nodes. The entry point for the cloud with Amazon Web
Services is the AWS IoT service. From here it will be forwarded using the rule engine to a database (DynamoDB).

We will have a html page on the S3 service that pulls the data from the database to highlight the connectivity
between the services.

GOAL OF DEMONSTRATION
The idea of the demonstration is to provide practical information to customer how they can connect embedded
systems to leading cloud platforms. During the first part of the demonstration you will highlight the cloud storage
solution directly from the myRIO system. We will be using the LabVIEW cloud toolkit for AWS to connect to AWS
SQS.

The goal of the second part of the demonstration is to show that LabVIEW and NI myRIO is capable to securely
inject HTTP messages to AWS IoT. We are using LabVIEW Cloud Toolkit for AWS to setup the SSL link.

KEY CONCEPTS DEMONSTRATED


 Data storage in the cloud, directly from an embedded device
 GPS Location data acqusition
 HTTP Connectivity – NI myRIO is an open system for IoT projects to connect to cloud servers like AWS,
Bluemix, Azure and others.
 IoT Connectivity to the cloud, directly from an NI embedded device

5
Connect myRIO to cloud platforms 2018

DEMO PART 1 - SETTING UP THE AWS SQS ENVIRONMENT


The demo will use Amazon Web Services (AWS) SQS to store message. Amazon offers many more services, which
you will see during sign up. The setup consists of the following:

1. Create an AWS account and sign up for AWS Free Tier


2. Setup security and access credentials
3. Create SQS queue

CREATE AN AWS ACCOUNT


You will need to have an AWS account. An AWS account is simply an Amazon.com account that is enabled to
use AWS products; you can use an existing Amazon.com account login and password when creating the AWS
account. To create a new account, you will need to provide a few personal details and your credit card. You can
sign up for the one year Free Tier, during which most of the services are free of charge. There are a few services
(such as sending text sms messages outside of the US region) that, when used will be charged a low cost to your
account, but in general if you’re staying within this demo you should not be charged.

1. Open https://aws.amazon.com/, and then choose Create an AWS Account.


2. Follow the online instructions. There are a few steps:
 Contact information. During the instructions select the option to create a personal account, as we
will not link to a company account.
 Payment Information. You will need to provide your credit card information, even though you will
sign up to the free tier. It is needed in case you purchase AWS products that in the future that are
out of the Free scope.
 Identification verification. Part of the sign-up procedure involves receiving a phone call and
entering a PIN using the phone keypad.
 Select the support plan. The default should be ‘Basic’ which is the one we need.
 It will then take a few minutes for AWS to setup your environment, after which you will receive an
email and you can log on the AWS console.

For more information, see AWS Free Usage Tier. The AWS Free Tier account include access to services like AWS
IoT, S3, EC2 and DynamoDB for 12 months. From your AWS account, you can view your AWS account activity,
view usage reports, and manage your AWS Security Credentials.

SETUP SECURITY AND ACCESS CREDENTIALS


You need to create an access key and a secret key to identify yourself with AWS. These keys are needed for
automatic sign in request from LabVIEW (or any other programmatic access) to AWS.
1. From the top menu bar, select services and from the services page, select under Security, Identity &
Compliance ‘IAM’ (Identity and Access Management)

6
Connect myRIO to cloud platforms 2018

2. IAM is where you create and manage users. Amazon recommends to delete your root account access
key and create limited IAM user keys. As we are simply using the account for demo purposes we will
keep using the root account. Right click the down arrow besides “Delete your root access keys” and
click ‘Manage Security Credentials’

3. Click on ‘Continue to Security Credentials’, then click on ‘Access Keys (Access Key ID and Secret Access
Key)’, to open up the category.
4. Click on the blue button Create New Access Key’

7
Connect myRIO to cloud platforms 2018

5. You will see a popup where you can download the key file.

6. Download the key file and store it in a safe place. The key file is a rootkey.csv file that you can open
with notepad. It’s content looks like:

AWSAccessKeyId=ABCDTHISISNOTREALKEY1OCG5U
AWSSecretKey=ThIs1sN0tAReaLKey123456789+BlaBla

7. You now have two keys: a secret key and an access key. The secret key cannot be recovered. If you lose
the key, you will need to inactivate the access key and create a new key set using the same procedure.

8
Connect myRIO to cloud platforms 2018

CREATE QUEUE IN AWS SQS


Now that you have an account you can log in and open the S3 service – simple storage service from the console:
https://aws.amazon.com/sqs/

Within the service you can work with the service using a web browser (GUI), a command line interface (you need
to download it from AWS, called AWS CLI) or the LabVIEW API.

Amazon Simple Queue Service (Amazon SQS) offers a reliable, highly-scalable hosted queue for storing messages
as they travel between applications or microservices. It moves data between distributed application components
and helps you decouple these components. Amazon SQS provides familiar middleware constructs such as dead-
letter queues and poison-pill management. Amazon SQS supports both standard and FIFO queues. But LabVIEW
Cloud toolkit for AWS only supports standard queue.

1. You will need a queue on AWS SQS to store your messages ; click Create New Queue

2. Enter the queue name (LEDweb) and region. Chose standard queue
NOTE: The name and region you select should match your settings in the LabVIEW application later!
3. Click Quick Create Queue .
4. Repeat step 1 through 3 with queue name LEDmyRIO

You should now be ready to setup and test from LabVIEW.

9
Connect myRIO to cloud platforms 2018

DEMO PART 1 - SETTING UP LABVIEW AND MYRIO FOR AWS SQS


1. Connect the myRIO to your network infrastructure through MAX, so it can access the internet.
In network settings, choose the network, passphrase and DHCP only.

2. Create a copy of the IoT AWS demo files and open the project in LabVIEW.
3. In the project instance, right-click on the myRIO, select properties and configure the IP address to
match that of your specific myRIO.
4. Connect to the target by right clicking the myRIO item in the project and selecting connect.
5. Open the RT.vi in the project.
6. Set the Access and Secret Key you received earlier on through the AWS IAM service and save the
VI.

10
Connect myRIO to cloud platforms 2018

7. Set the queue name and region matching your settings at Create Queue section.

8. Run the VI.


9. Try to push the button once
10. Check SQS LEDweb queue incoming message. There should be 1 message “ON”

11
Connect myRIO to cloud platforms 2018

11. Delete the message to empty the queue/


12. Stop the program

12
Connect myRIO to cloud platforms 2018

DEMO PART 2 – CONNECT LABVIEW TO AWS IOT SERVICES

SETTING UP THE AWS ENVIRONMENT


The demo will use Amazon Web Services (AWS) IoT, DynamoDB and S3. Before you start the setup, you need to
have performed the setup of the first demo. Additionally, you must have setup these steps:

1. Sign up with AWS IoT


2. Register the myRIO
3. Test the connection
4. Setup a Rule
5. Register with AWS DynamoDB
6. Setup the DynamoDB database

13
Connect myRIO to cloud platforms 2018

SIGN UP WITH AWS IOT


AWS IoT consists of the following components:
• Message Broker — Provides a secure mechanism for things and AWS IoT applications to publish and
receive messages from each other. You can use either the MQTT protocol directly or MQTT over
WebSockets to publish and subscribe. You can use the HTTP REST interface to publish.
• Rules Engine — Provides message processing and integration with other AWS services. You can use a
SQL-based language to select data from message payloads, process the data, and send the data to other
services, such as Amazon S3, Amazon DynamoDB, and AWS Lambda. You can also use the message
broker to republish messages to other subscribers.
• Thing Registry — Sometimes referred to as the Device Registry. Organizes the resources associated with
each thing. You register your things and associate up to three custom attributes with each thing. You
can also associate certificates and MQTT client IDs with each thing to improve your ability to manage
and troubleshoot your things.
• Thing Shadows Service — Provides persistent representations of your things in the AWS cloud. You can
publish updated state information to a thing shadow, and your thing can synchronize its state when it
connects. Your things can also publish their current state to a thing shadow for use by applications or
devices.
• Thing Shadow — Sometimes referred to as a device shadow. A JSON document used to store and
retrieve current state information for a thing (device, app, and so on).
• Device Gateway — Enables devices to securely and efficiently communicate with AWS IoT. Security and
Identity service—Provides shared responsibility for security in the AWS cloud. Your things must keep
their credentials safe to send data securely to the message broker. The message broker and rules engine
use AWS security features to send data securely to devices or other AWS services.

There are 4 components that we need to setup within AWS IoT:


A. Thing (store our myRIO device in IoTs registry)
B. Policy (describes by means of a certificate what a device can do on AWS IoT)
C. Certificate - MQTT transmission to your AWS IoT gateway is encrypted using TLS and authenticated
using certs you will create
D. Rule – You will configure a rule that send data published to the IoT MQTT broker to the AWS DynamoDB
database service.

CREATE AN IO T THING
1. Sign in to the AWS IoT console (http://console.aws.amazon.com/ ).
2. Click Create a Resource. If this is the first time you have accessed the AWS IoT Console, you may need
to click Get Started.

3. On the resulting screen, click Create a thing.

14
Connect myRIO to cloud platforms 2018

4. Provide a name for the Thing, and click Create Thing.

NOW WE NEED TO CREATE AN CERTIFICATE AND IOT POLICY.


1. Click the Security tab while still in the device window.

2. Click Create a certificate for the device. The certificates will be created and you will need to download
them from the resulting screen.
3. Download all 4 certificates and then click Activate

15
Connect myRIO to cloud platforms 2018

4. Click attach a policy and create a new policy

16
Connect myRIO to cloud platforms 2018

5. Setup the policy to the above settings.


6. The Create button should turn blue. Click it to complete the policy creation.

7. Now you need to associate the policy with the certificate and the certificate with the thing. Click the
back arrow in the screen, and go to the security menu item>Certificates.
8. Click on the check box of the certificate you just created and click the Actions button and select Attach
a Policy

17
Connect myRIO to cloud platforms 2018

9. In the Policy name dialog box, begin typing the name of your policy. The Name should be auto-
populated. Select the name and click Attach.
10. Repeat the process, selecting Attach a thing

SETUP A RULE AND ACTION


IoT Rule Actions give your devices the ability to interact with AWS services. Rules are analyzed and actions are
performed based on the MQTT topic stream. Rules can also filter the data to decide whether to forward the
data. We will simply forward all the data to the AWS DynamoDB

1. Click the Rules section, then Create (or if there’s no rule yet, click ‘Create a Rule’) on the AWS IoT service
Configure the rule:
Name FwdToDatabase
Description leave blank
Attribute VALUE state.reported
Topic Filter (*) $aws/things/myRIO/shadow/update/accepted
Condition leave blank

2. This will send all messages with topic $aws/things/myRIO/shadow/update/accepted to our action.
Click Add action

18
Connect myRIO to cloud platforms 2018

3. Select Insert a message into a DynamoDB table. You can see that there are plenty of options of what you
can do with the data coming into the cloud. Scroll down and click ‘Configure the action’

4. Set the hash key type and value, as well as range key, range key type and range key value.

Table name: * create a new resource see below


Hash key value myRIO (String type)
Range key value ${timestamp()} (Number type)
Write message data to this column payload

5. When you click ‘Create a new Resource’ on the table name, it will take you to AWS DynamoDB, which is
where you should configure to the new table. Click Create a table

19
Connect myRIO to cloud platforms 2018

6. Click Create and the table will be ready in a short while


7. Now move back to the rule tab in your browser and finish creating the rule setup
8. To grant the IoT service access to the database a IAM role needs to be specified. If you are setting up a rule
for the first time it will be blank and you will need to click Create a new role.
9. If you already have configured a rule earlier, you can click update role to allow AWS to access the database.
10. Next click Add Action at the bottom to finish creating the rule forwarding to the Database setup

You should now be ready to setup and test from LabVIEW.

20
Connect myRIO to cloud platforms 2018

DEMO PART 2 – SETTING UP LABVIEW AND MYRIO FOR AWS IOT


1. Make sure that your time and time zone that’s set through MAX on the myRIO match the time and zone
you are in.
2. Within the LabVIEW project, open the ‘RT.vi’ block diagram
3. Set the Access and Secret Key you received earlier on through the AWS IAM service and save the VI.

NOTE (*) – If you changed the topic in the rule setup you will need to match it to your setup.

4. Now deploy and run the vi.


5. Open the AWS IoT service, go to the ‘Test’ tab and enter a subscriber for topic
‘$aws/things/myRIO/shadow/update/accepted’
6. You will get an entry in the list of topics you can subscribe to, click on it and you should see messages
coming in.

7. If you can’t see the data coming in like this format, then correct any of the settings made earlier
(certificate/topic/address/etc.)

8. Next go to the DynamoDB and click on the table you created. Click on the ‘Items’ tab and check if your
data is being added to the table. It should look like

21
Connect myRIO to cloud platforms 2018

9. Stop the vi.

22
Connect myRIO to cloud platforms 2018

SETUP THE DASHBOARD PAGE ON S3

CREATE A BUCKET IN AWS S3


Now that you have an account you can log in and open the S3 service – simple storage service from the console:
https://aws.amazon.com/s3/

Within the service you can work with the service using a web browser (GUI), a command line interface (you need
to download it from AWS, called AWS CLI) or the LabVIEW API.

Folders within S3 are called buckets, and files are called objects. Buckets need to have a UNIQUE name (across
AWS!) and buckets can store infinite number of objects. A good way to enforce a unique name is to use your
initials, followed by project followed by some numbers; i.e. evh-nidays-oslo-2017
Buckets can be created in specific regions, such as EU (Ireland), US East or others. This may be important to your
customers if they do not want to store in another country for security reasons, legislation or company policy.
Having data closer may also increase throughput.

1. You will need a bucket (folder) on AWS to store your data; on the S3 page, click Create Bucket

2. Enter the bucket name and region.


NOTE: The region you select should match your settings in the LabVIEW application later!

23
Connect myRIO to cloud platforms 2018

3. Click Next to set properties. Here you can select versioning, logging or add tags. You can leave the
default settings and click Next.

4. Set the permissions. Make sure you have permissions to read and write to the object as well as to the
permissions on the objects (access control list).
5. Public permissions should be set to just Read on the objects, as we want to publish our data to
everyone. Click Next, review your settings and then click Create Bucket.
6. Click on your bucket to see the items in your folder. As you see the bucket is still empty.

24
Connect myRIO to cloud platforms 2018

You have already created a bucket to store the datafile in the first demo. Now we will add a html page to this
bucket to display the data from the queue of the first demo as well as the features we stored in the database.
This involves the following steps:
1. Modify the html pages
1. Upload them to S3

MODIFY THE HTML PAGES


You have 2 pages, an index.html and a refresh.js and 2 image(ledon.jpg and ledoff.jpg) that need to go on the
S3 data storage service. The html page contains the layout of the components we will display and calls the
JavaScript to dynamically pull the data and update it in the map.
For the JavaScript to receive the data from the DynamoDB it needs to have access to the database. You need to
edit the file therefore. You can do so in notepad++ or any other plain editor (I’m using notepad++ or Atom). The
html does not need any editing, you only need to change the refresh.js.

2. Edit the refresh.js to match your setup:


Line 1 The region should match the region you have the database in
you can check this in the URL if you go to the DynamoDB tables within AWS
Line 2 Update with your credentials
Line 13 change the Tablename (we defined Demo) if you defined differently
Line 14 change id you have made changes

3. Save the refresh.js


NOTE: saving the credentials in the file is not the safest way, but for this demo the easiest. There are better and
more suitable ways, but those involve more steps.

25
Connect myRIO to cloud platforms 2018

UPLOAD INDEX.HTML AND REFRESH.JS TO S3


1. Go to the S3 service in your browser (click on services>S3).
2. Open the bucket you created for the first demo. There should be just one folder ‘uploads’
3. Using the web interface click the upload button, or simply drag and drop the index.html and refresh.js
files in the main bucket. (not in ‘uploads’ folder)
During the upload, you need to specify who can access the file.

4. Since we want everyone to be able to view the html file, we need to give everyone read access.
Click next, next, upload

5. Your S3 folder will now look like

6. Double click the index.html to open the properties, then click the link in the overview tab.

26
Connect myRIO to cloud platforms 2018

NOTE: do not leave your cool dashboard open for extended periods of time on your browser. There is a limit on
the number of times you can access the DynamoDB for free.
7. Click Turn ON button to light up LED on myRIO. Click it again to turn off the LED.
8. Press the button on myRIO to light up LED on the dashboard. Press it again to turn it of

27
TROUBLESHOOTING STEPS
If you receive

Error 7 in Call Library Function Node in LabVIEWHTTPClient.lvlib:AddHeader.vi


-> Go into MAX and install software on myRIO: likely you miss the http client ssl support package

Error 412031 (time skewed) -> the time on the myRIO must match at least + 15 minute the AWS time
-> Go into MAX, and set your time zone and set to the current time in your time zone

NETWORK ISSUES:
You will need to have access to internet as well as to the myRIO. The myRIO should also be able to
connect to the internet. Depending on your venue you’re presenting in you have different options:

BEST: Wired internet connection. Always ask for a wired internet connection.
It is most reliable and suitable for the demo and it is also the easiest to setup.

GOOD: Use a wireless router that can act in client or Wi-Fi gateway mode
(travel router). These do not always work but could be a cheap first backup.
These will not always work however, it depends on the hotel network
configuration.

You might also like