use of com.microsoft.azure.sdk.iot.service.Module in project azure-iot-sdk-java by Azure.
the class TokenRenewalTests method createModuleClient.
private InternalClient createModuleClient(IotHubClientProtocol protocol) throws IOException, IotHubException, ModuleClientException, URISyntaxException, InterruptedException {
UUID uuid = UUID.randomUUID();
String deviceId = "token-renewal-test-device-" + protocol + "-" + uuid.toString();
String moduleId = "token-renewal-test-module-" + protocol + "-" + uuid.toString();
com.microsoft.azure.sdk.iot.service.Device device = com.microsoft.azure.sdk.iot.service.Device.createFromId(deviceId, DeviceStatus.Enabled, null);
device = Tools.addDeviceWithRetry(registryManager, device);
Module module = Module.createModule(deviceId, moduleId, AuthenticationType.SAS);
module = Tools.addModuleWithRetry(registryManager, module);
ModuleClient moduleClient = new ModuleClient(DeviceConnectionString.get(iotHubConnectionString, device, module), protocol);
testIdentities.add(new TestModuleIdentity(moduleClient, device, module));
return moduleClient;
}
use of com.microsoft.azure.sdk.iot.service.Module 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();
}
use of com.microsoft.azure.sdk.iot.service.Module 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();
}
Aggregations