AWS IoT Greengrass
Developer Guide

Test Communications

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

    1. On the AWS 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 AWS IoT Greengrass core device (0% packet loss):

      
                        Successful ping command output.

      Note

      If you're unable to ping an EC2 instance that's running AWS 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 AWS IoT endpoint.

    1. On the navigation pane on the home page of the AWS IoT Core console, choose Settings.

    2. Under Settings, 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.

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

    Upon execution, basicDiscovery.py attempts to collect information on the location of the AWS IoT Greengrass core at its endpoints. This information is stored after the 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

    You can 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 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 publisher instances with the hash in the file name for your HelloWorld_Publisher device.

    cd path-to-certs-folder python basicDiscovery.py --endpoint AWS_IOT_ENDPOINT --rootCA root-ca-cert.pem --cert publisher.cert.pem --key publisher.private.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}.

    
                            Screenshot of the publisher output.

    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.

  5. From the HelloWorld_Subscriber 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 subscriber instances with the hash in the file name for your HelloWorld_Subscriber device.

    cd path-to-certs-folder python basicDiscovery.py --endpoint AWS_IOT_ENDPOINT --rootCA root-ca-cert.pem --cert subscriber.cert.pem --key subscriber.private.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 AWS IoT Greengrass core device.

To manually enter the endpoint

  1. Choose Greengrass, choose Groups, and then choose your group.

  2. Choose Settings.

  3. For Local connection detection, choose Manually manage connection information, and then choose View Cores for specific endpoint information.

  4. Choose your core, and then choose Connectivity.

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

  6. Choose Update.