├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── aws_protocol_adaptor └── device_client │ ├── .DS_Store │ ├── Makefile │ ├── aws_config_parser.c │ ├── aws_config_parser.h │ ├── aws_iot_config.h │ ├── aws_nvmsgbroker.c │ ├── aws_nvmsgbroker.h │ ├── aws_nvmsgbroker_test.c │ ├── cfg_aws.txt │ └── libnvds_aws_proto.so └── success_screen.png /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *master* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | 61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS IoT Core Integration with NVIDIA DeepStream 2 | This project implements protocol adaptor between NVIDIA DeepStream SDK and AWS (edge to cloud messaging). 3 | The adaptor implements the API for client applications to publish inference results or metadata using MQTT messages to AWS IoT Core. 4 | 5 | ## Pre-requisites 6 | 7 | * AWS account admin console access (for this tutorial) 8 | * A Jetson device with DeepStream SDK installed and public internet access 9 | * Gstreamer installation as described in the [NVIDIA documentation](https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/accelerated_gstreamer.html) 10 | 11 | For the convenience of this installation, we can create an environment variable of the path where you DeepStream SDK is installed. Please replace to the path of your DeepStream SDK on your Jetson device. (For DeepStream 5.0, the default installation path is "/opt/nvidia/deepstream/deepstream-5.0/".) 12 | ``` 13 | export DEEPSTREAM_SDK_PATH= 14 | ``` 15 | 16 | ## Installation Guide: 17 | ### Step 1: Download AWS DeepStream adaptor 18 | 19 | In your Jetson device, navigate to Downloads folder, then download or clone the [AWS managed GitHub](https://github.com/awslabs/aws-iot-core-integration-with-nvidia-deepstream) repo. Copy the aws_protocol_adaptor sub-folder to ${DEEPSTREAM_SDK_PATH}/sources/libs. 20 | ``` 21 | cd ~/Downloads 22 | git clone https://github.com/awslabs/aws-iot-core-integration-with-nvidia-deepstream.git 23 | cd aws-iot-core-integration-with-nvidia-deepstream 24 | cp -r aws_protocol_adaptor ${DEEPSTREAM_SDK_PATH}/sources/libs 25 | ``` 26 | 27 | ### [Optional] Step 2: Manually build the shared library (You can skip this step if you want to use the .so file that we built for you.) 28 | 29 | he shared library (.so file) is built and checked in the git repo you cloned in Step 1 in the aws_protocol_adaptor/device_client directory. If you want to build and customize your shared library, you can follow step 2 to compile with customized features such as optimized buffer size for incoming or outgoing MQTT messages, or TLS connection timeout values. 30 | 31 | If cloned or downloaded successfully, aws_protocol_adaptor should appear in your current path. Next, we need to create an empty directory for [AWS IoT device SDK](https://github.com/aws/aws-iot-device-sdk-embedded-C/tree/v3.1.1) library. We also need to clone the [AWS IoT device SDK](https://github.com/aws/aws-iot-device-sdk-embedded-C/tree/v3.1.1) in Embedded-C version 3 into this empty directory we created. (Please note that we are aware that AWS IoT Embedded SDK Version 4 does not currently work with this project. It is in our roadmap to support this latest version 4 SDK in the near future.) 32 | ``` 33 | mkdir ${DEEPSTREAM_SDK_PATH}/sources/libs/aws_protocol_adaptor/aws-iot-sdk 34 | cd ${DEEPSTREAM_SDK_PATH}/sources/libs/aws_protocol_adaptor/aws-iot-sdk 35 | git clone --branch v3.1.1 https://github.com/aws/aws-iot-device-sdk-embedded-C.git 36 | ``` 37 | This AWS IoT device SDK has an external dependency on Mbed TLS, so navigate to aws-iot-sdk/external_libs/. And clone the existing Mbed TLS repo in this folder: 38 | 39 | ``` 40 | cd ${DEEPSTREAM_SDK_PATH}/sources/libs/aws_protocol_adaptor/aws-iot-sdk/external_libs/mbedTLS 41 | git clone https://github.com/ARMmbed/mbedtls.git 42 | ``` 43 | Navigate to device_client folder, and compile the shared library: 44 | ``` 45 | cd ${DEEPSTREAM_SDK_PATH}/sources/libs/aws_protocol_adaptor/device_client 46 | make clean 47 | make 48 | ``` 49 | If you inspect this current folder, you should see the libnvds_aws_proto.so file just updated. 50 | 51 | ### Step 3: Provision DeepStream App with AWS IoT credentials 52 | Navigate to AWS web console, and go to *IoT Core* service. On the left-side menu, click on *Secure* → *Policies*. And on the right upper corner, click on *Create*. A window would appear to help you create a policy for your thing you are about to create for DeepStream Application. You can also do this with AWS CLI. Please refer to [AWS IoT Policy Elements](https://docs.aws.amazon.com/iot/latest/developerguide/example-iot-policies-elements.html) for list of actions in AWS IoT to allow or deny. 53 | 54 | After creating the policy, you can then create a thing for DeepStream Application. You can do this on AWS console by going to the left-side AWS IoT service page, click on *Manage->Things.* And on the right upper corner, click on *Create*. This would start the process of creating a thing on AWS IoT. You can also do this with AWS CLI. Please note down the thing name you have used to create this thing, you will later need it. 55 | 56 | If you are using AWS console, after creating the thing, a new page would appear with download links for the certificates we just generated for this thing, download all of them. For root certificate, a link would redirect you to a root certificate download page. You can download Amazon Root CA1. And you can click on the *Activate* button on this page to activate the set of certificates that you just downloaded. 57 | 58 | Then click on *Attach Policy*, and choose the policy named *ds_app_policy* you just created. 59 | 60 | ### Step 4: Transfer certificates to Jetson device 61 | Navigate to the path of your downloaded certs. You should see four files in the following naming format: 62 | ``` 63 | XXX-certificate.pem.crt 64 | XXX-private.pem.key 65 | XXX-public.pem.key 66 | AmazonRootCA1.pem 67 | ``` 68 | You can change them to: 69 | ``` 70 | certificatePem.cert.pem 71 | privateKey.private.key 72 | publicKey.public.key 73 | root.ca.pem 74 | ``` 75 | You can then make a cert folder on your Jetson device, and transfer these downloaded certificates and keys to your Jetson device. In this demo, we are going to put these certificates in the following directory. 76 | ``` 77 | mkdir ${DEEPSTREAM_SDK_PATH}/sources/libs/aws_protocol_adaptor/device_client/certs 78 | mv <4 CERTS FILES> ${DEEPSTREAM_SDK_PATH}/sources/libs/aws_protocol_adaptor/device_client/certs 79 | ``` 80 | On your Jetson device, navigate to: 81 | ``` 82 | cd ${DEEPSTREAM_SDK_PATH}/sources/libs/aws_protocol_adaptor/device_client/ 83 | ``` 84 | Edit cfg_aws.txt: 85 | * Replace with your AWS IoT Endpoint URL, which can be found in the AWS IoT console → setting, in the box showing Endpoint. 86 | * Replace to the *absolute* *path* of your DeepStream SDK PATH. (WARNING: Using relative path sometimes would cause certificate parsing failure error). 87 | * Replace the values of both ThingName and ClientID with the name of the thing created above. 88 | 89 | ### Step 5: Run Deepstream App 90 | We are going to use the test apps developed by NVIDIA to verify our adaptor setup. We are going to run tests with both test4 and test5 in NVIDIA DeepStream SDK sample app folder. The deepstream-test4 can be used to demonstrate adding custom objects as NVDS_EVENT_MSG_META user metadata with buffers for generating a custom payload to be published to AWS IoT Core. The deepstream-test5 can demonstrate how to use "nvmsgconv" and "nvmsgbroker" plugins in the pipeline, create NVDS_META_EVENT_MSG type of meta, and upload to AWS IoT Core. Both apps can help verify the installation and functionalities of this message broker. 91 | 92 | #### Install dependency on your Jetson 93 | Install libgstrtspserver-1.0-dev 94 | ``` 95 | sudo apt-get install libgstrtspserver-1.0-dev 96 | ``` 97 | #### Test App 4 98 | Please first navigate to test4 in your DeepStream SDK, and make the app: 99 | ``` 100 | cd ${DEEPSTREAM_SDK_PATH}/sources/apps/sample_apps/deepstream-test4 101 | make 102 | ``` 103 | Then, you can use the following command to run test4. 104 | ``` 105 | ./deepstream-test4-app -i ../../../../samples/streams/sample_720p.h264 -p ../../../libs/aws_protocol_adaptor/device_client/libnvds_aws_proto.so --conn-str=hello -c ../../../libs/aws_protocol_adaptor/device_client/cfg_aws.txt -t test --no-display 106 | ``` 107 | Now navigate to AWS IoT console, and on the menu bar on the left, click on test, type in test (or # to receive messages on all topics) in the subscription topic box, and click on *Subscribe to topic*, you should see MQTT messages start to show up on this console after app successfully runs: 108 | ![Image of success](./success_screen.png) 109 | 110 | #### Test App 5 111 | Please navigate to test5 in your DeepStream SDK, and make the app. Please note you need a display connected for this test app. 112 | ``` 113 | cd ${DEEPSTREAM_SDK_PATH}/sources/apps/sample_apps/deepstream-test5 114 | make 115 | ``` 116 | In order to run deepstream-test5, you also need to modify your configuration file to point at the shared library. 117 | ``` 118 | cp configs/test5_config_file_src_infer.txt configs/test5_config_file_src_infer_aws.txt 119 | vim configs/test5_config_file_src_infer_aws.txt 120 | ``` 121 | You can then, modify msg-broker-proto-lib under your message broker sink (sink1), to point to: 122 | ${DEEPSTREAM_SDK_PATH}/sources/libs/aws_protocol_adaptor/device_client/libnvds_aws_proto.so. 123 | And also modify msg-broker-config under the same sink to point to: 124 | ${DEEPSTREAM_SDK_PATH}/sources/libs/aws_protocol_adaptor/device_client/cfg_aws.txt 125 | Next, you need to modify the topic to a topic name that you choose, and modify the first sink to a fake sink. Then, you can use the following command to run test5: 126 | ``` 127 | ./deepstream-test5-app -c configs/test5_config_file_src_infer_aws.txt 128 | ``` 129 | Now navigate to AWS IoT console, and on the menu bar on the left, click on test, type in test (or # to receive messages on all topics) in the subscription topic box, and click on *Subscribe to topic*, you should see MQTT messages start to show up on this console after app successfully runs. 130 | 131 | 132 | #### Processing IoT messages with AWS IoT rule 133 | Once you see messages coming into AWS IoT Core, there are a lot of options to further process them or store them on AWS cloud. One simple example would be to push these messages, using AWS IoT Rules, to a customized AWS Lambda function, which parses the messages and puts them in Amazon DynamoDB. You may find the following documents helpful in setting up this IoT rule to storage pipeline: 134 | * [Creating a Rule with a AWS Lambda Action](https://docs.aws.amazon.com/iot/latest/developerguide/iot-lambda-rule.html) 135 | * [Reading and Writing A Single Item in DynamoDB](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/dynamodb-example-table-read-write.html) 136 | * [Implementing a Serverless AWS IoT Backend with AWS Lambda and Amazon DynamoDB](https://aws.amazon.com/blogs/compute/implementing-a-serverless-aws-iot-backend-with-aws-lambda-and-amazon-dynamodb/) 137 | 138 | The following documents may further assist you building a more production-ready data pipeline: 139 | * [AWS IoT Analytics Console Quick Start Guide](https://docs.aws.amazon.com/iotanalytics/latest/userguide/quickstart.html) 140 | * [Integrating IoT data with your data lake with new AWS IoT Analytics features](https://aws.amazon.com/blogs/iot/integrating-iot-data-with-your-data-lake-with-new-aws-iot-analytics-features/) 141 | * [Real-Time IoT Device Monitoring with Kinesis Data Analytics](https://aws.amazon.com/solutions/real-time-iot-device-monitoring-with-kinesis/) 142 | * [Writing to Kinesis Data Firehose Using AWS IoT](https://docs.aws.amazon.com/firehose/latest/dev/writing-with-iot.html) 143 | 144 | ### Compatible with AWS IoT Greengrass 145 | 146 | This AWS DeepStream adaptor also supports connecting to AWS IoT Greengrass. You can modify in cfg_aws.txt to your Greengrass Endpoint/IP address. 147 | 148 | There are several options to find out Greengrass Endpoint/IP address. If you know the IP address of your Greengrass device or run “ifconfig” on your Greengrass device to find it out, you can directly put that as . AWS IoT Greengrass also provides a [Discovery API](https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-discover-api.html), enabling devices to retrieve information required to connect to an AWS IoT Greengrass core that is in the same Greengrass group as the device. 149 | 150 | For further information on enabling your device to connect to AWS IoT Greengrass, please follow module 4 in [AWS IoT Greengrass developer guide](https://docs.aws.amazon.com/greengrass/latest/developerguide/module4.html). 151 | 152 | ## Re-compiling Guide: 153 | You can always change this library to suit your own need. Please make the change the code and follow "Step 2: Manually build the shared library" section to make a new shared library for DeepStream. 154 | Some additional message properties like buffer size, can be set in `aws_iot_config.h`. If you want to change any of these settings, you will have to compile your own .so file. 155 | 156 | For we used QoS 0 for all the send functions. However, you can adjust to QoS 1 in message broker source code: `aws_nvmsgbroker.c`. 157 | 158 | To adjust the level of IOT logging, please go to Makefile and comment or un-comment the following lines. 159 | ``` 160 | LOG_FLAGS += -DENABLE_IOT_DEBUG 161 | LOG_FLAGS += -DENABLE_IOT_INFO 162 | LOG_FLAGS += -DENABLE_IOT_WARN 163 | LOG_FLAGS += -DENABLE_IOT_ERROR 164 | ``` 165 | 166 | ## License 167 | This project is licensed under the Apache-2.0 License. 168 | -------------------------------------------------------------------------------- /aws_protocol_adaptor/device_client/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-iot-core-integration-with-nvidia-deepstream/2f1b237fe0b59237e558273568467b79e155d9f8/aws_protocol_adaptor/device_client/.DS_Store -------------------------------------------------------------------------------- /aws_protocol_adaptor/device_client/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). 5 | # You may not use this file except in compliance with the License. 6 | # A copy of the License is located at 7 | # 8 | # http://aws.amazon.com/apache2.0 9 | # 10 | # or in the "license" file accompanying this file. This file is distributed 11 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | # express or implied. See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | ############################################################################### 15 | 16 | 17 | #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully. 18 | .prevent_execution: 19 | exit 0 20 | 21 | CC = gcc 22 | 23 | #remove @ for no make command prints 24 | DEBUG = @ 25 | 26 | APP_DIR = . 27 | APP_INCLUDE_DIRS += -I $(APP_DIR) 28 | APP_NAME = aws_nvmsgbroker_test 29 | APP_SRC_FILES = $(APP_NAME).c 30 | 31 | #IoT client directory 32 | IOT_CLIENT_DIR = ../aws-iot-sdk 33 | 34 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls 35 | PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common 36 | 37 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include 38 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn 39 | IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR) 40 | IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR) 41 | 42 | IOT_SRC_FILES += $(IOT_CLIENT_DIR)/src/aws_iot_mqtt_client.c 43 | IOT_SRC_FILES += $(IOT_CLIENT_DIR)/src/aws_iot_mqtt_client_common_internal.c 44 | IOT_SRC_FILES += $(IOT_CLIENT_DIR)/src/aws_iot_mqtt_client_connect.c 45 | IOT_SRC_FILES += $(IOT_CLIENT_DIR)/src/aws_iot_mqtt_client_publish.c 46 | IOT_SRC_FILES += $(IOT_CLIENT_DIR)/src/aws_iot_mqtt_client_subscribe.c 47 | IOT_SRC_FILES += $(IOT_CLIENT_DIR)/src/aws_iot_mqtt_client_unsubscribe.c 48 | IOT_SRC_FILES += $(IOT_CLIENT_DIR)/src/aws_iot_mqtt_client_yield.c 49 | 50 | 51 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c') 52 | IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c') 53 | IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c') 54 | 55 | #TLS - mbedtls 56 | MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS/mbedtls 57 | TLS_LIB_DIR = $(MBEDTLS_DIR)/library 58 | CRYPTO_LIB_DIR = $(MBEDTLS_DIR)/library 59 | TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include 60 | EXTERNAL_LIBS += -L$(TLS_LIB_DIR) 61 | LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR) 62 | LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(TLS_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a -lpthread 63 | 64 | # GLibs 65 | DP_SOURCE_DIR = ../../.. 66 | NVDS_VERSION:=4.0 67 | LIB_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/ 68 | PKGS:= gstreamer-1.0 gstreamer-video-1.0 x11 69 | GLIBS_INCLUDE+= -I $(DP_SOURCE_DIR)/includes 70 | GLIBS_INCLUDE+= `pkg-config --cflags $(PKGS)` 71 | LIBS+= `pkg-config --libs $(PKGS)` 72 | GLIB_SRC_FILES+= $(APP_DIR)/aws_config_parser.c 73 | GLIB_SRC_FILES+= $(APP_DIR)/aws_nvmsgbroker.c 74 | 75 | #Aggregate all include and src directories 76 | INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS) 77 | INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR) 78 | INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS) 79 | INCLUDE_ALL_DIRS += $(GLIBS_INCLUDE) 80 | 81 | SRC_FILES += $(IOT_SRC_FILES) 82 | SRC_FILES += $(GLIB_SRC_FILES) 83 | 84 | # Logging level control 85 | # LOG_FLAGS += -DENABLE_IOT_DEBUG 86 | # LOG_FLAGS += -DENABLE_IOT_INFO 87 | LOG_FLAGS += -DENABLE_IOT_WARN 88 | LOG_FLAGS += -DENABLE_IOT_ERROR 89 | 90 | COMPILER_FLAGS += $(LOG_FLAGS) 91 | #If the processor is big endian uncomment the compiler flag 92 | #COMPILER_FLAGS += -DREVERSED 93 | 94 | MBED_TLS_MAKE_CMD = $(MAKE) -C $(MBEDTLS_DIR) 95 | 96 | PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD) 97 | MAKE_OBJ_CMD = $(CC) -c -fPIC $(SRC_FILES) $(COMPILER_FLAGS) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS) $(LIBS) 98 | 99 | OBJS:=./*.o 100 | TLS_OBJS=$(TLS_LIB_DIR)/*.o 101 | MAKE_LIB_CMD = $(CC) -shared -fPIC -o libnvds_aws_proto.so $(OBJS) $(TLS_OBJS) ${LIBS} 102 | MAKE_TEST_CMD = $(CC) $(SRC_FILES) $(APP_SRC_FILES) $(COMPILER_FLAGS) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS) $(LIBS) -o $(APP_NAME) 103 | 104 | all: 105 | $(PRE_MAKE_CMD) 106 | $(DEBUG)$(MAKE_OBJ_CMD) 107 | $(DEBUG)$(MAKE_LIB_CMD) 108 | $(DEBUG)$(MAKE_TEST_CMD) 109 | $(POST_MAKE_CMD) 110 | 111 | clean: 112 | rm -f $(APP_DIR)/$(APP_NAME) 113 | rm -f *.o 114 | rm -f *.so 115 | $(MBED_TLS_MAKE_CMD) clean 116 | -------------------------------------------------------------------------------- /aws_protocol_adaptor/device_client/aws_config_parser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "aws_config_parser.h" 21 | #include "aws_iot_config.h" 22 | #include "aws_iot_mqtt_client_interface.h" 23 | 24 | #define CONFIG_MQTT_INFO "message-broker" 25 | #define CONFIG_MQTT_HOSTADD "HostAddress" 26 | #define CONFIG_MQTT_PORT "Port" 27 | #define CONFIG_MQTT_CLIENT_ID "ClientID" 28 | #define CONFIG_MQTT_THINGNAME "ThingName" 29 | #define CONFIG_MQTT_ROOTCALOCATION "RootCALocation" 30 | #define CONFIG_MQTT_CERTLOCATION "DeepstreamCertLocation" 31 | #define CONFIG_MQTT_PRIVKEYLOCATION "DeepstreamPrivateKeyLocation" 32 | #define CONFIG_MQTT_COMMAND_TIMEOUT "MQTTCommandTimeoutMS" 33 | #define CONFIG_MQTT_TLS_TIMEOUT "TLSHandshakeTimeoutMS" 34 | #define CONFIG_MQTT_SSL_HOST_NAME_VERIFY "SSLHostnameVerify" 35 | #define CHECK_ERROR(error) \ 36 | if (error) \ 37 | { \ 38 | g_print("ERROR in parsing: %s", error->message); \ 39 | goto done; \ 40 | } 41 | static gchar g_pHostURL[AWS_IOT_MAX_HOST_URL_LEN]; 42 | static gchar g_pClientID[AWS_IOT_MAX_CLIENT_ID_LEN]; 43 | static gchar g_pRootCALocation[AWS_IOT_MAX_ROOT_CA_PATH_LEN]; 44 | static gchar g_pDeviceCertLocation[AWS_IOT_MAX_CERT_PATH_LEN]; 45 | static gchar g_pDevicePrivateKeyLocation[AWS_IOT_MAX_PRIVATE_KEY_PATH_LEN]; 46 | 47 | GST_DEBUG_CATEGORY(APP_CFG_PARSER_CAT); 48 | 49 | gboolean 50 | parse_server(IoT_Client_Init_Params *iot_params, IoT_Client_Connect_Params *con_params, GKeyFile *key_file) 51 | { 52 | gboolean ret = FALSE; 53 | gchar **keys = NULL; 54 | gchar **key = NULL; 55 | GError *error = NULL; 56 | keys = g_key_file_get_keys(key_file, CONFIG_MQTT_INFO, NULL, &error); 57 | CHECK_ERROR(error); 58 | 59 | for (key = keys; *key; key++) 60 | { 61 | 62 | if (!g_strcmp0(*key, CONFIG_MQTT_HOSTADD)) 63 | { 64 | gchar *pHostURL_temp = g_key_file_get_string(key_file, CONFIG_MQTT_INFO, 65 | CONFIG_MQTT_HOSTADD, &error); 66 | iot_params->pHostURL = g_pHostURL; 67 | g_strlcpy(g_pHostURL, pHostURL_temp, AWS_IOT_MAX_HOST_URL_LEN); 68 | g_free(pHostURL_temp); 69 | CHECK_ERROR(error); 70 | } 71 | else if (!g_strcmp0(*key, CONFIG_MQTT_PORT)) 72 | { 73 | iot_params->port = 74 | g_key_file_get_integer(key_file, CONFIG_MQTT_INFO, 75 | CONFIG_MQTT_PORT, &error); 76 | CHECK_ERROR(error); 77 | } 78 | else if (!g_strcmp0(*key, CONFIG_MQTT_CLIENT_ID)) 79 | { 80 | gchar *pClientID_temp = g_key_file_get_string(key_file, CONFIG_MQTT_INFO, 81 | CONFIG_MQTT_CLIENT_ID, &error); 82 | con_params->pClientID = g_pClientID; 83 | g_strlcpy(g_pClientID, pClientID_temp, AWS_IOT_MAX_CLIENT_ID_LEN); 84 | g_free(pClientID_temp); 85 | CHECK_ERROR(error); 86 | } 87 | else if (!g_strcmp0(*key, CONFIG_MQTT_ROOTCALOCATION)) 88 | { 89 | gchar *pRootCALocation_temp = g_key_file_get_string(key_file, CONFIG_MQTT_INFO, 90 | CONFIG_MQTT_ROOTCALOCATION, &error); 91 | iot_params->pRootCALocation = g_pRootCALocation; 92 | g_strlcpy(g_pRootCALocation, pRootCALocation_temp, AWS_IOT_MAX_ROOT_CA_PATH_LEN); 93 | g_free(pRootCALocation_temp); 94 | CHECK_ERROR(error); 95 | } 96 | else if (!g_strcmp0(*key, CONFIG_MQTT_CERTLOCATION)) 97 | { 98 | gchar *pDeviceCertLocation_temp = g_key_file_get_string(key_file, CONFIG_MQTT_INFO, 99 | CONFIG_MQTT_CERTLOCATION, &error); 100 | iot_params->pDeviceCertLocation = g_pDeviceCertLocation; 101 | g_strlcpy(g_pDeviceCertLocation, pDeviceCertLocation_temp, AWS_IOT_MAX_CERT_PATH_LEN); 102 | g_free(pDeviceCertLocation_temp); 103 | CHECK_ERROR(error); 104 | } 105 | else if (!g_strcmp0(*key, CONFIG_MQTT_PRIVKEYLOCATION)) 106 | { 107 | gchar *pDevicePrivateKeyLocation_temp = g_key_file_get_string(key_file, CONFIG_MQTT_INFO, 108 | CONFIG_MQTT_PRIVKEYLOCATION, &error); 109 | iot_params->pDevicePrivateKeyLocation = g_pDevicePrivateKeyLocation; 110 | g_strlcpy(g_pDevicePrivateKeyLocation, pDevicePrivateKeyLocation_temp, AWS_IOT_MAX_PRIVATE_KEY_PATH_LEN); 111 | g_free(pDevicePrivateKeyLocation_temp); 112 | CHECK_ERROR(error); 113 | } 114 | else if (!g_strcmp0(*key, CONFIG_MQTT_COMMAND_TIMEOUT)) 115 | { 116 | iot_params->mqttCommandTimeout_ms = 117 | g_key_file_get_integer(key_file, CONFIG_MQTT_INFO, 118 | CONFIG_MQTT_COMMAND_TIMEOUT, &error); 119 | CHECK_ERROR(error); 120 | } 121 | else if (!g_strcmp0(*key, CONFIG_MQTT_TLS_TIMEOUT)) 122 | { 123 | iot_params->tlsHandshakeTimeout_ms = 124 | g_key_file_get_integer(key_file, CONFIG_MQTT_INFO, 125 | CONFIG_MQTT_TLS_TIMEOUT, &error); 126 | CHECK_ERROR(error); 127 | } 128 | else if (!g_strcmp0(*key, CONFIG_MQTT_SSL_HOST_NAME_VERIFY)) 129 | { 130 | gchar *isSSLHostnameVerify_str = g_key_file_get_string(key_file, CONFIG_MQTT_INFO, 131 | CONFIG_MQTT_SSL_HOST_NAME_VERIFY, &error); 132 | if (g_strcmp0(isSSLHostnameVerify_str, "false") && g_strcmp0(isSSLHostnameVerify_str, "true")) 133 | { 134 | NVGSTDS_WARN_MSG_V("SSLHostnameVerify has to be true or false. Current input is not valid, defaulting to true\n"); 135 | } 136 | iot_params->isSSLHostnameVerify = g_strcmp0(isSSLHostnameVerify_str, "false"); 137 | g_free(isSSLHostnameVerify_str); 138 | CHECK_ERROR(error); 139 | } 140 | else if (!g_strcmp0(*key, CONFIG_MQTT_THINGNAME)) 141 | { 142 | // No need for thing name in this implementation. 143 | continue; 144 | } 145 | else 146 | { 147 | NVGSTDS_WARN_MSG_V("Unknown key '%s' for group [%s]", *key, 148 | CONFIG_MQTT_INFO); 149 | } 150 | } 151 | 152 | ret = TRUE; 153 | done: 154 | if (error) 155 | { 156 | g_error_free(error); 157 | } 158 | if (keys) 159 | { 160 | g_strfreev(keys); 161 | } 162 | if (!ret) 163 | { 164 | NVGSTDS_ERR_MSG_V("%s failed", __func__); 165 | } 166 | return ret; 167 | } 168 | 169 | gboolean 170 | parse_config_file(IoT_Client_Init_Params *iot_params, IoT_Client_Connect_Params *con_params, gchar *cfg_file_path) 171 | { 172 | GKeyFile *cfg_file = g_key_file_new(); 173 | GError *error = NULL; 174 | gboolean ret = FALSE; 175 | gchar **groups = NULL; 176 | gchar **group; 177 | guint i, j; 178 | 179 | if (!APP_CFG_PARSER_CAT) 180 | { 181 | GST_DEBUG_CATEGORY_INIT(APP_CFG_PARSER_CAT, "NVDS_CFG_PARSER", 0, NULL); 182 | } 183 | if (!g_key_file_load_from_file(cfg_file, cfg_file_path, G_KEY_FILE_NONE, 184 | &error)) 185 | { 186 | GST_CAT_ERROR(APP_CFG_PARSER_CAT, "Failed to load uri file: %s", 187 | error->message); 188 | goto done; 189 | } 190 | groups = g_key_file_get_groups(cfg_file, NULL); 191 | for (group = groups; *group; group++) 192 | { 193 | gboolean parse_err = FALSE; 194 | GST_CAT_DEBUG(APP_CFG_PARSER_CAT, "Parsing group: %s", *group); 195 | if (!g_strcmp0(*group, CONFIG_MQTT_INFO)) 196 | { 197 | parse_err = !parse_server(iot_params, con_params, cfg_file); 198 | if (parse_err) 199 | { 200 | GST_CAT_ERROR(APP_CFG_PARSER_CAT, "%d", parse_err); 201 | goto done; 202 | } 203 | } 204 | } 205 | ret = true; 206 | done: 207 | if (cfg_file) 208 | { 209 | g_key_file_free(cfg_file); 210 | } 211 | 212 | if (groups) 213 | { 214 | g_strfreev(groups); 215 | } 216 | 217 | if (error) 218 | { 219 | g_error_free(error); 220 | } 221 | if (!ret) 222 | { 223 | NVGSTDS_ERR_MSG_V("%s failed", __func__); 224 | } 225 | return ret; 226 | } 227 | -------------------------------------------------------------------------------- /aws_protocol_adaptor/device_client/aws_config_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef __NVGSTDS_APP_H__ 17 | #define __NVGSTDS_APP_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" 21 | { 22 | #endif 23 | #include "aws_iot_mqtt_client_interface.h" 24 | #define NVGSTDS_ERR_MSG_V(msg, ...) \ 25 | g_print("** ERROR: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__) 26 | 27 | #define NVGSTDS_INFO_MSG_V(msg, ...) \ 28 | g_print("** INFO: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__) 29 | 30 | #define NVGSTDS_WARN_MSG_V(msg, ...) \ 31 | g_print("** WARN: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__) 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | #endif 36 | 37 | gboolean parse_config_file(IoT_Client_Init_Params *iot_params, IoT_Client_Connect_Params *con_params, gchar *cfg_file_path); 38 | -------------------------------------------------------------------------------- /aws_protocol_adaptor/device_client/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 22 | #define SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 23 | 24 | // MQTT PubSub 25 | #define AWS_IOT_MAX_HOST_URL_LEN 254 26 | #define AWS_IOT_MAX_CLIENT_ID_LEN 129 27 | #define AWS_IOT_MAX_ROOT_CA_PATH_LEN 200 28 | #define AWS_IOT_MAX_CERT_PATH_LEN 200 29 | #define AWS_IOT_MAX_PRIVATE_KEY_PATH_LEN 200 30 | 31 | #define AWS_IOT_MQTT_TX_BUF_LEN 4096 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 32 | #define AWS_IOT_MQTT_RX_BUF_LEN 512 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 33 | #define AWS_IOT_MQTT_TOPIC_BUF_LEN 257 ///< Maximum len of topics in AWS MQTT server + EOS 34 | #define AWS_IOT_CLIENT_YIELD_WAIT_TIME 10 ///< Maximum number of milliseconds to pass thread execution to the MQTT client. 35 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 36 | 37 | #define AWS_IOT_MAX_SEND_INTERVAL_SEC 120 ///< Have to yield every this amount of time before time-out disconnect 38 | 39 | // Thing Shadow specific configs 40 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER (AWS_IOT_MQTT_RX_BUF_LEN + 1) ///< Maximum size of the SHADOW buffer to store the received Shadow message, including terminating NULL byte. 41 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 42 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 43 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 44 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 45 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 46 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 47 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 48 | #define MAX_SIZE_OF_THING_NAME 20 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 49 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 50 | 51 | // Auto Reconnect specific config 52 | #define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm 53 | #define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect. 54 | 55 | #define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true 56 | 57 | #endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */ 58 | -------------------------------------------------------------------------------- /aws_protocol_adaptor/device_client/aws_nvmsgbroker.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "aws_iot_config.h" 25 | #include "aws_iot_log.h" 26 | #include "aws_iot_version.h" 27 | #include "aws_iot_mqtt_client_interface.h" 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "aws_config_parser.h" 34 | #include "nvds_msgapi.h" 35 | #include "aws_nvmsgbroker.h" 36 | 37 | NvDsMsgApiHandle (*nvds_msgapi_connect_ptr)(char *connection_str, nvds_msgapi_connect_cb_t connect_cb, char *config_path); 38 | NvDsMsgApiErrorType (*nvds_msgapi_send_ptr)(NvDsMsgApiHandle conn, char *topic, const uint8_t *payload, size_t nbuf); 39 | NvDsMsgApiErrorType (*nvds_msgapi_disconnect_ptr)(NvDsMsgApiHandle h_ptr); 40 | static GMutex thread_mutex; 41 | static GQueue *work_queue; 42 | static struct timespec last_send_time_stamp; // this is to make sure we send or yield frequent enough so we do not get disconnected. 43 | static nvds_msgapi_connect_cb_t disconnect_cb; // disconnect handler provided by connect thread 44 | 45 | /* ************************************************************************* */ 46 | // Connect function def 47 | /* ************************************************************************* */ 48 | 49 | static void disconnectCallbackHandler(AWS_IoT_Client *pClient, void *data) 50 | { 51 | IOT_WARN("MQTT Disconnect"); 52 | IoT_Error_t rc = FAILURE; 53 | if (NULL == pClient) 54 | { 55 | return; 56 | } 57 | IOT_UNUSED(data); 58 | if (aws_iot_is_autoreconnect_enabled(pClient)) 59 | { 60 | IOT_INFO("Auto Reconnect is enabled, Reconnecting attempt will start now"); 61 | } 62 | else 63 | { 64 | IOT_WARN("Auto Reconnect not enabled. Starting manual reconnect..."); 65 | rc = aws_iot_mqtt_attempt_reconnect(pClient); 66 | if (NETWORK_RECONNECTED == rc) 67 | { 68 | IOT_WARN("Manual Reconnect Successful"); 69 | } 70 | else 71 | { 72 | IOT_WARN("Manual Reconnect Failed - %d", rc); 73 | if (disconnect_cb != NULL) 74 | { 75 | disconnect_cb((NvDsMsgApiHandle)pClient, NVDS_MSGAPI_EVT_DISCONNECT); 76 | } 77 | } 78 | } 79 | } 80 | 81 | NvDsMsgApiHandle nvds_msgapi_connect(char *connection_str, nvds_msgapi_connect_cb_t connect_cb, char *config_path) 82 | { 83 | disconnect_cb = connect_cb; 84 | if (config_path == NULL) 85 | { 86 | IOT_ERROR("Essensial args missing for function nvds_msgapi_connect\n"); 87 | return NULL; 88 | } 89 | 90 | // param init 91 | g_mutex_init(&thread_mutex); 92 | work_queue = g_queue_new(); 93 | IoT_Error_t rc = FAILURE; 94 | AWS_IoT_Client *client = g_malloc(sizeof(AWS_IoT_Client)); 95 | IoT_Client_Init_Params mqttInitParams = iotClientInitParamsDefault; 96 | IoT_Client_Connect_Params connectParams = iotClientConnectParamsDefault; 97 | 98 | // try to connect to iot server 99 | IOT_INFO("\nAWS IoT SDK Version %d.%d.%d-%s\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG); 100 | parse_config_file(&mqttInitParams, &connectParams, (gchar *)config_path); 101 | mqttInitParams.enableAutoReconnect = false; // We enable this later below 102 | mqttInitParams.disconnectHandler = disconnectCallbackHandler; 103 | mqttInitParams.disconnectHandlerData = NULL; 104 | connectParams.keepAliveIntervalInSec = 600; 105 | connectParams.isCleanSession = true; 106 | connectParams.MQTTVersion = MQTT_3_1_1; 107 | connectParams.clientIDLen = (uint16_t)strlen(connectParams.pClientID); 108 | connectParams.isWillMsgPresent = false; 109 | 110 | IOT_DEBUG("rootCA %s", mqttInitParams.pRootCALocation); 111 | IOT_DEBUG("clientCRT %s", mqttInitParams.pDeviceCertLocation); 112 | IOT_DEBUG("clientKey %s", mqttInitParams.pDevicePrivateKeyLocation); 113 | 114 | rc = aws_iot_mqtt_init(client, &mqttInitParams); 115 | if (SUCCESS != rc) 116 | { 117 | IOT_ERROR("aws_iot_mqtt_init returned error : %d ", rc); 118 | return NULL; 119 | } 120 | 121 | IOT_INFO("Connecting..."); 122 | rc = aws_iot_mqtt_connect(client, &connectParams); 123 | if (SUCCESS != rc) 124 | { 125 | IOT_ERROR("Error(%d) connecting to %s:%d", rc, mqttInitParams.pHostURL, mqttInitParams.port); 126 | if (disconnect_cb != NULL) 127 | connect_cb((NvDsMsgApiHandle)client, NVDS_MSGAPI_EVT_DISCONNECT); 128 | return NULL; 129 | } 130 | disconnect_cb = connect_cb; 131 | clock_gettime(CLOCK_REALTIME, &last_send_time_stamp); 132 | // auto-reconnect? how? 133 | IOT_INFO("Successfully connected"); 134 | return (NvDsMsgApiHandle)client; 135 | } 136 | 137 | /* ************************************************************************* */ 138 | // Disconnect function def 139 | /* ************************************************************************* */ 140 | 141 | NvDsMsgApiErrorType nvds_msgapi_disconnect(NvDsMsgApiHandle h_ptr) 142 | { 143 | if ((h_ptr == NULL)) 144 | { 145 | IOT_ERROR("Essensial args missing for function nvds_msgapi_disconnect\n"); 146 | return NVDS_MSGAPI_ERR; 147 | } 148 | IoT_Error_t rc = FAILURE; 149 | AWS_IoT_Client *client = (AWS_IoT_Client *)h_ptr; 150 | rc = aws_iot_mqtt_disconnect(client); 151 | if (SUCCESS != rc) 152 | { 153 | IOT_ERROR("Unable to disconnect, error: %d\n", rc); 154 | return NVDS_MSGAPI_ERR; 155 | } 156 | IOT_INFO("Successfully disconnected"); 157 | g_free(client); 158 | return NVDS_MSGAPI_OK; 159 | } 160 | 161 | /* ************************************************************************* */ 162 | // Send function def 163 | /* ************************************************************************* */ 164 | 165 | static IoT_Error_t _mqtt_msg_send(AWS_IoT_Client *client, char *topic, const uint8_t *payload, size_t nbuf) 166 | { 167 | IoT_Error_t rc = FAILURE; 168 | IoT_Publish_Message_Params paramsQOS0; 169 | paramsQOS0.qos = QOS0; 170 | paramsQOS0.payload = (void *)payload; 171 | paramsQOS0.isRetained = 0; 172 | paramsQOS0.payloadLen = nbuf; 173 | g_mutex_lock(&thread_mutex); 174 | rc = aws_iot_mqtt_publish(client, topic, strlen(topic), ¶msQOS0); 175 | g_mutex_unlock(&thread_mutex); 176 | return rc; 177 | } 178 | 179 | NvDsMsgApiErrorType nvds_msgapi_send(NvDsMsgApiHandle conn, char *topic, const uint8_t *payload, size_t nbuf) 180 | { 181 | if ((conn == NULL) || (topic == NULL) || (payload == NULL) || (nbuf == 0)) 182 | { 183 | IOT_ERROR("Essensial args missing for function nvds_msgapi_send\n"); 184 | return NVDS_MSGAPI_ERR; 185 | } 186 | AWS_IoT_Client *client = (AWS_IoT_Client *)conn; 187 | IoT_Error_t rc = _mqtt_msg_send(client, topic, payload, nbuf); 188 | if (SUCCESS != rc) 189 | { 190 | IOT_ERROR("Unable to publish, error: %d\n", rc); 191 | return NVDS_MSGAPI_ERR; 192 | } 193 | IOT_INFO("Successfully sent sync message"); 194 | return NVDS_MSGAPI_OK; 195 | } 196 | 197 | /* ************************************************************************* */ 198 | // Async: Send function def 199 | // Therefore, we are using a mutex to guard aws_iot_mqtt_publish in nvds_msgapi_send_async. 200 | // Once this beta version below becomes official, we will release the one without mutex. 201 | /* ************************************************************************* */ 202 | 203 | typedef struct Works 204 | { 205 | NvDsMsgApiHandle h_ptr; 206 | size_t payload_size; 207 | nvds_msgapi_send_cb_t call_back_handler; 208 | void *user_ptr; 209 | char topic[AWS_IOT_MQTT_TOPIC_BUF_LEN]; 210 | char payload[AWS_IOT_MQTT_TX_BUF_LEN]; 211 | } Work; 212 | 213 | // flag connection status 214 | // add comment to keep connection always on otherwise: NVDS_MSGAPI_ERR 215 | // not demonstrating subscriptions 216 | NvDsMsgApiErrorType nvds_msgapi_send_async(NvDsMsgApiHandle h_ptr, char *topic, const uint8_t *payload, size_t nbuf, nvds_msgapi_send_cb_t send_callback, void *user_ptr) 217 | { 218 | if ((h_ptr == NULL) || (topic == NULL) || (payload == NULL) || (nbuf == 0)) 219 | { 220 | IOT_ERROR("Essensial args missing for function nvds_msgapi_send: %d, %d, %d, %d\n", (h_ptr == NULL), (topic == NULL), (payload == NULL), (nbuf == 0)); 221 | return NVDS_MSGAPI_ERR; 222 | } 223 | Work *work_node = g_malloc(sizeof(Work)); 224 | if (work_node == NULL) 225 | { 226 | IOT_ERROR("Malloc failed."); 227 | return NVDS_MSGAPI_ERR; 228 | } 229 | work_node->h_ptr = h_ptr; 230 | work_node->payload_size = nbuf; 231 | work_node->call_back_handler = send_callback; 232 | work_node->user_ptr = user_ptr; 233 | if ((strlen(topic) > (AWS_IOT_MQTT_TOPIC_BUF_LEN - 1)) || (nbuf > AWS_IOT_MQTT_TX_BUF_LEN)) 234 | { 235 | IOT_ERROR("Topic or payload buff size too small."); 236 | return NVDS_MSGAPI_ERR; 237 | } 238 | memset(work_node->topic, 0, sizeof(work_node->topic)); 239 | memset(work_node->payload, 0, sizeof(work_node->payload)); 240 | memcpy(work_node->topic, topic, strlen(topic)); 241 | memcpy(work_node->payload, payload, nbuf); 242 | g_queue_push_tail(work_queue, work_node); 243 | return NVDS_MSGAPI_OK; 244 | } 245 | 246 | /* ************************************************************************* */ 247 | // Do Work function def 248 | /* ************************************************************************* */ 249 | 250 | void nvds_msgapi_do_work(NvDsMsgApiHandle h_ptr) 251 | { 252 | // decide whether to yield in this run 253 | IoT_Error_t rc = FAILURE; 254 | bool need_to_yield = false; 255 | struct timespec current_time_stamp; 256 | clock_gettime(CLOCK_REALTIME, ¤t_time_stamp); 257 | uint time_diff = current_time_stamp.tv_sec - last_send_time_stamp.tv_sec; 258 | if (time_diff > AWS_IOT_MAX_SEND_INTERVAL_SEC) 259 | { 260 | need_to_yield = true; 261 | } 262 | IOT_DEBUG("Current queue length: %d\n", g_queue_get_length(work_queue)); 263 | if (g_queue_is_empty(work_queue)) 264 | { 265 | IOT_INFO("Work queue empty."); 266 | if (need_to_yield) 267 | { 268 | IOT_INFO("IoT yielding in order to not be disconnected."); 269 | g_mutex_lock(&thread_mutex); 270 | rc = aws_iot_mqtt_yield((AWS_IoT_Client *)h_ptr, AWS_IOT_CLIENT_YIELD_WAIT_TIME); 271 | if (rc != SUCCESS && disconnect_cb != NULL) 272 | { 273 | disconnect_cb(h_ptr, NVDS_MSGAPI_EVT_DISCONNECT); 274 | } 275 | last_send_time_stamp = current_time_stamp; 276 | g_mutex_unlock(&thread_mutex); 277 | } 278 | return; 279 | } 280 | while (! g_queue_is_empty(work_queue)){ 281 | Work *work_node = (Work *)g_queue_pop_head(work_queue); 282 | AWS_IoT_Client *client = (AWS_IoT_Client *)work_node->h_ptr; 283 | rc = _mqtt_msg_send(client, work_node->topic, work_node->payload, work_node->payload_size); 284 | if (SUCCESS != rc) 285 | { 286 | IOT_ERROR("Unable to publish, error: %d\n", rc); 287 | if (work_node->call_back_handler != NULL) 288 | { 289 | work_node->call_back_handler(work_node->user_ptr, NVDS_MSGAPI_ERR); 290 | } 291 | g_free(work_node); 292 | return; 293 | } 294 | if (work_node->call_back_handler != NULL){ 295 | IOT_INFO("Pointer callback."); 296 | work_node->call_back_handler(work_node->user_ptr, NVDS_MSGAPI_OK); 297 | } 298 | g_free(work_node); 299 | } 300 | last_send_time_stamp = current_time_stamp; 301 | return; 302 | } 303 | -------------------------------------------------------------------------------- /aws_protocol_adaptor/device_client/aws_nvmsgbroker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef __NVGSTDS_APP_H__ 17 | #define __NVGSTDS_APP_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" 21 | { 22 | #endif 23 | // #include "deepstream_common.h" 24 | // #include "aws_iot_mqtt_client_interface.h" 25 | 26 | #define NVGSTDS_ERR_MSG_V(msg, ...) \ 27 | g_print("** ERROR: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__) 28 | 29 | #define NVGSTDS_INFO_MSG_V(msg, ...) \ 30 | g_print("** INFO: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__) 31 | 32 | #define NVGSTDS_WARN_MSG_V(msg, ...) \ 33 | g_print("** WARN: <%s:%d>: " msg "\n", __func__, __LINE__, ##__VA_ARGS__) 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | NvDsMsgApiHandle nvds_msgapi_connect(char *connection_str, nvds_msgapi_connect_cb_t connect_cb, char *config_path); 41 | NvDsMsgApiErrorType nvds_msgapi_disconnect(NvDsMsgApiHandle h_ptr); 42 | NvDsMsgApiErrorType nvds_msgapi_send(NvDsMsgApiHandle conn, char *topic, const uint8_t *payload, size_t nbuf); 43 | NvDsMsgApiErrorType nvds_msgapi_send_async(NvDsMsgApiHandle h_ptr, char *topic, const uint8_t *payload, size_t nbuf, nvds_msgapi_send_cb_t send_callback, void *user_ptr); 44 | void nvds_msgapi_do_work(NvDsMsgApiHandle h_ptr); 45 | -------------------------------------------------------------------------------- /aws_protocol_adaptor/device_client/aws_nvmsgbroker_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "aws_iot_config.h" 24 | #include "aws_iot_log.h" 25 | #include "aws_iot_version.h" 26 | #include "aws_iot_mqtt_client_interface.h" 27 | 28 | #include 29 | #include "aws_config_parser.h" 30 | #include "nvds_msgapi.h" 31 | #include 32 | #include 33 | #include 34 | 35 | extern const IoT_Client_Init_Params iotClientInitParamsDefault; 36 | extern const IoT_Client_Connect_Params iotClientConnectParamsDefault; 37 | 38 | NvDsMsgApiHandle (*nvds_msgapi_connect_ptr)(char *connection_str, nvds_msgapi_connect_cb_t connect_cb, char *config_path); 39 | NvDsMsgApiErrorType (*nvds_msgapi_send_ptr)(NvDsMsgApiHandle conn, char *topic, const uint8_t *payload, size_t nbuf); 40 | NvDsMsgApiErrorType (*nvds_msgapi_disconnect_ptr)(NvDsMsgApiHandle h_ptr); 41 | NvDsMsgApiErrorType (*nvds_msgapi_send_async_ptr)(NvDsMsgApiHandle conn, char *topic, const uint8_t *payload, size_t nbuf, nvds_msgapi_send_cb_t send_callback, void *user_ptr); 42 | NvDsMsgApiErrorType (*nvds_msgapi_do_work_ptr)(NvDsMsgApiHandle conn); 43 | 44 | const char *AWS_PROTO_SO = "./libnvds_aws_proto.so"; 45 | /* ************************************************************************* */ 46 | // Connect function def 47 | /* ************************************************************************* */ 48 | 49 | void connect_cb(NvDsMsgApiHandle h_ptr, NvDsMsgApiEventType evt) 50 | { 51 | AWS_IoT_Client *client = (AWS_IoT_Client *)h_ptr; 52 | if (evt == NVDS_MSGAPI_EVT_DISCONNECT) 53 | { 54 | g_print("In sample prog: connect failed. \n"); 55 | } 56 | else 57 | g_print("In sample prog: connect success \n"); 58 | } 59 | 60 | /* ************************************************************************* */ 61 | // Async: Send function def 62 | /* ************************************************************************* */ 63 | 64 | struct send_info_t 65 | { 66 | pid_t tid; 67 | int num; 68 | }; 69 | 70 | void send_callback(void *user_ptr, NvDsMsgApiErrorType completion_flag) 71 | { 72 | struct send_info_t *info = (struct send_info_t *)user_ptr; 73 | if (completion_flag == NVDS_MSGAPI_OK) 74 | g_print("Thread [%d] , Message num %d : send success\n", info->tid, info->num); 75 | else 76 | g_print("Thread [%d] , Message num %d : send failed\n", info->tid, info->num); 77 | g_free(info); 78 | } 79 | 80 | void *func(void *ptr) 81 | { 82 | NvDsMsgApiHandle conn = (NvDsMsgApiHandle)ptr; 83 | char cPayload_send_async[100] = {0}; 84 | sprintf(cPayload_send_async, "%s", "hello from SDK nvds_msgapi_send_async"); 85 | pid_t myid = syscall(SYS_gettid); 86 | char cTopic_send_async[20] = {0}; 87 | sprintf(cTopic_send_async, "%s", "sdkTest/sub"); 88 | for (int i = 0; i < 10; i++) 89 | { 90 | struct send_info_t *myinfo = g_malloc(sizeof(struct send_info_t)); 91 | myinfo->tid = myid; 92 | myinfo->num = i; 93 | nvds_msgapi_send_async_ptr(conn, cTopic_send_async, (const uint8_t *)cPayload_send_async, strlen(cPayload_send_async), send_callback, &myinfo); 94 | sleep(0.5); 95 | } 96 | } 97 | 98 | int main(int argc, char **argv) 99 | { 100 | void *so_handle; 101 | so_handle = dlopen(AWS_PROTO_SO, RTLD_NOW); 102 | if (!so_handle) 103 | { 104 | g_print("Failed to load lib, exiting: %s\n", dlerror()); 105 | return 0; 106 | } 107 | *(void **)(&nvds_msgapi_connect_ptr) = dlsym(so_handle, "nvds_msgapi_connect"); 108 | *(void **)(&nvds_msgapi_send_ptr) = dlsym(so_handle, "nvds_msgapi_send"); 109 | *(void **)(&nvds_msgapi_disconnect_ptr) = dlsym(so_handle, "nvds_msgapi_disconnect"); 110 | *(void **)(&nvds_msgapi_send_async_ptr) = dlsym(so_handle, "nvds_msgapi_send_async"); 111 | *(void **)(&nvds_msgapi_do_work_ptr) = dlsym(so_handle, "nvds_msgapi_do_work"); 112 | gchar config[20] = "cfg_aws.txt"; 113 | 114 | /* ************************************************************************* */ 115 | // Connect call 116 | /* ************************************************************************* */ 117 | NvDsMsgApiHandle conn = nvds_msgapi_connect_ptr(NULL, connect_cb, config); 118 | 119 | /* ************************************************************************* */ 120 | // Send call 121 | /* ************************************************************************* */ 122 | char cPayload_send[100]; 123 | sprintf(cPayload_send, "%s", "hello from SDK nvds_msgapi_send"); 124 | char cTopic_send[20]; 125 | sprintf(cTopic_send, "%s", "sdkTest/sub"); 126 | nvds_msgapi_send_ptr(conn, cTopic_send, cPayload_send, strlen(cPayload_send)); 127 | /* ************************************************************************* */ 128 | // Async: Send call (current AWS IoT client does not support multi-thread. 129 | /* ************************************************************************* */ 130 | 131 | int NUM_THREADS = 2; 132 | pthread_t tid[NUM_THREADS]; 133 | for (int i = 0; i < NUM_THREADS; i++) 134 | pthread_create(&tid[i], NULL, &func, (void *)conn); 135 | for (int i = 0; i < NUM_THREADS; i++) 136 | pthread_join(tid[i], NULL); 137 | /* ************************************************************************* */ 138 | // Do work call 139 | /* ************************************************************************* */ 140 | for (int i = 0; i < NUM_THREADS * 15; i++) 141 | { 142 | g_print("doing work.\n"); 143 | nvds_msgapi_do_work_ptr(conn); 144 | } 145 | /* ************************************************************************* */ 146 | // Disconnect call 147 | /* ************************************************************************* */ 148 | g_print("Disconnecting.\n"); 149 | nvds_msgapi_disconnect_ptr(conn); 150 | 151 | return 0; 152 | } 153 | -------------------------------------------------------------------------------- /aws_protocol_adaptor/device_client/cfg_aws.txt: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). 5 | # You may not use this file except in compliance with the License. 6 | # A copy of the License is located at 7 | # 8 | # http://aws.amazon.com/apache2.0 9 | # 10 | # or in the "license" file accompanying this file. This file is distributed 11 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | # express or implied. See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | ############################################################################### 15 | 16 | [message-broker] 17 | HostAddress = 18 | Port = 443 19 | ThingName = deepstrea-app-to-cloud 20 | ClientID = deepstrea-app-to-cloud 21 | RootCALocation = /sources/libs/aws_protocol_adaptor/device_client/certs/root.ca.pem 22 | DeepstreamCertLocation = /sources/libs/aws_protocol_adaptor/device_client/certs/certificatePem.cert.pem 23 | DeepstreamPrivateKeyLocation = /sources/libs/aws_protocol_adaptor/device_client/certs/privateKey.private.key 24 | MQTTCommandTimeoutMS = 20000 25 | TLSHandshakeTimeoutMS = 20000 26 | SSLHostnameVerify = false 27 | -------------------------------------------------------------------------------- /aws_protocol_adaptor/device_client/libnvds_aws_proto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-iot-core-integration-with-nvidia-deepstream/2f1b237fe0b59237e558273568467b79e155d9f8/aws_protocol_adaptor/device_client/libnvds_aws_proto.so -------------------------------------------------------------------------------- /success_screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/aws-iot-core-integration-with-nvidia-deepstream/2f1b237fe0b59237e558273568467b79e155d9f8/success_screen.png --------------------------------------------------------------------------------