Search in sources :

Example 36 with RegistryManager

use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.

the class DeviceManagerSample method GetDevice.

private static void GetDevice() throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    Device returnDevice;
    try {
        returnDevice = registryManager.getDevice(SampleUtils.deviceId);
        System.out.println("Device: " + returnDevice.getDeviceId());
        System.out.println("Device primary key: " + returnDevice.getPrimaryKey());
        System.out.println("Device secondary key: " + returnDevice.getSecondaryKey());
        System.out.println("Device ETag: " + returnDevice.geteTag());
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    registryManager.close();
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 37 with RegistryManager

use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.

the class DeviceManagerX509Sample method RemoveDevice.

private static void RemoveDevice() throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    try {
        registryManager.removeDevice(SampleUtils.deviceId);
        System.out.println("Device removed: " + SampleUtils.deviceId);
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    registryManager.close();
}
Also used : RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 38 with RegistryManager

use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.

the class ModuleManagerSample method UpdateModule.

private static void UpdateModule() throws Exception {
    String primaryKey = "[New primary key goes here]";
    String secondaryKey = "[New secondary key goes here]";
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    Module module = Module.createFromId(SampleUtils.deviceId, SampleUtils.moduleId0, null);
    module.getSymmetricKey().setPrimaryKeyFinal(primaryKey);
    module.getSymmetricKey().setSecondaryKeyFinal(secondaryKey);
    try {
        module = registryManager.updateModule(module);
        System.out.println("Device updated: " + module.getId());
        System.out.println("Device primary key: " + module.getPrimaryKey());
        System.out.println("Device secondary key: " + module.getSecondaryKey());
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    registryManager.close();
}
Also used : RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) Module(com.microsoft.azure.sdk.iot.service.Module) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 39 with RegistryManager

use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.

the class ModuleManagerSample method AddModule.

private static void AddModule(int n) throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    String moduleId;
    if (n == 0) {
        moduleId = SampleUtils.moduleId0;
    } else {
        moduleId = SampleUtils.moduleId1;
    }
    Module module = Module.createFromId(SampleUtils.deviceId, moduleId, null);
    try {
        module = registryManager.addModule(module);
        System.out.println("Module created: " + module.getId());
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    registryManager.close();
}
Also used : RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) Module(com.microsoft.azure.sdk.iot.service.Module) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Aggregations

RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)39 IOException (java.io.IOException)20 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)19 Device (com.microsoft.azure.sdk.iot.service.Device)15 Test (org.junit.Test)14 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)7 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)6 AzureSasCredential (com.azure.core.credential.AzureSasCredential)5 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)5 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)5 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)5 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)5 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)5 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)5 RegistryStatistics (com.microsoft.azure.sdk.iot.service.RegistryStatistics)4 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)3 Configuration (com.microsoft.azure.sdk.iot.service.Configuration)3 JobProperties (com.microsoft.azure.sdk.iot.service.JobProperties)3 Message (com.microsoft.azure.sdk.iot.service.Message)3 Module (com.microsoft.azure.sdk.iot.service.Module)3