[ad_1]
As an IoT resolution architect, prospects typically ask me how they will connect with AWS IoT Core (cloud) utilizing a microcontroller unit (MCU). One resolution is to make use of Bluetooth Low Power (BLE) because the connection from the MCU to a cellular gadget; from there, the cellular gadget connects to the cloud. BLE works for shopper IoT gadget use circumstances akin to thermostats, door locks, related bicycles, good watches, and plenty of others.
On this weblog, I show tips on how to use a Nordic nRF52840-DK board (MCU) to connect with AWS IoT Core utilizing BLE with an iOS cellular app. I present two methods to connect with AWS IoT Core (cloud): first by straight utilizing BLE and passing information into AWS IoT Core utilizing MQTT, and second through the use of GATT setup to cross information via to AWS IoT Core utilizing BLE and your cell phone.
Pre-requisites
Answer overview
In our resolution, we’ll use Nordics nRF52840-DK with FreeRTOS and can perform the next duties (these are generally required duties in embedded growth to attach MCUs to the cloud utilizing BLE and cellular purposes):
First, we’ll do the embedded-side growth:
- Arrange the {hardware} (MCU with serial port communication with the pc).
- Arrange firmware (if wanted to speak with the pc).
- Arrange and configure FreeRTOS on the MCU.
- Arrange, configure, and deploy FreeRTOS BLE utility on the MCU.
Then, we’ll do the cloud aspect duties:
- Arrange a BLE IoT factor in AWS IoT Core.
Then, we’ll do the cellular app consumer duties:
- Configure and deploy the applying to our cell phone (iOS).
As soon as we’ve got accomplished following duties, we will take a look at the entire end-to-end strategy of MCU connecting to AWS IoT Core utilizing MQTT in addition to Customized GATT MQTT settings from Cell consumer, giving us perception on many alternative methods we will connect with AWS IoT.
Answer Diagram

To arrange your {hardware}
Join your host pc to the USB port labeled J2, situated straight above the coin cell battery holder in your Nordic nRF52840 board (see the highlighted field within the following image).

To arrange your terminal emulator
You want a terminal emulator to learn information between your desktop and board utilizing serial connection. This terminal emulator can be used to learn the output from the board, in addition to write to the board akin to firmware and FreeRTOS code. For this weblog, you should utilize the next:
- For Home windows: TeraTerm
- For Linux and MacOS: GNU Display (comply with configuration utilizing settings right here)
In your terminal emulator, run the next:
ls /dev/cu.*
In case your gadget doesn’t present up, chances are you’ll want a serial port driver for the board (discuss with SEGGER J-Hyperlink right here to arrange).
If the sunshine in your board is continually blinking, then its not related to your laptop computer. When related, a inexperienced mild pulsates on LED5 (see LED5 printed on the board).
To arrange the embedded growth IDE and connect with your gadget
Obtain and arrange SEGGER Embedded Studio and select the Embedded Studio for ARM choice. With Nordic gadgets, you possibly can receive a free license right here. This additionally installs JLink—if it didn’t set up, you possibly can set up from right here.

Open SEGGER and set up the Nordic CPU supported bundle:
- From the highest menu, choose Instruments, then choose Bundle supervisor.
- Seek for “nRF CPU Help Bundle” after which set up the bundle.

- As soon as it’s related, open your working system file supervisor (for Mac: Finder, for Home windows: File Explorer) to examine that the nRF52840-DK has appeared as a detachable drive named “JLINK”. Will probably be similar for all working techniques.
- Now, configure the terminal emulator settings for this. You have to your serial port particulars.
- Run the next command within the command line:
ls /dev/cu.*
- Run the next command within the command line:
The next output ought to be proven:

A tool seems much like: /dev/cu.usbmodem0006833844771. The gadget on this instance is related.
Subsequent, we’ll configure the SEGGER terminal emulator.
- From the highest menu, choose Instruments.
- Choose Terminal Emulator, then choose Properties.
- Replace the settings as follows:
- Baud Price: 115200
- Information bits: 8
- Parity: None
- Port: <chosen output from above>
- Cease Bits: 1

Now connect with the gadget:
- From the highest menu, choose Instruments.
- Choose Terminal Emulator, then choose Join <gadget port>.

As soon as the MCU is related, you will notice the gadget Join port greyed out, as proven:

