Test communications - Amazon IoT Greengrass
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Amazon IoT Greengrass Version 1 no longer receives feature updates, and will receive only security patches and bug fixes until June 30, 2023. For more information, see the Amazon IoT Greengrass V1 maintenance policy. We strongly recommend that you migrate to Amazon IoT Greengrass Version 2, which adds significant new features and support for additional platforms.

Test communications

  1. Make sure that your computer and the Amazon IoT Greengrass core device are connected to the internet using the same network.

    1. On the Amazon IoT Greengrass core device, run the following command to find its IP address.

      hostname -I
    2. On your computer, run the following command using the IP address of the core. You can use Ctrl + C to stop the ping command.

      ping IP-address

      Output similar to the following indicates successful communication between the computer and the Amazon IoT Greengrass core device (0% packet loss):

      
                        Successful ping command output.
      Note

      If you're unable to ping an EC2 instance that's running Amazon IoT Greengrass, make sure that the inbound security group rules for the instance allow ICMP traffic for Echo request messages. For more information, see Adding rules to a security group in the Amazon EC2 User Guide for Linux Instances.

      On Windows host computers, in the Windows Firewall with Advanced Security app, you might also need to enable an inbound rule that allows inbound echo requests (for example, File and Printer Sharing (Echo Request - ICMPv4-In)), or create one.

  2. Get your Amazon IoT endpoint.

    1. From the Amazon IoT console navigation pane, choose Settings.

    2. Under Device data endpoint, make a note of the value of Endpoint. You use this value to replace the AWS_IOT_ENDPOINT placeholder in the commands in the following steps.

  3. On your computer (not the Amazon IoT Greengrass core device), open two command-line (terminal or command prompt) windows. One window represents the HelloWorld_Publisher client device and the other represents the HelloWorld_Subscriber client device.

    Upon execution, basicDiscovery.py attempts to collect information on the location of the Amazon IoT Greengrass core at its endpoints. This information is stored after the client device has discovered and successfully connected to the core. This allows future messaging and operations to be executed locally (without the need for an internet connection).

    Note

    Client IDs used for MQTT connections must match the thing name of the client device. The basicDiscovery.py script sets the client ID for MQTT connections to the thing name that you specify when you run the script.

    Run the following command from the folder that contains the basicDiscovery.py file for detailed script usage information:

    python basicDiscovery.py --help
  4. From the HelloWorld_Publisher client device window, run the following commands.

    • Replace path-to-certs-folder with the path to the folder that contains the certificates, keys, and basicDiscovery.py.

    • Replace AWS_IOT_ENDPOINT with your endpoint.

    • Replace the two publisherCertId instances with the certificate ID in the file name for your HelloWorld_Publisher client device.

    cd path-to-certs-folder python basicDiscovery.py --endpoint AWS_IOT_ENDPOINT --rootCA AmazonRootCA1.pem --cert publisherCertId-certificate.pem.crt --key publisherCertId-private.pem.key --thingName HelloWorld_Publisher --topic 'hello/world/pubsub' --mode publish --message 'Hello, World! Sent from HelloWorld_Publisher'

    You should see output similar to the following, which includes entries such as Published topic 'hello/world/pubsub': {"message": "Hello, World! Sent from HelloWorld_Publisher", "sequence": 1}.

    Note

    If the script returns an error: unrecognized arguments message, change the single quotation marks to double quotation marks for the --topic and --message parameters and run the command again.

    To troubleshoot a connection issue, you can try using manual IP detection.

    
                            Screenshot of the publisher output.
  5. From the HelloWorld_Subscriber client device window, run the following commands.

    • Replace path-to-certs-folder with the path to the folder that contains the certificates, keys, and basicDiscovery.py.

    • Replace AWS_IOT_ENDPOINT with your endpoint.

    • Replace the two subscriberCertId instances with the certificate ID in the file name for your HelloWorld_Subscriber client device.

    cd path-to-certs-folder python basicDiscovery.py --endpoint AWS_IOT_ENDPOINT --rootCA AmazonRootCA1.pem --cert subscriberCertId-certificate.pem.crt --key subscriberCertId-private.pem.key --thingName HelloWorld_Subscriber --topic 'hello/world/pubsub' --mode subscribe

    You should see the following output, which includes entries such as Received message on topic hello/world/pubsub: {"message": "Hello, World! Sent from HelloWorld_Publisher", "sequence": 1}.

    
                            Screenshot of the subscriber output.

Close the HelloWorld_Publisher window to stop messages from accruing in the HelloWorld_Subscriber window.

Testing on a corporate network might interfere with connecting to the core. As a workaround, you can manually enter the endpoint. This ensures that the basicDiscovery.py script connects to the correct IP address of the Amazon IoT Greengrass core device.

To manually enter the endpoint

  1. In the Amazon IoT console navigation pane, under Manage, expand Greengrass devices, and then choose Groups (V1).

  2. Under Greengrass groups, choose your group.

  3. Configure the core to manually manage MQTT broker endpoints. Do the following:

    1. On the group configuration page, choose the Lambda functions tab.

    2. Under System Lambda functions, choose IP detector, and then choose Edit.

    3. In the Edit IP detector settings, choose Manually manage MQTT broker endpoints, and then choose Save.

  4. Enter the MQTT broker endpoint for the core. Do the following:

    1. Under Overview, choose the Greengrass core.

    2. Under MQTT broker endpoints, choose Manage endpoints.

    3. Choose Add endpoint and make sure that you have only one endpoint value. This value must be the IP address endpoint for port 8883 of your Amazon IoT Greengrass core device (for example, 192.168.1.4).

    4. Choose Update.