Exemple #1
0
        public async Task <bool> GetDeviceTwinData()
        {
            DeviceTwinAndMethod deviceMethod   = new DeviceTwinAndMethod(iotHubConnectionString, deviceName);
            DeviceTwinData      deviceTwinData = await deviceMethod.GetDeviceTwinData();

            deviceJson             = deviceTwinData.deviceJson;
            tagsJson               = deviceTwinData.tagsJson;
            reportedPropertiesJson = deviceTwinData.reportedPropertiesJson;
            desiredPropertiesJson  = deviceTwinData.desiredPropertiesJson;

            if (deviceJson == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #2
0
        public async Task <DeviceTwinData> GetDeviceTwinData()
        {
            DeviceTwinData result = new DeviceTwinData();

            dynamic registryManager = RegistryManager.CreateFromConnectionString(connString);

            try
            {
                var deviceTwin = await registryManager.GetTwinAsync(deviceName);

                if (deviceTwin != null)
                {
                    result.deviceJson             = deviceTwin.ToJson();
                    result.tagsJson               = deviceTwin.Tags.ToJson();
                    result.reportedPropertiesJson = deviceTwin.Properties.Reported.ToJson();
                    result.desiredPropertiesJson  = deviceTwin.Properties.Desired.ToJson();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + "Make sure you are using the latest Microsoft.Azure.Devices package.", "Device Twin Properties", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(result);
        }