To arrange FreeRTOS with BLE and an AWS IoT factor
Open a command line and clone the FreeRTOS repo. Use the next command:
git clone https://github.com/aws/amazon-freertos.git --recurse-submodules
To arrange a BLE IoT factor for our Nordic board
On this part, we’ll arrange the IoT factor (MCU board) in AWS IoT Core (cloud aspect), title it nrf52840BLE, after which register and not using a certificates. By now, you must have already arrange “ iOS SDK for FreeRTOS Bluetooth gadgets.” For Android, comply with the steps right here. Now, let’s go forward and arrange the cloud aspect and create your AWS IoT factor.
Create a factor
- Open the AWS IoT console.
- Within the navigation pane, choose Handle, then choose Issues.
- Choose Create issues, then choose Create single factor and provides it a reputation: nrf52840BLE. (Depart the remainder of the settings as default.)
- Within the Gadget Certificates part, choose Skip making a certificates presently.
Now that the factor is created, let’s discover its endpoint:
- Within the navigation pane, choose Handle, then choose Issues.
- Within the search bar, seek for nrf52840BLE, then select nrf52840BLE.
- From the navigation pane, choose Work together, and be aware the endpoint as proven within the following screenshot:

Subsequent, we have to create Amazon Cognito identities. To try this, we might want to create an Amazon Cognito consumer pool and ID pool.
To create an Amazon Cognito consumer pool: Create a consumer pool
- Open the Amazon Cognito console, select Handle consumer swimming pools, then Create a consumer pool.
- Give pool title: nrfdemo.
- From navigation pane, select App Shoppers, then Add an app consumer, and provides it a reputation: nrfappclient.
- From navigation pane, select Evaluate defaults, select Create pool.
- From the navigation pane, below Common settings, be aware down Pool id (as proven within the following picture).
- From the navigation pane, choose App Shoppers after which choose Present particulars. Make be aware of the App consumer id and the App consumer secret.

To create an Amazon Cognito identification pool: create an ID pool
- Within the Amazon Cognito console, select Handle Id Swimming pools, choose Create new identification pool.
- In Id pool title give title nrfdemoidpool.
- Broaden Authentication suppliers, select the Cognito tab, after which enter your consumer pool ID and app consumer ID.
- Choose Create Pool.
- Broaden View Particulars, and make an observation of the 2 IAM function names (see the next screenshot), Select Permit to create the IAM roles for authenticated and unauthenticated identities to
- entry Amazon Cognito.
- Choose Edit identification pool. Make an observation of the identification pool ID – e.g.,
eu-central-1:1abcde01-1a0b-1ab6-a12b-ab1abc12a123
Make be aware of the IAM roles.

To create and fix an IAM coverage to the authenticated identification – IAM coverage to allow Amazon Cognito ID to connect with AWS Cloud
- Open the IAM console, and from the navigation pane, select Roles.
- Discover and select your authenticated identification’s function,
- Discover these roles within the IAM created in earlier step (mine have been: Cognito_nrfdemoidpoolAuth_Role and Cognito_nrfdemoidpoolUnauth_Role).
- Select Connect insurance policies, after which select Add inline coverage.
- Select the JSON tab, and paste the next JSON code.
{ "Model":"2012-10-17", "Assertion":[ { "Effect":"Allow", "Action":[ "iot:AttachPolicy", "iot:AttachPrincipalPolicy", "iot:Connect", "iot:Publish", "iot:Subscribe", "iot:Receive", "iot:GetThingShadow", "iot:UpdateThingShadow", "iot:DeleteThingShadow" ], "Useful resource":[ "*" ] } ] } - Give the coverage title: IAMnrfPolicy.
- Choose Create Coverage.

At this level, we’ve got arrange an IoT factor for our MCU and connectivity credentials, which we’ll use to authenticate within the cellular app when MCU establishes the BLE connection. Be sure to maintain your AWS IoT and Amazon Cognito info readily available. You want the endpoint URL and IDs (created within the earlier steps) to authenticate your cellular utility with the AWS Cloud.
Arrange your FreeRTOS setting for BLE
To arrange a FreeRTOS BLE Cell SDK demo utility
- Obtain the related SDK (I’ll use directions for iOS.):
- For iOS, clone the repo and arrange the pod per the directions right here.
- For Android, clone the repo and comply with the directions right here.
- Upon getting cloned the repo and arrange the pod utilizing cocoapods, add the next within the Podfile which exists below [amazon-freertos-ble-ios-sdk/Example/AmazonFreeRTOSDemo/Podfile]:
pod 'AmazonFreeRTOS', :git => 'https://github.com/aws/amazon-freertos-ble-ios-sdk.git', :tag => '1.2.0'
Word: In Xcode, if you happen to get following recordsdata for pod exhibiting up as crimson, as seen within the following screenshot, then run the next command in your workspace listing:
pod set up
This may set up all of the dependencies for you.

