Skip to main content

FairCom AWS IoT core bridge tutorials

The purpose of this tutorial is to demonstrate and describe how to use FairCom APIs and services to forward (bridge) messages from the FairCom broker to an AWS IoT core broker.

Requirements:
  1. Ensure the FairCom server is installed and running.

  2. Confirm server access by running the FairCom API Explorer (see API Explorer to learn about the user interface).

Complete the tutorial requirements before this procedure.

Establish access to the AWS IoT core console:
  1. Create an AWS account.

  2. Log into your AWS account.

  3. Navigate to the IoT core management center.

    IoTCoreManagementCenter.png
  4. Create required AWS service endpoints.

  5. Create AWS IoT client certificates.

Figure 1. Access an IoT core MQTT client
Access an IoT core MQTT client


  1. Navigate to the IoT core MQTT test client in the AWS core console (see Figure 1, “Access an IoT core MQTT client).

  2. Observe that your location is set to the correct region referred to in AWS Endpoint in the console header.

  3. Use this console to see forwarded messages from the FairCom broker, published messages, the topics you are subscribed to, and more.

Learn more about features of the MQTT test client at View MQTT messages with the AWS IoT MQTT client.

Figure 2. Configure a broker connection
Configure a broker connection


  1. Configure a custom port for MQTTS messaging in the FairCom-Edge<version>\config\services.json file.

    Note

    • This step is optional.

    • The port defaults to 8883.

  2. Select the MQ API from the Select API dropdown menu.

  3. Select "configureBrokerConnection" from the JSON Actions dropdown menu.

  4. Insert the "brokerPort" and "brokerTLS" properties into the API Request.

    Figure 3. Insert "brokerPort" and "brokerTLS"
    Insert "brokerPort" and "brokerTLS"


    1. Click the Show all action properties icon (ShowAllActionProperties.png) (see Figure 3, “Insert "brokerPort" and "brokerTLS").

    2. Click the Add Property icon (AddProperty.png) for the "brokerPort" and "brokerTLS" properties.

  5. Replace the "brokerHostname" property value with the applicable values in the following format.

    "brokerHostname": "<uniqueID>-<location>.amazonaws.com",
  6. Replace the "tls" property values with the following "tls" values:

    {
        "api": "mq",
        "apiVersion": "1.0",
        "requestId": "00000006",
        "authToken": "aValidAuthToken",
        "action": "configureBrokerConnection",
        "params": {
            "brokerConnectionName": "AWS_Broker",
            "brokerHostname": "a3306bbg4mk0h9-ats.iot.us-west-2.amazonaws.com",
            "tls": {
                "certificateFilename": "C:/Certificates/certificate.pem.crt",
                "privateKeyFilename": "C:/Certificates/private.pem.key",
                "certificateAuthoritiesFilename": "C:/Certificates/root.pem"
            },
            "brokerPort": 8883
        }
    }
    
  7. Replace the "brokerPort" property value with the port number you are using.

  8. Click Send request (Run.png).

  9. Observe the response and ensure the action completed successfully.

    Note

    "errorCode" with a value of 0 indicates success. "errorCode" with a non-zero value indicates a failure, see Errors and contact FairCom with any questions.

  1. Select MQ API from the Select API dropdown menu.

  2. Select "describeBrokerConnection" from the JSON Actions dropdown menu.

  3. Replace the JSON in the API Request editor with the following JSON:

    {
        "api": "mq",
        "apiVersion": "1.0",
        "authToken": "aValidAuthToken",
        "requestId": "00000011",
        "action": "describeBrokerConnections",
        "params": {
            "brokerConnectionNames": [
                "AWS_Broker"
            ]
        }
    }
    
  4. Observe the response and ensure the action completed successfully.

    Note

    "errorCode" with a value of 0 indicates success. "errorCode" with a non-zero value indicates a failure, see Errors and contact FairCom with any questions.

  1. Select MQ API from the Select API dropdown menu.

  2. Select "configureTopic" from the JSON Actions dropdown menu.

  3. Insert the "forwardToExternalBrokers" property into the API Request.

    Figure 4. Insert "forwardToExternalBrokers"
    Insert "forwardToExternalBrokers"


    1. Click the Show all action properties icon (ShowAllActionProperties.png) (see Figure 4, “Insert "forwardToExternalBrokers").

    2. Click the Add Property icon (AddProperty.png) for the "forwardToExternalBrokers" property.

  4. Replace the "forwardToExternalBrokers" property values with the following "forwardToExternalBrokers" values:

    {
        "api": "mq",
        "apiVersion": "1.0",
        "requestId": "00000014",
        "authToken": "aValidAuthToken",
        "action": "configureTopic",
        "params": {
            "topic": "acmefactory/line1/station1/acidbath/telemetry",
            "forwardToExternalBrokers": [
                {
                    "brokerConnectionName": "AWS_Broker",
                    "topic": "acmefactory/line1/station1/acidbath/telemetry"
                }
            ]
        }
    }
    
  5. Click Send request (Run.png).

  6. Observe the response and ensure the action completed successfully.

    Note

    "errorCode" with a value of 0 indicates success. "errorCode" with a non-zero value indicates a failure, see Errors and contact FairCom with any questions.

The FairCom package includes the ability to run a Python script that can publish to a currently running FairCom broker.

  1. Navigate to and open the publish folder through <FairCom-Edge>\drivers\python.mqtt\pythonMQTTTutorial1.

  2. Open the data.json with a text editor.

  3. Update the data.json file with a test message — for example, test message here.

  4. Run the following command in a command prompt to publish the data.json file to the FairCom broker.

    python publish.py -t acmefactory/line1/station1/acidbath/telemetry -f data.json

    Note

    The publish.py file in the publish folder is preconfigured to publish to port 8883. If you changed this port in services.json, edit the publish.py file to publish to the same port.

For more information to publish and subscribe using FairCom Python.MQTT driver, see MQTT client for Python.

Subscribe to a topic in the test client to see messages published from the FairCom broker to the AWS MQTT test client.

Note

Subscribing to # in the test client, will result in you seeing messages from every topic.

Figure 5. AWS MQTT test client
AWS MQTT test client


  1. Subscribe to all topics.

    1. In the Topic Filter textbox type #.

    2. Click Subscribe (Subscribe.png).

    3. Observe # listed under Subscriptions.

  2. Observe that the message is from the acmefactory/line1/station1/acidbath/telemetry topic which was specified during the Configure a broker connection.

  3. Observe test message here in the message body from the data.json file that was edited in Create a client and publish to the FairCom broker.