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.
AWS_openssl/aws_iot_src/shadow/aws_iot_shadow_json_data.h@27:2f486c766854, 2017-02-07 (annotated)
- Committer:
- rfinn
- Date:
- Tue Feb 07 16:18:57 2017 +0000
- Revision:
- 27:2f486c766854
- Parent:
- 15:6f2798e45099
changed SDFileSystem library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ampembeng | 15:6f2798e45099 | 1 | /* |
ampembeng | 15:6f2798e45099 | 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
ampembeng | 15:6f2798e45099 | 3 | * |
ampembeng | 15:6f2798e45099 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
ampembeng | 15:6f2798e45099 | 5 | * You may not use this file except in compliance with the License. |
ampembeng | 15:6f2798e45099 | 6 | * A copy of the License is located at |
ampembeng | 15:6f2798e45099 | 7 | * |
ampembeng | 15:6f2798e45099 | 8 | * http://aws.amazon.com/apache2.0 |
ampembeng | 15:6f2798e45099 | 9 | * |
ampembeng | 15:6f2798e45099 | 10 | * or in the "license" file accompanying this file. This file is distributed |
ampembeng | 15:6f2798e45099 | 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
ampembeng | 15:6f2798e45099 | 12 | * express or implied. See the License for the specific language governing |
ampembeng | 15:6f2798e45099 | 13 | * permissions and limitations under the License. |
ampembeng | 15:6f2798e45099 | 14 | */ |
ampembeng | 15:6f2798e45099 | 15 | |
ampembeng | 15:6f2798e45099 | 16 | #ifndef SRC_SHADOW_AWS_IOT_SHADOW_JSON_DATA_H_ |
ampembeng | 15:6f2798e45099 | 17 | #define SRC_SHADOW_AWS_IOT_SHADOW_JSON_DATA_H_ |
ampembeng | 15:6f2798e45099 | 18 | |
ampembeng | 15:6f2798e45099 | 19 | /** |
ampembeng | 15:6f2798e45099 | 20 | * @file aws_iot_shadow_json_data.h |
ampembeng | 15:6f2798e45099 | 21 | * @brief This file is the interface for all the Shadow related JSON functions. |
ampembeng | 15:6f2798e45099 | 22 | */ |
ampembeng | 15:6f2798e45099 | 23 | |
ampembeng | 15:6f2798e45099 | 24 | #include <stddef.h> |
ampembeng | 15:6f2798e45099 | 25 | |
ampembeng | 15:6f2798e45099 | 26 | /** |
ampembeng | 15:6f2798e45099 | 27 | * @brief This is a static JSON object that could be used in code |
ampembeng | 15:6f2798e45099 | 28 | * |
ampembeng | 15:6f2798e45099 | 29 | */ |
ampembeng | 15:6f2798e45099 | 30 | typedef struct jsonStruct jsonStruct_t; |
ampembeng | 15:6f2798e45099 | 31 | /** |
ampembeng | 15:6f2798e45099 | 32 | * @brief Every JSON name value can have a callback. The callback should follow this signature |
ampembeng | 15:6f2798e45099 | 33 | */ |
ampembeng | 15:6f2798e45099 | 34 | typedef void (*jsonStructCallback_t)(const char *pJsonValueBuffer, uint32_t valueLength, jsonStruct_t *pJsonStruct_t); |
ampembeng | 15:6f2798e45099 | 35 | |
ampembeng | 15:6f2798e45099 | 36 | /** |
ampembeng | 15:6f2798e45099 | 37 | * @brief All the JSON object types enum |
ampembeng | 15:6f2798e45099 | 38 | * |
ampembeng | 15:6f2798e45099 | 39 | * JSON number types need to be split into proper integer / floating point data types and sizes on embedded platforms. |
ampembeng | 15:6f2798e45099 | 40 | */ |
ampembeng | 15:6f2798e45099 | 41 | typedef enum { |
ampembeng | 15:6f2798e45099 | 42 | SHADOW_JSON_INT32, |
ampembeng | 15:6f2798e45099 | 43 | SHADOW_JSON_INT16, |
ampembeng | 15:6f2798e45099 | 44 | SHADOW_JSON_INT8, |
ampembeng | 15:6f2798e45099 | 45 | SHADOW_JSON_UINT32, |
ampembeng | 15:6f2798e45099 | 46 | SHADOW_JSON_UINT16, |
ampembeng | 15:6f2798e45099 | 47 | SHADOW_JSON_UINT8, |
ampembeng | 15:6f2798e45099 | 48 | SHADOW_JSON_FLOAT, |
ampembeng | 15:6f2798e45099 | 49 | SHADOW_JSON_DOUBLE, |
ampembeng | 15:6f2798e45099 | 50 | SHADOW_JSON_BOOL, |
ampembeng | 15:6f2798e45099 | 51 | SHADOW_JSON_STRING, |
ampembeng | 15:6f2798e45099 | 52 | SHADOW_JSON_OBJECT |
ampembeng | 15:6f2798e45099 | 53 | } JsonPrimitiveType; |
ampembeng | 15:6f2798e45099 | 54 | |
ampembeng | 15:6f2798e45099 | 55 | /** |
ampembeng | 15:6f2798e45099 | 56 | * @brief This is the struct form of a JSON Key value pair |
ampembeng | 15:6f2798e45099 | 57 | */ |
ampembeng | 15:6f2798e45099 | 58 | struct jsonStruct { |
ampembeng | 15:6f2798e45099 | 59 | const char *pKey; ///< JSON key |
ampembeng | 15:6f2798e45099 | 60 | void *pData; ///< pointer to the data (JSON value) |
ampembeng | 15:6f2798e45099 | 61 | JsonPrimitiveType type; ///< type of JSON |
ampembeng | 15:6f2798e45099 | 62 | jsonStructCallback_t cb; ///< callback to be executed on receiving the Key value pair |
ampembeng | 15:6f2798e45099 | 63 | }; |
ampembeng | 15:6f2798e45099 | 64 | |
ampembeng | 15:6f2798e45099 | 65 | /** |
ampembeng | 15:6f2798e45099 | 66 | * @brief Initialize the JSON document with Shadow expected name/value |
ampembeng | 15:6f2798e45099 | 67 | * |
ampembeng | 15:6f2798e45099 | 68 | * This Function will fill the JSON Buffer with a null terminated string. Internally it uses snprintf |
ampembeng | 15:6f2798e45099 | 69 | * This function should always be used First, followed by iot_shadow_add_reported and/or iot_shadow_add_desired. |
ampembeng | 15:6f2798e45099 | 70 | * Always finish the call sequence with iot_finalize_json_document |
ampembeng | 15:6f2798e45099 | 71 | * |
ampembeng | 15:6f2798e45099 | 72 | * @note Ensure the size of the Buffer is enough to hold the entire JSON Document. |
ampembeng | 15:6f2798e45099 | 73 | * |
ampembeng | 15:6f2798e45099 | 74 | * |
ampembeng | 15:6f2798e45099 | 75 | * @param pJsonDocument The JSON Document filled in this char buffer |
ampembeng | 15:6f2798e45099 | 76 | * @param maxSizeOfJsonDocument maximum size of the pJsonDocument that can be used to fill the JSON document |
ampembeng | 15:6f2798e45099 | 77 | * @return An IoT Error Type defining if the buffer was null or the entire string was not filled up |
ampembeng | 15:6f2798e45099 | 78 | */ |
ampembeng | 15:6f2798e45099 | 79 | IoT_Error_t aws_iot_shadow_init_json_document(char *pJsonDocument, size_t maxSizeOfJsonDocument); |
ampembeng | 15:6f2798e45099 | 80 | |
ampembeng | 15:6f2798e45099 | 81 | /** |
ampembeng | 15:6f2798e45099 | 82 | * @brief Add the reported section of the JSON document of jsonStruct_t |
ampembeng | 15:6f2798e45099 | 83 | * |
ampembeng | 15:6f2798e45099 | 84 | * This is a variadic function and please be careful with the usage. count is the number of jsonStruct_t types that you would like to add in the reported section |
ampembeng | 15:6f2798e45099 | 85 | * This function will add "reported":{<all the values that needs to be added>} |
ampembeng | 15:6f2798e45099 | 86 | * |
ampembeng | 15:6f2798e45099 | 87 | * @note Ensure the size of the Buffer is enough to hold the reported section + the init section. Always use the same JSON document buffer used in the iot_shadow_init_json_document function. This function will accommodate the size of previous null terminated string, so pass teh max size of the buffer |
ampembeng | 15:6f2798e45099 | 88 | * |
ampembeng | 15:6f2798e45099 | 89 | * |
ampembeng | 15:6f2798e45099 | 90 | * @param pJsonDocument The JSON Document filled in this char buffer |
ampembeng | 15:6f2798e45099 | 91 | * @param maxSizeOfJsonDocument maximum size of the pJsonDocument that can be used to fill the JSON document |
ampembeng | 15:6f2798e45099 | 92 | * @param count total number of arguments(jsonStruct_t object) passed in the arguments |
ampembeng | 15:6f2798e45099 | 93 | * @return An IoT Error Type defining if the buffer was null or the entire string was not filled up |
ampembeng | 15:6f2798e45099 | 94 | */ |
ampembeng | 15:6f2798e45099 | 95 | IoT_Error_t aws_iot_shadow_add_reported(char *pJsonDocument, size_t maxSizeOfJsonDocument, uint8_t count, ...); |
ampembeng | 15:6f2798e45099 | 96 | |
ampembeng | 15:6f2798e45099 | 97 | /** |
ampembeng | 15:6f2798e45099 | 98 | * @brief Add the desired section of the JSON document of jsonStruct_t |
ampembeng | 15:6f2798e45099 | 99 | * |
ampembeng | 15:6f2798e45099 | 100 | * This is a variadic function and please be careful with the usage. count is the number of jsonStruct_t types that you would like to add in the reported section |
ampembeng | 15:6f2798e45099 | 101 | * This function will add "desired":{<all the values that needs to be added>} |
ampembeng | 15:6f2798e45099 | 102 | * |
ampembeng | 15:6f2798e45099 | 103 | * @note Ensure the size of the Buffer is enough to hold the reported section + the init section. Always use the same JSON document buffer used in the iot_shadow_init_json_document function. This function will accommodate the size of previous null terminated string, so pass the max size of the buffer |
ampembeng | 15:6f2798e45099 | 104 | * |
ampembeng | 15:6f2798e45099 | 105 | * |
ampembeng | 15:6f2798e45099 | 106 | * @param pJsonDocument The JSON Document filled in this char buffer |
ampembeng | 15:6f2798e45099 | 107 | * @param maxSizeOfJsonDocument maximum size of the pJsonDocument that can be used to fill the JSON document |
ampembeng | 15:6f2798e45099 | 108 | * @param count total number of arguments(jsonStruct_t object) passed in the arguments |
ampembeng | 15:6f2798e45099 | 109 | * @return An IoT Error Type defining if the buffer was null or the entire string was not filled up |
ampembeng | 15:6f2798e45099 | 110 | */ |
ampembeng | 15:6f2798e45099 | 111 | IoT_Error_t aws_iot_shadow_add_desired(char *pJsonDocument, size_t maxSizeOfJsonDocument, uint8_t count, ...); |
ampembeng | 15:6f2798e45099 | 112 | |
ampembeng | 15:6f2798e45099 | 113 | /** |
ampembeng | 15:6f2798e45099 | 114 | * @brief Finalize the JSON document with Shadow expected client Token. |
ampembeng | 15:6f2798e45099 | 115 | * |
ampembeng | 15:6f2798e45099 | 116 | * This function will automatically increment the client token every time this function is called. |
ampembeng | 15:6f2798e45099 | 117 | * |
ampembeng | 15:6f2798e45099 | 118 | * @note Ensure the size of the Buffer is enough to hold the entire JSON Document. If the finalized section is not invoked then the JSON doucment will not be valid |
ampembeng | 15:6f2798e45099 | 119 | * |
ampembeng | 15:6f2798e45099 | 120 | * |
ampembeng | 15:6f2798e45099 | 121 | * @param pJsonDocument The JSON Document filled in this char buffer |
ampembeng | 15:6f2798e45099 | 122 | * @param maxSizeOfJsonDocument maximum size of the pJsonDocument that can be used to fill the JSON document |
ampembeng | 15:6f2798e45099 | 123 | * @return An IoT Error Type defining if the buffer was null or the entire string was not filled up |
ampembeng | 15:6f2798e45099 | 124 | */ |
ampembeng | 15:6f2798e45099 | 125 | IoT_Error_t aws_iot_finalize_json_document(char *pJsonDocument, size_t maxSizeOfJsonDocument); |
ampembeng | 15:6f2798e45099 | 126 | |
ampembeng | 15:6f2798e45099 | 127 | /** |
ampembeng | 15:6f2798e45099 | 128 | * @brief Fill the given buffer with client token for tracking the Repsonse. |
ampembeng | 15:6f2798e45099 | 129 | * |
ampembeng | 15:6f2798e45099 | 130 | * This function will add the AWS_IOT_MQTT_CLIENT_ID with a sequence number. Every time this function is used the sequence number gets incremented |
ampembeng | 15:6f2798e45099 | 131 | * |
ampembeng | 15:6f2798e45099 | 132 | * |
ampembeng | 15:6f2798e45099 | 133 | * @param pBufferToBeUpdatedWithClientToken buffer to be updated with the client token string |
ampembeng | 15:6f2798e45099 | 134 | * @param maxSizeOfJsonDocument maximum size of the pBufferToBeUpdatedWithClientToken that can be used |
ampembeng | 15:6f2798e45099 | 135 | * @return An IoT Error Type defining if the buffer was null or the entire string was not filled up |
ampembeng | 15:6f2798e45099 | 136 | */ |
ampembeng | 15:6f2798e45099 | 137 | |
ampembeng | 15:6f2798e45099 | 138 | IoT_Error_t aws_iot_fill_with_client_token(char *pBufferToBeUpdatedWithClientToken, size_t maxSizeOfJsonDocument); |
ampembeng | 15:6f2798e45099 | 139 | |
ampembeng | 15:6f2798e45099 | 140 | #endif /* SRC_SHADOW_AWS_IOT_SHADOW_JSON_DATA_H_ */ |
ampembeng | 15:6f2798e45099 | 141 |