AWS IoT Greengrass
Developer Guide

Test Communications (Device Syncs Disabled)

  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 home page of the AWS IoT Core console, choose Settings.

      
                The Settings page selected in the AWS IoT Core console.
    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 GG_Switch device and the other represents the GG_TrafficLight device.

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

  4. From the GG_Switch 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 switch instances with the hash in the file name for your GG_Switch device.

    cd path-to-certs-folder python lightController.py --endpoint AWS_IOT_ENDPOINT --rootCA root-ca-cert.pem --cert switch.cert.pem --key switch.private.key --thingName GG_TrafficLight --clientId GG_Switch
  5. From the GG_TrafficLight 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 light instances with the hash in the file name for your GG_TrafficLight device.

    cd path-to-certs-folder python trafficLight.py --endpoint AWS_IOT_ENDPOINT --rootCA root-ca-cert.pem --cert light.cert.pem --key light.private.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.
  6. In the AWS IoT Core console, choose your AWS IoT Greengrass group, choose Devices, and then choose GG_TrafficLight.

    
                            Screenshot of Devices page with GG_TrafficLIght
                                highlighted.
  7. Choose Shadow. After the GG_Switch changes states, there should not be any updates to this shadow topic in Shadow State. That's because the GG_TrafficLight is set to LOCAL SHADOW ONLY as opposed to SHADOW SYNCING TO CLOUD.

  8. Press Ctrl + C in the GG_Switch (lightController.py) 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.