################################################################################
# Copyright (c) 2019, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA Corporation is strictly prohibited.
#
################################################################################

This project implements protocol adaptor for Azure (device2cloud messaging)
The adaptor implements the nv_dsmi API for client applications to interface with it.

Create azure IOT hub : https://docs.microsoft.com/en-us/azure/iot-hub/tutorial-connectivity
NOTE: Once you have your IOT hub created, please make sure you fill in the connection details in cfg_azure.txt

Dependencies:
------------
 sudo apt-get update
 sudo apt-get install -y libcurl4-openssl-dev libssl-dev uuid-dev libglib2.0 libglib2.0-dev

#If your host machine is x86 and using ubuntu 18.04, additionally install the below
 sudo apt-get install -y libcurl3


Azure cfg:
----------
You can add Azure connection and message details in the cfg file.
Uncomment the fields you may want to edit and add proper values

[message-broker]
#connection_str = HostName=<my-hub>.azure-devices.net;DeviceId=<device_id>;SharedAccessKey=<my-policy-key>
#shared_access_key = <my-policy-key>
#custom_msg_properties =  <key>=<value>;

NOTE: DO NOT delete the line [message-broker] inside the cfg file. Its the section identifier used for parsing


Azure device connection string:
-------------------------------
Make sure to provide the connection_str within cfg_azure.txt
connection_str = HostName=<my-hub>.azure-devices.net;DeviceId=<device_id>;SharedAccessKey=<my-policy-key>

OR

pass in part of the required connection string in the call to nvds_msgapi_connect_ptr:
 conn_handle = msgapi_connect_ptr((char *)"url;port;device-id",(nvds_msgapi_connect_cb_t) sample_msgapi_connect_cb, (char *)CFG_FILE);
AND provide the shared_access_key within cfg_azure.txt
shared_access_key = <my-policy-key>


Set message properties:
-----------------------
Option to provide custom MQTT / IOT-hub client message properties of format key=value;
Multiple such key value message pairs can be provided
Note: Max length of the custom_msg_property string is limited to 512 bytes
ex1: key1=value1;
ex2: key1=value1;key2=value2;key3=value3;

Setup and enable logging:
-------------------------
Before running the sample applications, enable logs by running the logger setup script:
For x86,
 chmod u+x ~/deepstream_x86_public/sources/tools/nvds_logger/setup_nvds_logger.sh
 sudo ~/deepstream_x86_public/sources/tools/nvds_logger/setup_nvds_logger.sh
On Jetson,
 chmod u+x ~/deepstream_sdk_on_jetson/sources/tools/nvds_logger/setup_nvds_logger.sh
 sudo ~/deepstream_sdk_on_jetson/sources/tools/nvds_logger/setup_nvds_logger.sh

When the test app starts, log messages from the message adaptors(azure) can be seen at /tmp/nvds/ds.log

To run test program:
--------------------
 make -f Makefile.test
 ./test_azure_proto_async <path_to_libnvds_azure_proto.so>
 ./test_azure_proto_sync <path_to_libnvds_azure_proto.so>

 NOTE:
 libnvds_azure_proto.so can be found at /opt/nvidia/deepstream/deepstream-<version>/lib/libnvds_azure_proto.so
