Difference between revisions of "Secure IOT with AWS and Hornbill ESP32"
(21 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[category:ESP32 BareMetal]] | [[category:ESP32 BareMetal]] | ||
− | + | [[category:ESP32 Arduino]] | |
+ | Security of connected devices is of paramount concern. There are several possible ways to make the devices secure. One of the most essential and widely used options is to use end to end encryption. The widely used Transport Layer Security (TLS) version 1.2 is the latest standard used on web for secure connections including banking. There are very few micro-controller based solutions that implement TLS 1.2 due to lack of resources. ESP32 is one of the most affordable options out there. So let’s look at securely connecting Hornbill ESP32 Dev board to Amazon web services (AWS) IOT. | ||
+ | |||
+ | We will start with configuring AWS account, setting up the '''thing''', generating the security certificates, testing with a MQTT desktop client and then communicating with the hardware. | ||
+ | |||
+ | |||
=AWS User Account= | =AWS User Account= | ||
− | For | + | For using the AWS services you need to have a user account and login using the [https://www.amazon.com/ap/signin?openid.assoc_handle=aws&openid.return_to=https%3A%2F%2Fsignin.aws.amazon.com%2Foauth%3Fresponse_type%3Dcode%26client_id%3Darn%253Aaws%253Aiam%253A%253A015428540659%253Auser%252Fhomepage%26redirect_uri%3Dhttps%253A%252F%252Fconsole.aws.amazon.com%252Fconsole%252Fhome%253Fstate%253DhashArgs%252523%2526isauthcode%253Dtrue%26noAuthCookie%3Dtrue&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&action=&disableCorpSignUp=&clientContext=&marketPlaceId=&poolName=&authCookies=&pageId=aws.ssop&siteState=unregistered%2Cen_US&accountStatusPolicy=P1&sso=&openid.pape.preferred_auth_policies=MultifactorPhysical&openid.pape.max_auth_age=120&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&server=%2Fap%2Fsignin%3Fie%3DUTF8&accountPoolAlias=&forceMobileApp=0&language=en_US&forceMobileLayout=0 AWS Login link] |
+ | |||
+ | Existing users can directly login and directly jump to next. New users should register first and link the credit card for payments. Basic plan is free for first Year, other plans are chargeable. Check [https://aws.amazon.com/iot-platform/pricing/ this link] for available plans. | ||
+ | [[File:AwsIOT_Login_page.JPG]] | ||
+ | <br><br> | ||
+ | |||
+ | = Creating a new thing= | ||
+ | After Login, click on '''Signin To Console''' to go to AWS dash board. | ||
+ | Now type AWS IOT and Select the AWS IOT (Connect Devices to Cloud) from drop down as shown below. | ||
+ | [[File:AwsIOT Start.png]] | ||
+ | <br><br> | ||
+ | |||
+ | Now the AWS GetStarted Window will open only for the first time. Click on GetStarted to go to dash board. | ||
+ | [[File:AwsIOT GetStarted.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | Click on Register-->Things for registering a new '''Thing''' as shown below. | ||
+ | [[File:AwsIOT registerThing.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | Click on Create to create a new '''Thing'''. | ||
+ | [[File:AwsIOT ThingCreate.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | Provide a unique '''Thing''' name and click on Create to proceed. | ||
+ | [[File:AwsIOT TestThingName.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | myTestThing is SuccessFul created as shown below. | ||
+ | [[File:AwsIOT ThingCreatedSuccessfully.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | Get the MQTT HOST name and thing name from Interact menu. These will be used to connect with AWS MQTT and also to subscribe/publish the topics. | ||
+ | [[File:AwsIOT ThingInteract.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | =Generate certificates for new thing= | ||
+ | Go to Security menu and click on Create Certificate to register the certificates. | ||
+ | [[File:AwsIOT ThingCreateCertificate.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | Click on the activate button to activate the certificates and download the certificate,private key and root CA as name them as below.<br> | ||
+ | aws-root-ca.pem <br> | ||
+ | certificate.pem.crt <br> | ||
+ | private.pem.key <br> | ||
+ | [[File:AwsIOT ThingCertActivateSuccess.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | =Define and Attach Policies= | ||
+ | Go do AWS dash board and select the Security-->Policies and click on '''Create a Policy''' as shown below. | ||
+ | [[File:AwsIOT ThingPolicyCreate.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | Define the policy for myTestThing as shown below | ||
+ | [[File:AwsIOT ThingPolicyDefine.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | Now go back to Certificates and attach the policy that was defined above | ||
+ | [[File:AwsIOT ThingPolicyAttach.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | Select the '''thing''' and attach the policies define above. | ||
+ | [[File:AwsIOT ThingPolicyAttach 1.jpg]] | ||
+ | |||
+ | <br> | ||
+ | |||
+ | =Verify the Attached Policies= | ||
+ | Now verify whether the policies are attached to newly created thing as shown below. | ||
+ | [[File:AwsIOT VerifyPolicy.jpg]] | ||
+ | |||
+ | |||
+ | =Testing Using MQTT Fx tool= | ||
+ | As we have a test thing and also the certificates assigned with required policies. We can test it using the MQTT Fx broker tool. Lets list all the info we had while creating the thing and it certificates. | ||
+ | |||
+ | Broker Address / HOST Name: a3jzsmkecjw9hn.iot.us-west-2.amazonaws.com <br> | ||
+ | Broker Port : 8883 | ||
+ | |||
+ | Certificates:<br> | ||
+ | aws-root-ca.pem <br> | ||
+ | certificate.pem.crt <br> | ||
+ | private.pem.key<br> | ||
+ | [[File:MqttFx Setup.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | After doing the above setting, connect to the AWS. | ||
+ | [[File:Mqtt Connect.jpg]] | ||
+ | <br><br> | ||
+ | |||
+ | Subscribe to the thing that we created in the above tutorial. | ||
+ | [[File:Mqtt Subscribe.JPG]] | ||
+ | <br><br> | ||
+ | |||
+ | Successfully subscribed to the myTestThing. | ||
+ | [[File:Mqtt SubscribeSucess.JPG]] | ||
+ | <br><br> | ||
+ | |||
+ | Now select the myTestThing topic and publish a message. | ||
+ | [[File:Mqtt Publish.JPG]] | ||
+ | <br><br> | ||
+ | |||
+ | The published message is successfully received. | ||
+ | [[File:Mqtt SubscribeTopicRcvd.JPG]] | ||
+ | |||
+ | =Industrial data Logger= | ||
+ | Below is the sample code for logging the temperature and Current using HornBill ESP32. | ||
+ | <html> | ||
+ | <script src="https://gist.github.com/SaheblalBagwan/793a1bb6c8d55d454436508c0fba2d7b.js"></script> | ||
+ | </html> | ||
+ | |||
+ | Download the complete IDF project from [https://github.com/ExploreEmbedded/Hornbill-Examples/tree/master/esp-idf/Hornbill-Industrial-Data-Logger this link]. | ||
+ | <br> | ||
+ | |||
+ | Have an opinion, suggestion , question or feedback about the article let it out here! | ||
+ | {{DISQUS}} |
Latest revision as of 21:03, 12 April 2017
Security of connected devices is of paramount concern. There are several possible ways to make the devices secure. One of the most essential and widely used options is to use end to end encryption. The widely used Transport Layer Security (TLS) version 1.2 is the latest standard used on web for secure connections including banking. There are very few micro-controller based solutions that implement TLS 1.2 due to lack of resources. ESP32 is one of the most affordable options out there. So let’s look at securely connecting Hornbill ESP32 Dev board to Amazon web services (AWS) IOT.
We will start with configuring AWS account, setting up the thing, generating the security certificates, testing with a MQTT desktop client and then communicating with the hardware.
Contents
AWS User Account
For using the AWS services you need to have a user account and login using the AWS Login link
Existing users can directly login and directly jump to next. New users should register first and link the credit card for payments. Basic plan is free for first Year, other plans are chargeable. Check this link for available plans.
Creating a new thing
After Login, click on Signin To Console to go to AWS dash board.
Now type AWS IOT and Select the AWS IOT (Connect Devices to Cloud) from drop down as shown below.
Now the AWS GetStarted Window will open only for the first time. Click on GetStarted to go to dash board.
Click on Register-->Things for registering a new Thing as shown below.
Click on Create to create a new Thing.
Provide a unique Thing name and click on Create to proceed.
myTestThing is SuccessFul created as shown below.
Get the MQTT HOST name and thing name from Interact menu. These will be used to connect with AWS MQTT and also to subscribe/publish the topics.
Generate certificates for new thing
Go to Security menu and click on Create Certificate to register the certificates.
Click on the activate button to activate the certificates and download the certificate,private key and root CA as name them as below.
aws-root-ca.pem
certificate.pem.crt
private.pem.key
Define and Attach Policies
Go do AWS dash board and select the Security-->Policies and click on Create a Policy as shown below.
Define the policy for myTestThing as shown below
Now go back to Certificates and attach the policy that was defined above
Select the thing and attach the policies define above.
Verify the Attached Policies
Now verify whether the policies are attached to newly created thing as shown below.
Testing Using MQTT Fx tool
As we have a test thing and also the certificates assigned with required policies. We can test it using the MQTT Fx broker tool. Lets list all the info we had while creating the thing and it certificates.
Broker Address / HOST Name: a3jzsmkecjw9hn.iot.us-west-2.amazonaws.com
Broker Port : 8883
Certificates:
aws-root-ca.pem
certificate.pem.crt
private.pem.key
After doing the above setting, connect to the AWS.
Subscribe to the thing that we created in the above tutorial.
Successfully subscribed to the myTestThing.
Now select the myTestThing topic and publish a message.
The published message is successfully received.
Industrial data Logger
Below is the sample code for logging the temperature and Current using HornBill ESP32.
Download the complete IDF project from this link.
Have an opinion, suggestion , question or feedback about the article let it out here!