- Shut Xcode, re-open the challenge, and clear construct.
Lastly let’s create an IoT coverage on AWS IoT for this. (Should you not wish to proceed with this demo resolution after you full the steps, ensure to delete the coverage later.)
- Open the AWS IoT console.
- Within the navigation pane, choose Safe.
- In Safe, choose Insurance policies.
- Select Create.
- Give the poolicy a reputation: nrfdemopolicy
- In Motion, sort in iot:*
- In Useful resource ARN, sort in *
- Choose Permit in Impact part.
- Full by deciding on Create.

Modify iOS Cell app utilizing Xcode
To configure SWIFT code
We might want to modify our iOS cellular app in swift code to let it know which area and which IoT coverage to make use of and which MQTT matter to ship the info over to.
- Open Xcode, then open the next file. We are going to modify constants as within the following screenshot.
amazon-freertos-ble-ios-sdk/Instance/AmazonFreeRTOSDemo/AmazonFreeRTOSDemo/Amazon/AmazonConstants.swift
Different areas akin to: EUWest1, EUWest2, EUWest3, EUNorth1, EUSouth1 are additionally obtainable these might be present in: AWSServiceEnum.h file choose the area related to you. As proven, I’m utilizing Frankfurt area (EU-Central-1).

- Modify the json file which is able to use the related AWS Cognito UserPool and IdPool we created earlier.
amazon-freertos-ble-ios-sdk/Instance/AmazonFreeRTOSDemo/AmazonFreeRTOSDemo/Help/awsconfiguration.json

Now we will proceed to construct the challenge. (Be sure you are utilizing your individual code signing credentials and never Amazon-provided defaults, as this may fail to construct).
- In Xcode prime menu, choose Product.
- Select Clear Construct folder, then Construct.
- As soon as the construct completes, choose Product, and select Run.
This may deploy the app your to iOS gadget and can code signal to run it on the gadget.

- Choose Create account. This may ship code to the e-mail you requested and ensure.
Through the use of following these directions you’ve gotten accomplished the cellular app growth, deployment, and its construct. So, now the iOS BLE cellular app is accomplished, let’s deploy the FreeRTOS BLE Demo app to MCU.
To deploy FreeRTOS demo BLE code to the MCU
Switching again to the MCU, you have to to arrange directions utilizing particulars right here. Earlier we already had related to the MCU utilizing SEGGER embedded studio—now, let’s deploy FreeRTOS and demo code to connect with the cellular app to ship information to AWS IoT Core.
For FreeRTOS launch, we’re utilizing launch of 05/26/2021.
To configure the challenge
- On this “Getting began with the Nordic nRF52840-DK” tutorial, if you get to the “Configure your challenge part”, be aware down your AWS IoT endpoint and modify #outline fixed code in following file:
aws_clientcredential.h - Replace the endpoint and factor title as seen within the following screenshot:

- Examine that the BLE GATT Demo is enabled below amazon-freertos folder. To do that, go to
distributors/nordic/boards/nrf52840-dk/aws_demos/config_files/iot_ble_config.h, and add#outline IOT_BLE_ADD_CUSTOM_SERVICES ( 1 )to the record of outline statements.

- Improve Bluetooth pairing timeout for the cellular app since you can be paring the gadget together with your telephone. To pair the MCU with cellular consumer you can be required to enter y’ to just accept the pairing. To make sure timeout doesn’t happen, let’s improve the timeout within the following file:
iot_ble_config.h - Replace the next line to 60 seconds:
#outline IOT_BLE_NUMERIC_COMPARISON_TIMEOUT_SEC ( 60 ) - Save the file.
To Construct and run the challenge FOR MCU in SEGGER
- If that is the primary time that you’re operating the demo on this board, it’s essential to flash a bootloader to the board earlier than the demo can run. Run the next:
FreeRTOS Folder / initiatives/nordic/nrf52840-dk/ses/aws_demos/bootloader/bootloader.emProject - If you get the next immediate, choose O.Ok.

To construct the demo BLE app for MCU
- Open following FreeRTOS challenge in SEGGER Embedded Studio:
FreeRTOS Folder/initiatives/nordic/nrf52840-dk/ses/aws_demos/aws_demos.emProject - Modify the next file (application_code/common_demos/ble/mqtt_ble/mqtt_demo_ble_transport.c) string to a special message than “hi there world.” I’ll use following take a look at (be happy to make use of what you favor):
"Hiya BLE message from Nordic nRF52840-DK MCU"


- Save the challenge, proper click on and construct the challenge (as proven within the earlier screenshot).
- As soon as constructed, choose Goal > Join J-Hyperlink, after which select Debug, Go.
- As soon as the construct is finished, go to Goal and Join J-Hyperlink.
- When full, open the FreeRTOS app in your iOS gadget.
- You will note the nRF MCU will present up on the gadgets. Choose your gadget after which choose Pair.


