AWS IoT core and MQTT services: test with console and MQTT.fx – 6

Spread the love

Now we have a series of devices connected, but we must test if all work well, to do that, we are going to discover some essential test instruments.

Amazon AWS IoT Core MQTT test online and with MQTT fx
Amazon AWS IoT Core MQTT test online and with MQTT fx

AWS IoT Online console

We can use the IoT AWS console to test the flow. Click on the left menu Test.
https://eu-west-1.console.aws.amazon.com/iot/home?region=eu-west-1#/test (Europe)
https://us-east-1.console.aws.amazon.com/iot/home?region=us-east-1#/test (North America)

Now write relay/pub on the Subscription topic input box, then click Subscribe button; on Arduino IDE, upload the sketch and open Serial monitor.

IoT Core Subscribe Test with Client MQTT
IoT Core Subscribe Test with Client MQTT

The message sent by the microcontroller will appear on the test page.

Connecting to reef-casa-sopra 
1.

Connection established!
IP address:	192.168.1.179
Connecting to AWS IOT
Message on relay/pub topic... Published!
Message on relay/pub topic... Published!
Message on relay/pub topic... Published!
incoming: [relay/sub]
---------------------------
{
  "message": "Hello from AWS IoT console",
  "status": "OK"
}
---------------------------
Message on relay/pub topic... Published!
Message on relay/pub topic... Published!
Message on relay/pub topic... Published!

Now in the Test page of the IoT Core console, click on Publish to a topic, insert in Publish input box relay/sub and click Publish to the topic button.

IoT Core Publish Test with Client MQTT
IoT Core Publish Test with Client MQTT

The published result is in the serial output of our microcontroller.

incoming: [relay/sub]
---------------------------
{
  "message": "Hello from AWS IoT console",
  "status": "OK"
}
---------------------------

MQTT.fx

To use MQTT.fx without using an existing configuration, we must create a thing with a proper certificate.

If this is the first device of this guide, you can refer to the article of this series, “AWS IoT core and MQTT services: creating AWS thing with certificate and policy” to create a new thing, use mqttfx_test for the name and save the certificate

If you have followed all steps of this guide, check these steps.

Create new thing

In the project that you have already downloaded, check that exist the folder mqttfx_test/certificates, if not, create It.

  1. In the AWS IoT console (IoT Core), choose from the left menù Manage and Things.
    Or directly:
    https://us-east-1.console.aws.amazon.com/iot/home?region=us-east-1#/thinghub (North America)
    https://eu-west-1.console.aws.amazon.com/iot/home?region=eu-west-1#/thinghub (Europe)
  2. Than click on Create button in the top right, than Register a single AWS IoT thing.
  3. Name the new thing mqttfx_test, and copy this also in the setup.txt file on [Device name] section. Leave the remaining fields set to their defaults. Choose Next.
  4.  Choose Create certificate.
  5. Download inside the folder mqttfx_test/certificates: Thing cert, private key, than click near A CA root per AWS IoT the Download link, and select Amazon Root CA 1.
  6. Choose Activate.
  7. Then click on Attach a policy.
  8. Select the esp8266_relay_policy.
  9. Click Done.
IoT Core esp8266 esp32 MQTT Certificates download
IoT Core esp8266 esp32 MQTT Certificates download

Modify policy to add new device

  1. To change policy you must go to AWS IoT Console;
  2. To the left menu you must click on Secure than in sub menu select Policies
    https://eu-west-1.console.aws.amazon.com/iot/home?region=eu-west-1#/policy/esp8266_relay_policy (Europe)
    https://us-east-1.console.aws.amazon.com/iot/home?region=us-east-1#/policy/esp8266_relay_policy (North America);
  3. Click on esp8266_relay_policy;
  4. Click in the top right of the text of policy Edit policy document;
  5. All permission of subscription to topic is ready you must only add this lines
    {
      "Effect": "Allow",
      "Action": "iot:Connect",
      "Resource": "arn:aws:iot:[Region]:[Account ID]:client/mqttfx_test"
    },

mqttfx_test is the name of the thing created now.

  1. And now click on Save as new version.

Configure MQTT.fx

Now we are going to set all the information needed for our client.

Amazon AWS IoT Core MQTT configure MQTT.fx
Amazon AWS IoT Core MQTT configure MQTT.fx
  1. In the ClientID put the thing name mqttfx_test;
  2. Select SSL/TLS tab, and select Self signed certificates;
  3. Put AmazonRootCA1.pem certificate on CA File;
  4. Put XXXXXXXXX-certificate.pem.crt on Client Certificate File;
  5. Put XXXXXXXXX-private.pem.key in Client Key File;
  6. Verify PEM Formatted is checked;

Now your client is configured, you can click on Connect button.

Now on subscribe, insert relay/sub and Subscribe button.

Amazon AWS IoT Core MQTT MQTT fx publish and subscribe
Amazon AWS IoT Core MQTT MQTT fx publish and subscribe

In Publish section, you can add relay/pub and write something in the text area, then click Publish button.

Amazon AWS IoT Core MQTT online test publish and subscribe
Amazon AWS IoT Core MQTT online test publish and subscribe.

Thanks

  1. AWS IoT core and MQTT services: introduction and prerequisite
  2. AWS IoT core and MQTT services: creating AWS thing with certificate and policy
  3. AWS IoT core and MQTT services: connect esp8266 devices
  4. AWS IoT core and MQTT services: connect esp32 devices
  5. AWS IoT core and MQTT services: connect Arduino SAMD (WiFiNINA) devices
  6. AWS IoT core and MQTT services: test with console and MQTT.fx


Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *