Search in sources :

Example 11 with RegistryManager

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

the class DeviceManagerX509Sample method AddDevice.

private static void AddDevice() throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    Device device;
    if (isSelfSigned) {
        device = Device.createDevice(SampleUtils.deviceId, AuthenticationType.SELF_SIGNED);
    } else {
        device = Device.createDevice(SampleUtils.deviceId, AuthenticationType.CERTIFICATE_AUTHORITY);
    }
    try {
        device = registryManager.addDevice(device);
        System.out.println("Device created: " + device.getDeviceId());
        if (isSelfSigned) {
            System.out.println("Device primary thumbprint: " + device.getPrimaryThumbprint());
            System.out.println("Device secondary thumbprint: " + device.getSecondaryThumbprint());
        }
    } 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 12 with RegistryManager

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

the class DeviceManagerX509Sample 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 eTag: " + returnDevice.geteTag());
        if (isSelfSigned) {
            System.out.println("Device primary thumbprint: " + returnDevice.getPrimaryThumbprint());
            System.out.println("Device secondary thumbprint: " + returnDevice.getSecondaryThumbprint());
        }
    } 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 13 with RegistryManager

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

the class ModuleManagerSample method RemoveModule.

private static void RemoveModule() throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    try {
        registryManager.removeModule(SampleUtils.deviceId, SampleUtils.moduleId0);
        System.out.println("Module removed: " + SampleUtils.moduleId0);
        registryManager.removeModule(SampleUtils.deviceId, SampleUtils.moduleId1);
        System.out.println("Module removed: " + SampleUtils.moduleId1);
    } 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 14 with RegistryManager

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

the class ModuleManagerSample method GetModule.

private static void GetModule() throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    Module returnModule;
    try {
        returnModule = registryManager.getModule(SampleUtils.deviceId, SampleUtils.moduleId0);
        System.out.println("Module: " + returnModule.getId());
        System.out.println("Module primary key: " + returnModule.getPrimaryKey());
        System.out.println("Module secondary key: " + returnModule.getSecondaryKey());
        System.out.println("Module eTag: " + returnModule.geteTag());
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    List<Module> list = registryManager.getModulesOnDevice(SampleUtils.deviceId);
    for (Module module : list) {
        System.out.println("Module: " + module.getId());
        System.out.println("Module primary key: " + module.getPrimaryKey());
        System.out.println("Module secondary key: " + module.getSecondaryKey());
        System.out.println("Module eTag: " + module.geteTag());
    }
    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 15 with RegistryManager

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

the class RoleBasedAuthenticationSample method runRegistryManagerSample.

private static String runRegistryManagerSample(String iotHubHostName, TokenCredential credential) {
    // RegistryManager has some configurable options for HTTP read and connect timeouts, as well as for setting proxies.
    // For this sample, the default options will be used though.
    RegistryManagerOptions options = RegistryManagerOptions.builder().build();
    // This constructor takes in your implementation of TokenCredential which allows you to use RBAC authentication
    // rather than symmetric key based authentication that comes with constructors that take connection strings.
    RegistryManager registryManager = new RegistryManager(iotHubHostName, credential, options);
    String deviceId = "my-new-device-" + UUID.randomUUID().toString();
    Device newDevice = Device.createDevice(deviceId, AuthenticationType.SAS);
    try {
        System.out.println("Creating device " + deviceId);
        registryManager.addDevice(newDevice);
        System.out.println("Successfully created device " + deviceId);
    } catch (IOException | IotHubException e) {
        System.err.println("Failed to register new device");
        e.printStackTrace();
        System.exit(-1);
    }
    return deviceId;
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) RegistryManagerOptions(com.microsoft.azure.sdk.iot.service.RegistryManagerOptions) 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