- As soon as you choose Pair in your cellular gadget, enter ‘y’ on the serial terminal emulator (pc) for the MCU to be accepted with the pairing.
-
- For MacOS / Linux: display screen /dev/cu.usbmodem0006837380271 115200
- For Home windows (utilizing TeraTerm): Within the Terminal Press ‘y’ on the display screen verify Bluetooth pairing.
Elective: To exit the display screen app, press CTRL+A and Ok and press y to exit the display screen app.
To see messages coming into AWS IoT Core
- Open the AWS IoT console.
- Within the navigation pane, choose Check.
- In Subscribe to a subject, enter ‘#‘ to seize all matters.
- Select Subscribe.

You will note messages showing within the AWS IoT console. Congratulations, you’ve gotten related your Nordics MCU utilizing FreeRTOS BLE from MCU and utilizing FreeRTOS iOS cellular app to behave as MQTT Proxy to ship information to AWS IoT Core.
To allow the customized BLE GATT server demo
Now that we’ve got accomplished MQTT over BLE to AWS IoT Core, let’s do the take a look at utilizing Customized BLE MQTT GATT to ship information to AWS IoT Core utilizing GATT setup:
First we’ll modify the next header file to ensure Customized BLE GATT server demo is enabled for Cell iOS consumer utility.
- Open following file:
FreeRTOS /distributors/nordic/boards/nrf52840-dk/aws_demos/config_files/aws_demo_config.h
-
- Remark out – #outline CONFIG_MQTT_BLE_TRANSPORT_DEMO_ENABLED
- Add following #outline CONFIG_BLE_GATT_SERVER_DEMO_ENABLED.
As soon as modifications are completed you will notice the code as seen within the following screenshot:

- Save the challenge.
- Proper-click, select Clear, then Construct.
- As soon as the construct is finished, navigate to Debug, and select Go.
- On the iOS cellular app aspect, open the FreeRTOS app.
- Choose the MCU. If you get following choice, select Begin Counter:


Lastly, to see information coming into AWS IoT Core:
- Open the AWS IoT console.
- Within the navigation pane, choose Check.
- In Subscribe to a subject, sort in “#” to seize all matters, as proven within the following screenshot.
- Select Subscribe.

Cleansing up
Should you adopted together with this resolution, full the next steps to keep away from incurring undesirable costs to your AWS account.
AWS IoT Core
- Within the Handle part, delete the Factor (nrf52840BLE)
- Within the Safe part, take away the Coverage (nrfdemopolicy)
Amazon cognito
- Delete the Consumer pool (nrfdemo)
- Delete the Id pool (nrfdemoidpool)
AWS IAM
- Delete the roles:
- Cognito_nrfdemoidpoolAuth_Role
- Cognito_nrfdemoidpoolUnauth_Role
- Delete IAM Coverage (IAMnrfPolicy)
Conclusion
On this weblog, first, I demonstrated tips on how to arrange our MCU and connect with our desktop. Second, I constructed our cellular app which acts as our proxy for BLE. Third, I arrange our demos on the MCU and constructed and deployed it to the MCU. Lastly, I despatched information from the MCU via a cell phone app BLE proxy, in addition to a customized BLE GATT server into AWS IoT.
This walkthrough demonstrates the flexibleness of utilizing FreeRTOS with our Nordics nRF52840-DK MCU; mixed with BLE, we’ve got simple connectivity. FreeRTOS does the heavy lifting, permitting us to concentrate on customized utility code for MCU.
This weblog exhibits how a number of fundamental elements and native AWS options assist you to simplify each IoT utility growth and supply of MCU information, which prospects can use additional as soon as within the cloud to hold out analytics and historic information evaluation. From MCU (utilizing FreeRTOS) to AWS IoT Core, you possibly can arrange and deploy your resolution with minimal traces of code and use pattern purposes supplied by FreeRTOS. As well as, as soon as the info streams into AWS IoT Core, it’s simple to develop and customise dashboards and apply machine studying fashions that allow groups to iterate rapidly and obtain data-driven insights out of your finish gadgets. To be taught extra, take a look at the FreeRTOS and AWS IoT Core product element net pages.
Concerning the creator
Syed Rehan is a International Sr. Specialist Options Architect at Amazon Net Companies and relies in London. He’s protecting world span of consumers and supporting them as lead IoT/ML Answer Architect. Syed has in-depth information of IoT/ML and cloud and works on this function with world prospects starting from start-up to enterprises to allow them to construct IoT options with the AWS cloud eco system.
[ad_2]
