AWS MQTT cloud connection

From Teltonika Networks Wiki
Main Page > General Information > Configuration Examples > Third party services > IoT platforms > AWS MQTT cloud connection

Introduction

In this article you will find instructions on how to setup AWS IoT as a MQTT Broker and how to setup a RUT router as a MQTT Publisher and send data over to this AWS Broker.

With that, you will be able to configure any other device as a MQTT Subscriber, and listen to any published info by the router or other devices on this same broker.

Prerequisites

You will need:

  • An AWS account
  • A router from the RUT2xx or RUT9xx or RUTXxx series
  • A computer with mosquitto application (optional)

Setting up AWS IoT

Creating a thing

First off, open the AWS Management Console and login with your credentials. After that, you will see a screen similar to this:

On the search bar on the top, search for "IoT Core", and click on the first search result. You will see a screen like the one below, open the "Manage" section and click on "Things".

Image986.png

Then, do the following procedure to create a Thing: click on the "Create Things" button -> "Create single thing" -> Give it any name -> "No shadow" -> "Auto-generate a new certificate (recommended)" -> "Create thing".

Certificate Handling

Certificates are used by Publishers and Subscribers to connect to your AWS MQTT Broker.

You will be prompted to download the certificates, download the "Device certificate", "Private key file, "Public key file" and "Amazon Root CA 1". Image985.png

Move all the 4 files to a folder on the C:\ drive, so it's easy to locate them. Then, i'd recommend renaming them as following: Keep the "AmazonRootCA1.pem" as it is, the file xxxxx.pem.crt as device_certificate.pem.crt, the file xxxxx-private.pem.key as private_key.pem.key and the file xxxxx-public.pem.key as public_key.pem.key. After that, you will have the following:

Image874.png

Setting up policies

The policies are needed for allowing incoming data into AWS.

Go back to the AWS IoT HuB, open the "Secure" tab and click on "Policies".

Image8754.png

Do the following procedure: Click on "Create policy" -> Give it a name -> Policy effect: allow -> Policy action: * -> Policy resource: *-> CreateImage854.png

Then, on the same "Secure" tab, click on certificates. There you will see one certificate, the one you've created, select it by checking the checkbox, then go to "Actions", and click on "Attach policy".

Image5422.png

Then select the policy you've created previously, and click on "Attach policies"

Image471.png

Getting your endpoint

The endpoint is the host address of your MQTT Broker, where Publishers and Subscribers will connect to.

You can find it into the "Settings" tab, copy and save it somewhere.

Image4785.png

With that, your MQTT Broker is all setup, and you can start setting up your RUT router as a Publisher.

RUT as MQTT Publisher

What data do you want to publish?

Depending on your RUT model, you can have the following options of data sources to send over MQTT:

  • Bluetooth
  • Wifi scanner
  • MODBUS
  • Router monitoring

Publishing Bluetooth/Wifi scanner/Modbus data

Before sending data from those sources to the MQTT Broker, the router needs to know what data from each source to send:

  • For Bluetooth, first you have to pair the device you want to get data from
  • For Wifi scanner data, you have to enable the wifi scanner functionality first
  • For MODBUS data, you need to set what data from what MODBUS slave the router has to get

If you need any help on setting up each functionality, the Teltonika Wiki has topics for each one of them

Then, you will use the "Data to server" functionality, under "Services" menu.

Image451.png

Click on the "Add" button on the right side of the page, you will see the following menu.

Img4587.png

The main fields you have to fill up are pretty straight forward, just pay more attention for the fields needed for AWS MQTT Broker connection:

"URL / Host / Connection string" : There you will paste your AWS Endpoint

"Port" : 8883

"Topic" : Any name you want, just write it down so you can subscribe this topic later

"Use TLS" : On

"TLS type" : "Certificate based"

"CA File, Client certificate, Private key" : There you will select the files you've downloaded from AWS IoT HuB

After setting up all, you should have something similar to the screen below. Click on save and apply.

Config421.png

To check if your setup is working, you can use any MQTT client, and subscribe to the topic you've created, you should be able to see the data of the source you've selected. In the image below, i've used the AWS IoT mqtt test client to subscribe to the topic that the router was publishing.

Image4752.png

Example: Publishing RUT MODBUS data over MQTT

In this example the RUT device will act as MODBUS TCP Master and MODBUS TCP Slave, so the device will make requests (Master) and answer to himself (Slave). The received reply, will be sent over MQTT.

  • Bluetooth