Demo application for using the AT&T IoT Starter Kit Powered by AWS.
Dependencies: SDFileSystem
Fork of ATT_AWS_IoT_demo by
IoT Starter Kit Powered by AWS Demo
This program demonstrates the AT&T IoT Starter Kit sending data directly into AWS IoT. It's explained and used in the Getting Started with the IoT Starter Kit Powered by AWS on starterkit.att.com.
What's required
- AT&T IoT LTE Add-on (also known as the Cellular Shield)
- NXP K64F - for programming
- microSD card - used to store your AWS security credentials
- AWS account
- Python, locally installed
If you don't already have an IoT Starter Kit, you can purchase a kit here. The IoT Starter Kit Powered by AWS includes the LTE cellular shield, K64F, and a microSD card.
README.md@25:91d771247ac8, 2016-12-19 (annotated)
- Committer:
- ampembeng
- Date:
- Mon Dec 19 20:52:28 2016 +0000
- Revision:
- 25:91d771247ac8
- Parent:
- 24:224c07ec3bd0
Updated the look/feel of the Python GUI to match the AT&T locker demo S3 page. Added "assets" folder to support this. Updated the README.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ampembeng | 21:56f91bdacff1 | 1 | ############################################################################################################# |
ampembeng | 24:224c07ec3bd0 | 2 | Shadow Demo Summary |
ampembeng | 21:56f91bdacff1 | 3 | ############################################################################################################# |
ampembeng | 24:224c07ec3bd0 | 4 | The Shadow demo uses the FRDM-K64F target hardware and the Avnet Shield M14A2A (using AT&T LTE network) to |
ampembeng | 24:224c07ec3bd0 | 5 | connect to an Amazon Web Services IoT "thing" (device). The AWS IoT device Shadow will reflect the FRDM LED |
ampembeng | 24:224c07ec3bd0 | 6 | color along with FRDM sensor data. The Python GUI (ATT_AWS_IoT_Demo_GUI.py) can be used to reflect the Shadow |
ampembeng | 24:224c07ec3bd0 | 7 | information and request LED color changes. |
ampembeng | 24:224c07ec3bd0 | 8 | |
ampembeng | 24:224c07ec3bd0 | 9 | ############################################################################################################# |
ampembeng | 24:224c07ec3bd0 | 10 | Topic Demo Summary |
ampembeng | 24:224c07ec3bd0 | 11 | ############################################################################################################# |
ampembeng | 24:224c07ec3bd0 | 12 | The Topic demo can be ran by following the steps in the "Topic Demo Quickstart" below. Instead of writing to |
ampembeng | 24:224c07ec3bd0 | 13 | the thing Shadow this demo publishes a JSON payload (color/temp/humidity) to a Topic. From AWS you can define |
ampembeng | 24:224c07ec3bd0 | 14 | a Rule to perform any number of actions from the Topic. |
ampembeng | 16:02008a2a2569 | 15 | |
ampembeng | 16:02008a2a2569 | 16 | ############################################################################################################# |
ampembeng | 16:02008a2a2569 | 17 | Resources |
ampembeng | 16:02008a2a2569 | 18 | ############################################################################################################# |
ampembeng | 16:02008a2a2569 | 19 | Getting Started with MBED using FRDM-K64F: (NOTE!!! The FRDM bootloader MUST be updated to work with Windows 10) |
ampembeng | 16:02008a2a2569 | 20 | https://developer.mbed.org/platforms/frdm-k64f/ |
ampembeng | 16:02008a2a2569 | 21 | |
ampembeng | 16:02008a2a2569 | 22 | Avnet IoT Kit quickstart: |
ampembeng | 16:02008a2a2569 | 23 | https://starterkit.att.com/quickstart |
ampembeng | 16:02008a2a2569 | 24 | |
ampembeng | 16:02008a2a2569 | 25 | AWS IoT Interactive Tutorial (what this demo is based on): |
ampembeng | 16:02008a2a2569 | 26 | https://us-west-2.console.aws.amazon.com/iot/home?region=us-west-2#/tutorial/help |
ampembeng | 16:02008a2a2569 | 27 | |
ampembeng | 16:02008a2a2569 | 28 | AWS IoT C-SDK Tutorial (targeted for Raspberry Pi-2): |
ampembeng | 16:02008a2a2569 | 29 | http://docs.aws.amazon.com/iot/latest/developerguide/iot-device-sdk-c.html |
ampembeng | 16:02008a2a2569 | 30 | |
ampembeng | 16:02008a2a2569 | 31 | Python AWS IoT Tutorial: |
ampembeng | 16:02008a2a2569 | 32 | https://github.com/aws/aws-iot-device-sdk-python |
ampembeng | 16:02008a2a2569 | 33 | |
ampembeng | 16:02008a2a2569 | 34 | ############################################################################################################# |
ampembeng | 24:224c07ec3bd0 | 35 | Shadow Demo Quickstart |
ampembeng | 16:02008a2a2569 | 36 | ############################################################################################################# |
ampembeng | 16:02008a2a2569 | 37 | NOTE1: FRDM-K64F bootloader must be updated to work with Windows 10 (otherwise board will reset over and over). |
ampembeng | 16:02008a2a2569 | 38 | |
ampembeng | 16:02008a2a2569 | 39 | FRDM-K64F: |
ampembeng | 16:02008a2a2569 | 40 | 1) This quickstart assumes you've gone through the "Getting Started with MBED using FRDM-K64F" and that you |
ampembeng | 16:02008a2a2569 | 41 | can successfully drag-and-drop binaries to flash the FRDM-K64F device. |
ampembeng | 16:02008a2a2569 | 42 | |
ampembeng | 21:56f91bdacff1 | 43 | |
ampembeng | 16:02008a2a2569 | 44 | AT&T IoT Kit: |
ampembeng | 16:02008a2a2569 | 45 | 1) This quickstart assumes you've gone through the "Avnet IoT Kit quickstart" and your kits sim card has been |
ampembeng | 16:02008a2a2569 | 46 | activated and verified to work with the AT&T LTE network. |
ampembeng | 16:02008a2a2569 | 47 | |
ampembeng | 21:56f91bdacff1 | 48 | |
ampembeng | 16:02008a2a2569 | 49 | Amazon AWS IoT: |
ampembeng | 16:02008a2a2569 | 50 | 1) Create an AWS IoT thing using AWS IoT Console. Makes sure to get your 'thing' certificates. |
mbed_official | 2:270602af41c9 | 51 | |
ampembeng | 21:56f91bdacff1 | 52 | |
ampembeng | 16:02008a2a2569 | 53 | MBED: |
ampembeng | 16:02008a2a2569 | 54 | 1) In the mbed ATT_AWS_IoT_demo project open "network_interface.h" and comment in the following: |
ampembeng | 24:224c07ec3bd0 | 55 | #define USING_AVNET_SHIELD |
ampembeng | 24:224c07ec3bd0 | 56 | |
ampembeng | 24:224c07ec3bd0 | 57 | NOTE: Make sure you only comment in ONE Network Connection. Alternately you can comment in |
ampembeng | 24:224c07ec3bd0 | 58 | USING_FRDM_K64F_LWIP to use the wired Ethernet. |
ampembeng | 24:224c07ec3bd0 | 59 | |
ampembeng | 16:02008a2a2569 | 60 | |
ampembeng | 21:56f91bdacff1 | 61 | 2a) Option a (default) - Use an SD card: |
ampembeng | 21:56f91bdacff1 | 62 | a) Format a MicroSD card to use a "FAT32" file system (https://www.sdcard.org/downloads/formatter_4/) |
ampembeng | 21:56f91bdacff1 | 63 | |
ampembeng | 21:56f91bdacff1 | 64 | b) Create a folder on the SD card root named 'certs' |
ampembeng | 21:56f91bdacff1 | 65 | |
ampembeng | 21:56f91bdacff1 | 66 | c) Copy your AWS things certs into this folder. Your file paths should look exactly like this: |
ampembeng | 21:56f91bdacff1 | 67 | /certs/rootCA-certificate.crt |
ampembeng | 21:56f91bdacff1 | 68 | /certs/certificate.pem.crt |
ampembeng | 21:56f91bdacff1 | 69 | /certs/private.pem.key |
ampembeng | 21:56f91bdacff1 | 70 | |
ampembeng | 21:56f91bdacff1 | 71 | d) Create a file in the 'certs' directory named 'mqtt_config.txt', and copy the template below into the file |
ampembeng | 21:56f91bdacff1 | 72 | fill in these parameters with your AWS IoT thing information (minus the brackets): |
ampembeng | 21:56f91bdacff1 | 73 | NOTE: Port is always 8883 (if not using web socket) |
ampembeng | 21:56f91bdacff1 | 74 | AWS_IOT_MQTT_HOST=[1234asdf.iot.us-west-2.amazonaws.com] |
ampembeng | 21:56f91bdacff1 | 75 | AWS_IOT_MQTT_PORT=8883 |
ampembeng | 21:56f91bdacff1 | 76 | AWS_IOT_MQTT_CLIENT_ID=[MyThingName] |
ampembeng | 21:56f91bdacff1 | 77 | AWS_IOT_MY_THING_NAME=[MyThingName] |
ampembeng | 16:02008a2a2569 | 78 | |
ampembeng | 21:56f91bdacff1 | 79 | e) Place SD card into the FRDM-K64F MicroSD slot before powering it on. |
ampembeng | 21:56f91bdacff1 | 80 | |
ampembeng | 21:56f91bdacff1 | 81 | |
ampembeng | 21:56f91bdacff1 | 82 | 2b) Option b - Hard code certs/key and MQTT config: |
ampembeng | 21:56f91bdacff1 | 83 | a) In the mbed ATT_AWS_IoT_demo project open "aws_iot_config.h" and comment out the following #define: |
ampembeng | 21:56f91bdacff1 | 84 | //#define USING_SD_CARD |
ampembeng | 21:56f91bdacff1 | 85 | |
ampembeng | 21:56f91bdacff1 | 86 | b) In the mbed ATT_AWS_IoT_demo project open "aws_iot_config.h" and update the following to match your AWS |
ampembeng | 21:56f91bdacff1 | 87 | IoT 'thing': |
ampembeng | 21:56f91bdacff1 | 88 | #define AWS_IOT_MQTT_HOST |
ampembeng | 21:56f91bdacff1 | 89 | #define AWS_IOT_MQTT_CLIENT_ID |
ampembeng | 21:56f91bdacff1 | 90 | #define AWS_IOT_MY_THING_NAME |
ampembeng | 21:56f91bdacff1 | 91 | |
ampembeng | 21:56f91bdacff1 | 92 | c) In the mbed ATT_AWS_IoT_demo project open "certs.cpp" and update the following to match your AWS 'thing' |
ampembeng | 21:56f91bdacff1 | 93 | private key and IoT certificate. NOTE Make sure the string format matches the format of AWS_IOT_ROOT_CA |
ampembeng | 21:56f91bdacff1 | 94 | (which is pre-populated): |
ampembeng | 21:56f91bdacff1 | 95 | const unsigned char AWS_IOT_CERTIFICATE[] |
ampembeng | 21:56f91bdacff1 | 96 | const unsigned char AWS_IOT_PRIVATE_KEY[] |
ampembeng | 21:56f91bdacff1 | 97 | |
ampembeng | 16:02008a2a2569 | 98 | |
ampembeng | 16:02008a2a2569 | 99 | Python GUI (optional): |
ampembeng | 16:02008a2a2569 | 100 | 1) The Python GUI "ATT_AWS_IoT_Demo_GUI.py" is used to communicate with the 'thing' device shadow, and can |
ampembeng | 16:02008a2a2569 | 101 | be used to request 'desired' and report 'reported' shadow states. This quickstart assumes you've gone |
ampembeng | 16:02008a2a2569 | 102 | through the "Python AWS IoT Tutorial" to the point where you've installed Python 2.7.11 and the libraries |
ampembeng | 16:02008a2a2569 | 103 | required to run the script (paho-mqtt, AWSIoTPythonSDK). |
ampembeng | 16:02008a2a2569 | 104 | |
ampembeng | 25:91d771247ac8 | 105 | 2) Copy the mbed project folder "PythonGUI" onto your PC somewhere. "C:/Temp/PythonGUI" for example. |
ampembeng | 21:56f91bdacff1 | 106 | |
ampembeng | 25:91d771247ac8 | 107 | 3a) Option a (default) - Use an mqtt_config.txt file: |
ampembeng | 21:56f91bdacff1 | 108 | a) Use the same mqtt_config.txt file from MBED section above. |
ampembeng | 21:56f91bdacff1 | 109 | b) Place the file where Python looks for it: |
ampembeng | 21:56f91bdacff1 | 110 | AWS_MQTT_CONFIG_FILENAME = "C:/Temp/certs/mqtt_config.txt" |
ampembeng | 16:02008a2a2569 | 111 | |
ampembeng | 25:91d771247ac8 | 112 | 3b) Option b - Hard code the MQTT config: |
ampembeng | 21:56f91bdacff1 | 113 | a) In the ATT_AWS_IoT_Demo_GUI.py script search for the "AWS IoT Config Parameters" and update them so they |
ampembeng | 21:56f91bdacff1 | 114 | match the same 'thing' parameters as the mbed project. |
ampembeng | 21:56f91bdacff1 | 115 | |
ampembeng | 21:56f91bdacff1 | 116 | b) In the Python file change the following variable to TRUE: |
ampembeng | 21:56f91bdacff1 | 117 | hardCodeMQTT = True |
ampembeng | 21:56f91bdacff1 | 118 | |
ampembeng | 25:91d771247ac8 | 119 | 4) Place your 'thing' certificates into file locations where the Python looks for them. For example: |
ampembeng | 16:02008a2a2569 | 120 | AWS_IOT_ROOT_CA_FILENAME = "C:/Temp/certs/rootCA-certificate.crt" |
ampembeng | 16:02008a2a2569 | 121 | AWS_IOT_PRIVATE_KEY_FILENAME = "C:/Temp/certs/private.pem.key" |
ampembeng | 16:02008a2a2569 | 122 | AWS_IOT_CERTIFICATE_FILENAME = "C:/Temp/certs/certificate.pem.crt" |
ampembeng | 25:91d771247ac8 | 123 | |
ampembeng | 16:02008a2a2569 | 124 | Once all this is setup you should be able to: |
ampembeng | 16:02008a2a2569 | 125 | 1) See the FRDM board start up and connect to Amazon and then create a 'thing' shadow (if there is none). |
ampembeng | 16:02008a2a2569 | 126 | 2) See the FRDM board get the shadow LED color. |
ampembeng | 16:02008a2a2569 | 127 | 3) Press the SW3 button on the FRDM board to cycle the LED color -> (Off R G B W) |
ampembeng | 16:02008a2a2569 | 128 | 4) Use the AWS IoT Console to "Update shadow" to set new 'desired' colors via -> (0 1 2 4 7) |
ampembeng | 21:56f91bdacff1 | 129 | 5) Use the Python GUI buttons to request 'desired' colors. The GUI should also report the "AWS Reported LED Status" |
ampembeng | 24:224c07ec3bd0 | 130 | 6) See the FRDM board report the Temperature and Humidity values. |
ampembeng | 24:224c07ec3bd0 | 131 | |
ampembeng | 24:224c07ec3bd0 | 132 | ############################################################################################################# |
ampembeng | 24:224c07ec3bd0 | 133 | Topic Demo Quickstart |
ampembeng | 24:224c07ec3bd0 | 134 | ############################################################################################################# |
ampembeng | 24:224c07ec3bd0 | 135 | 1) In order to setup the Topic Demo you still have to perform all of the Shadow Demo steps. |
ampembeng | 24:224c07ec3bd0 | 136 | |
ampembeng | 24:224c07ec3bd0 | 137 | 2) In the mbed ATT_AWS_IoT_demo project open "main.cpp" and comment in the following line: |
ampembeng | 24:224c07ec3bd0 | 138 | //return outOfBoxDemo(); |
ampembeng | 24:224c07ec3bd0 | 139 | |
ampembeng | 24:224c07ec3bd0 | 140 | 3) In the mbed ATT_AWS_IoT_demo project open "aws_iot_config.h" and set the AWS_IOT_MY_TOPIC: |
ampembeng | 24:224c07ec3bd0 | 141 | #define AWS_IOT_MY_TOPIC "ExampleTopic/%s" |
ampembeng | 24:224c07ec3bd0 | 142 | |
ampembeng | 24:224c07ec3bd0 | 143 | 4) In AWS Console go to AWS IoT -> Test -> Subscribe to a topic and as the topic name put in "ExampleTopic/+" |
ampembeng | 24:224c07ec3bd0 | 144 | // NOTE: the "/+" is a wildcard, this demo puts the ICCID there. This allows you to have multiple devices |
ampembeng | 24:224c07ec3bd0 | 145 | // publish to the same Topic. |
ampembeng | 24:224c07ec3bd0 | 146 | |
ampembeng | 24:224c07ec3bd0 | 147 | Once all this is setup you should be able to: |
ampembeng | 24:224c07ec3bd0 | 148 | Wait for the target to print "READY TO PUBLISH!" |
ampembeng | 24:224c07ec3bd0 | 149 | Press the SW3 button, and the LED should change color and a JSON packet will be sent to the Topic |
ampembeng | 24:224c07ec3bd0 | 150 | In the AWS Console you should see the Topic data, for example -> "{"color":"Blue","temperature":86.876564,"humidity":36}" |