page_type: sample languages:
This sample shows you how to interact with Azure IoT Central APIs in C#. If you have any questions or feature requests, please create new issue with detailed infomation.
File/folder | Description |
---|---|
SDK |
Auto-generate C# REST client from the swagger |
samples |
Each sample app that interats with single IoT Central API |
.gitignore |
Define what to ignore at commit time. |
README.md |
This README file. |
LICENSE |
The license for the sample. |
Examples
folderMake sure Azure CLI has been installed on your dev machine.
In console window, run below command to login:
az login
az extension add --name azure-iot
Setup application and resource group name
APP_NAME="fleet-manager-$RANDOM"
RESOURCE_GROUP="rg-fleet-manager"
echo "Your resource group is: $RESOURCE_GROUP"
echo "Your application name is: $APP_NAME"
Create the resource group
az group create --location centralus --resource-group $RESOURCE_GROUP
Create Azure IoT Central Application from CLI
az iot central app create \
--resource-group $RESOURCE_GROUP \
--name $APP_NAME --sku ST2 --location centralus \
--subdomain $APP_NAME --template iotc-pnp-preview \
--display-name 'Fleet management'
Register Azure AAD Application
aadAppId=$(az ad app create --display-name fleetapp --required-resource-accesses @manifest.json --is-fallback-public-client true --public-client-redirect-uris http://localhost --sign-in-audience AzureADmyOrg --output tsv --query "appId")
Grant Admin Consent
az ad app permission admin-consent --id $aadAppId
Get your tenant ID
tenantId=$(az account show --output tsv --query "tenantId")
Show the required variables from following command
echo $tenantId $aadAppId $APP_NAME
Replace from Examples/Constants.cs
with the results returned from above command line
public const string ClientApplicationId = "{aadAppId}"
public const string TenantId = "{tenantId}";
public const string AppName = "{APP_NAME}";
samples\Examples
folderUncomments line by line from following code in Program.cs
// UserOrgExample.Run(centralClient, options);
// DeviceTemplateExample.Run(centralClient, options);
// DeviceExample.Run(centralClient, options);
// FileUploadExample.Run(centralClient, options);
// DeviceGroupExample.Run(centralClient, options);
// EnrollmentGroupExample.Run(centralClient, options);
In the terminal, type and run dotnet run
.
Clone the official specs using
git clone https://github.com/Azure/azure-rest-api-specs.git
Install latest autorest
npm install -g autorest@latest
Enter Azure IoT Central Rest API spec folder
cd azure-rest-api-specs/specification/iotcentral/data-plane
Using autorest
generate SDK
autorest readme.md --csharp --tag=package-2022-10-31-preview --csharp-sdks-folder="~/sdk/csharp" --generation1-convenience-client --namespace="Microsoft.Azure.IoTCentral.Preview" --public-clients=true
NOTE
--tag
can be changed to any version that central supported, check the readme.md file under data-plane
folder.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.