• Home
  • Resources
    • User Guides
    • Concepts Articles
    • API References
    • Client Libraries & SDKs
    • Product Updates
  • FAQs
    • General
    • IoTConnect
      • Device Rules
      • Devices
      • Settings
      • Device Commands
      • Device Templates
      • Device Firmware
      • Device Onboarding
    • Security
  • Contact Us
  • Home
  • Resources
    • User Guides
    • Concepts Articles
    • API References
    • Client Libraries & SDKs
    • Product Updates
  • FAQs
    • General
    • IoTConnect
      • Device Rules
      • Devices
      • Settings
      • Device Commands
      • Device Templates
      • Device Firmware
      • Device Onboarding
    • Security
  • Contact Us

Client Libraries & SDKs

home/Documentation/Client Libraries & SDKs
  • Device SDK Reference
    • Overview
    • Device Authentication Options
    • Data Flow
    • Public Methods
      • Device Connection
      • Send Telemetry
      • Get Attributes
      • Send acknowledgment
      • Update Twin
    • SDKs (Message version 1.0)
      • DOT NET (C#)
      • Node.js
      • Java
      • Python
      • iOS
      • Android
      • Embedded
      • C language
      • Build Your Own SDK
      • Node-RED
        • IoTConnect Node-red 1.0.9
        • IoTConnect Node-red 1.0.8
      • Node-RED Subflow
        • Single Device
        • Multiple Device
    • SDKs (Message version 2.1)
      • Python
      • DOT NET (C#)
      • C language
        • IoTConnect Generic C SDK
          • Linux Build Instructions
          • Windows Build Instructions
      • Python 1.1
    • Code Samples
      • Node.js
        • TPM 3.1
        • Standard SDK 3.0
        • Standard
        • TPM
        • Standard SDK 3.0.1
        • Standard 2.0
      • Java
        • Standard
        • Standard 2.0
        • Standard 3.0
      • Python
        • Standard 2.0
        • TPM 2.1
        • Standard 3.0.1
        • Standard
        • TPM
          • TPM 3.0.1
        • TPM 3.0
        • Standard 3.0.2
        • Standard 3.0.3
        • Standard 3.0.4
        • Python SDK
      • iOS
        • ios1.0.1
      • C Language
        • nRF9160 DK
        • STM32L4
        • ESP32
        • Standard 3.0
        • Standard 2.0
        • Standard 3.1
      • Android
        • Standard 3.0
        • Standard 2.0.6
        • Standard 2.0.0
      • DOT NET (C#)
        • Standard
        • Standard 2.0
        • Standard 3.0
    • Device Message 1.0
      • D2C (Device to Cloud)
        • IoTConnect SDK
        • Custom SDK
      • C2D (Cloud to Device)
        • IoTConnect SDK
        • Custom SDK
      • Troubleshooting & Response codes
      • Know Your Essentials
    • Device Message 2.1
    • AWS Device Message 2.1
    • SDK Deep-diving
Download PDF

Standard 2.0

Card Image

Dotnet C# SDK

Version 2.0.0

Release On 01/20

Sample Code lettest version of Dotnet Core SDK

# Date Name Download
1 03/20/2020 Symmetric Key Sample – Dotnet Core Download
2 03/20/2020 Symmetric Key Gateway Sample – Dotnet Core Download
3 03/20/2020 Self Sign Sample – Dotnet Core Download
4 03/20/2020 Self Sign Gateway Sample – Dotnet Core Download
5 03/20/2020 CA Sign Sample – Dotnet Core Download
6 03/20/2020 CA Sign Gateway Sample – Dotnet Core Download

Sample Code lettest version of Dotnet Standard SDK

# Date Name Download
1 03/20/2020 Symmetric Key Sample – Dotnet Standard Download
2 03/20/2020 Symmetric Key Gateway Sample – Dotnet Standard Download
3 03/20/2020 Self Sign Sample – Dotnet Standard Download
4 03/20/2020 Self Sign Gateway Sample – Dotnet Standard Download
5 03/20/2020 CA Sign Sample – Dotnet Standard Download
6 03/20/2020 CA Sign Gateway Sample – Dotnet Standard Download

How to build Dotnet sample code?

SDK zip file contains two Nuget packages(.Net Core 2.0 and .Net Standard Nuget package.)

Prerequisite tools:

  1. NET Core 2.0/.NET Framework

Installation:

  1. Open Visual Studio 2017, Create new .net core Console App
  2. Create new folder called Nuget and place IOTConnect SDK Nuget package
  3. Open Nuget Package Manager of Console App and click on Settings for Package source
  4. Add new Package source, name it as LocalPackage and in source give path of Nuget folder created in step #2

Public Methods and Implementations

In Program.cs add the namespace of IOTConnect SDK

 using IOTConnectSDK;

Create an object of SDKClient

string cpId = "", uniqueId = "";
SDKClient client = new SDKClient(cpId, uniqueId, FirmwareDelegate, TwinUpdateCallBack);

Callback function to receive Cloud to Device message (C2D)

public static Task FirmwareDelegate(string message)
{
    Console.WriteLine("Command Received.");
    Console.WriteLine(message);
    return Task.CompletedTask;
}

Callback function to receive twin update

public static Task TwinUpdateCallBack(Dictionary<string, object> twins)
{
    Console.WriteLine("Twin Update received.");
    foreach (var twin in twins)
    {
        Console.WriteLine($"{twin.Key}:{twin.Value}");
    }
    return Task.CompletedTask;
}

Sample data

[{
  "cpId": "",     //CPID of company
  "time": "",     //Datetime Fromat: YYYY-MM-DDTHH:MM:SS.SSSSSSSS"                
  "uniqueId": "", //Device ID
      "d": [{         //Telemetry data
             "voltage": 143.0,
             "current": 4.0,
             "frequency": 6.10,
             }]
}]

To send the data from Device To Cloud(D2C)

client.SendData(File.ReadAllText(@"devicedata.json"));

Certificate Configuration
In order to set certificate and password you have to use bellow static properties:

SDKClient.SSL.Certificate = certiPath;
SDKClient.SSL.Password = certiPass;
  • SDKClient.SSL.Certificate : x509 certificate file path
  • SDKClient.SSL.Password : Certificate password

To update the Twin Property

client.UpdateTwin("twin-property","new value");

To send the acknowledgment to cloud for Device command and Firmware OTA command

var commandData = JsonConvert.DeserializeObject(message);

DeviceAckModel ackDetails = new DeviceAckModel()
{
	AckId = commandData.AcknowledgeId,
	ChildId = ""
};

//IOTConnect.Net SDK version < 2.0
bool isOta = (commandData != null && !string.IsNullOrWhiteSpace(commandData.Command) && 
             commandData.Command.StartsWith(" ", StringComparison.CurrentCultureIgnoreCase));

//IOTConnect.Net SDK version >= 2.0
isOta = commandData.CommandType.Equals("0x02", StringComparison.CurrentCultureIgnoreCase);

if (isOta)
{
	//TODO : download and save ota file from url
	ackDetails.Msg = "OTA updated successfully.";
	ackDetails.Status = 7;
}
else
{
	ackDetails.Msg = "Device command received successfully.";
	ackDetails.Status = 6;
}

var dataOta = JsonConvert.SerializeObject(ackDetails);

//NOTE: SendAck method have different arguments as per the SDK version. Choose accordingly.
//IOTConnect.Net SDK version < 2.0
client.SendAck(dataOta, isOta ? 11 : 5);

//IOTConnect.Net SDK version >= 2.0
client.SendAck(dataOta, "2020-02-14T12:19:33.7769262Z", isOta ? 11 : 5);

             
dataOta:- {
          "AcknowledgeId" : , #you will received at callback() method   
          "Status" : 7, #its status 6= for commands and 7 for firmware(OTA)  
          "Msg" : "", #Msg(optional) its used for send your custom message  
          "childId" : ""  # childId(optional) its used when you have gateway template   
         }
			
current_time:- '2018-05-24T10:06:17.857Z', //Date format should be as defined
		
mt:- 11 # for firmware update..
     5  # for command ack.

Powered by Softweb – An Avnet Company.

Copyright ©2022 Avnet, Inc. All rights reserved.

Human Rights Privacy Terms of Use