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();
}
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();
}
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();
}
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();
}
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;
}
Aggregations