IOT Hub: Device Connection String Generation Example
tulaseerao opened this issue · 9 comments
Hello Azure Team,
I would like to generate/retrieve device Coneection String using gem 'azure_mgmt_iot_hub' or any other supported azure gems. I was unable to find any examples or specs related to Device connections strings generation. I do have all credentials and able to make connection using Azure::IotHub::Profiles::Latest::Mgmt::Client. I am stuck where creation of device connection stings for a specific device using below snippet or any sample would be greatly appreciated.
@azure_options = { tenant_id: ENV['TENANT_ID'], client_id: ENV['CLIENT_ID'], client_secret: ENV['CLIENT_SECRET'], subscription_id: ENV['SUBSCRIPTION_ID'] }
iot_client = Azure::IotHub::Profiles::Latest::Mgmt::Client.new(@azure_options)
Here is the C# sample to generate Connection Strings for our IOT devices and I would like mimic same thing with rails app.
`using System.Threading.Tasks;
namespace Microsoft.Azure.Devices.Samples
{
public class Program
{
// The IoT Hub connection string. This is available under the "Shared access policies" in the Azure portal.
// For this sample either:
// - pass this value as a command-prompt argument
// - set the IOTHUB_CONN_STRING_CSHARP environment variable
// - create a launchSettings.json (see launchSettings.json.template) containing the variable
private static string s_connectionString =
"PULL ME FROM ENV";
private static string s_iotHubHostName = "PULL ME FROM ENV";
public static async Task<int> Main(string[] args)
{
RegistryManager registryManager = RegistryManager.CreateFromConnectionString(s_connectionString);
Device newDevice = new Device("testhubregistration");
var device = await registryManager.AddDeviceAsync(newDevice);
var deviceConnectionString = GetDeviceConnectionString(device, s_iotHubHostName);
return 0;
}
/**
* host name is like ***.net
*/
public static string GetDeviceConnectionString(Device device, string iotHubHostName)
{
return
$"HostName={device};DeviceId={device.Id};SharedAccessKey={device.Authentication.SymmetricKey.PrimaryKey}";
}
}`
what's the error you met? If you have c# code, the logic flow should be almost same.
what's the error you met? If you have c# code, the logic flow should be almost same.
@myronfanqiu I am not getting error and trying to mock same code snippet of c# unable to find corresponding example classes for below snippet in Ruby.
RegistryManager registryManager = RegistryManager.CreateFromConnectionString(s_connectionString);
`Device newDevice = new Device("testhubregistration");
var device = await registryManager.AddDeviceAsync(newDevice);
var deviceConnectionString = GetDeviceConnectionString(device, s_iotHubHostName);`
@tulaseerao Which sdk in c# are you using?
@myronfanqiu We are using latest what ever is here
https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.registrymanager?view=azure-dotnet
@tulaseerao looks like this sdk is related with data-plane operations. We cannot find corresponding ruby sdk in this repo. I'm not sure whether we have corresponding sdk in ruby or not. Let me invite service team to answer.
hi @myronfanqiu , I can speak from the Azure IoT SDKs perspective-- we do not have a corresponding Ruby SDK for data plane IoT usage (and we don't have one planned on the roadmap currently). If this is something you're interested in, please file a feature request on our UserVoice, and we appreciate the feedback! We currently offer IoT SDKs in C, Node.js, Python, C#, and Java.
Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!