Test communications (device syncs disabled) - 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 (device syncs disabled)

  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 GG_Switch client device and the other represents the GG_TrafficLight client device.

    1. From the GG_Switch client device window, run the following commands.

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

      • Replace AWS_IOT_ENDPOINT with your endpoint.

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

      cd path-to-certs-folder python lightController.py --endpoint AWS_IOT_ENDPOINT --rootCA AmazonRootCA1.pem --cert switchCertId-certificate.pem.crt --key switchCertId-private.pem.key --thingName GG_TrafficLight --clientId GG_Switch
    2. From the GG_TrafficLight client device window, run the following commands.

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

      • Replace AWS_IOT_ENDPOINT with your endpoint.

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

      cd path-to-certs-folder python trafficLight.py --endpoint AWS_IOT_ENDPOINT --rootCA AmazonRootCA1.pem --cert lightCertId-certificate.pem.crt --key lightCertId-private.pem.key --thingName GG_TrafficLight --clientId GG_TrafficLight

      Every 20 seconds, the switch updates the shadow state to G, Y, and R, and the light displays its new state, as shown next.

      GG_Switch output:

      
                                    Screenshot of the output associated with
                                        GG_Switch.

      GG_TrafficLight output:

      
                                    Screenshot of the output associated with
                                        GG_TrafficLight.

    When executed for the first time, each client device script runs the Amazon IoT Greengrass discovery service to connect to the Amazon IoT Greengrass core (through the internet). After a client device has discovered and successfully connected to the Amazon IoT Greengrass core, future operations can be executed locally.

    Note

    The lightController.py and trafficLight.py scripts store connection information in the groupCA folder, which is created in the same folder as the scripts. If you receive connection errors, make sure that the IP address in the ggc-host file matches the IP address endpoint for your core.

  4. In the Amazon IoT console, choose your Amazon IoT Greengrass group, choose the Client devices tab, and then choose GG_TrafficLight to open the client device's Amazon IoT thing details page.

  5. Choose the Device Shadows tab. After the GG_Switch changes states, there should not be any updates to this shadow. That's because the GG_TrafficLight is set to Disable shadow sync with cloud.

  6. Press Ctrl + C in the GG_Switch (lightController.py) client device window. You should see that the GG_TrafficLight (trafficLight.py) window stops receiving state change messages.

    Keep these windows open so you can run the commands in the next section.