none
After provision to iot hub by Provisionning Service, how could I get the connection string to connect iot hub? RRS feed

  • Question

  • 1. run demo

    hunter@beauty:~/oss/azure/azure-iot-sdk-c/cmake$ ./provisioning_client/samples/prov_dev_client_sample/prov_dev_client_sample 

    Provisioning API Version: 1.2.8

    Registering... Press enter key to interrupt.

    Provisioning Status: PROV_DEVICE_REG_STATUS_CONNECTED
    Provisioning Status: PROV_DEVICE_REG_STATUS_ASSIGNING
    Provisioning Status: PROV_DEVICE_REG_STATUS_ASSIGNING



    2. successfully registered, no connection string in callback, no connection string in portal. 



    3. generated connection string doesn't work

    hunter@beauty:~/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests$ node SimulatedDevice-3.js "HostName=huntert1.azure-devices.net;DeviceId=test-docs-cert-device;x509=true"
    IoT Hub troubleshooting tutorial
    Simulated device #3

    /home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/azure-iot-mqtt-base/lib/mqtt_base.js:154
                throw new ReferenceError('Invalid transport configuration');
                ^

    ReferenceError: Invalid transport configuration
        at MqttBase.connect (/home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/azure-iot-mqtt-base/lib/mqtt_base.js:154:19)
        at /home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/azure-iot-device-mqtt/lib/mqtt.js:225:49
        at /home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/azure-iot-device-mqtt/lib/mqtt.js:890:17
        at /home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/azure-iot-device/lib/utils.js:12:9
        at /home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/azure-iot-common/lib/utils.js:29:13
        at /home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/getos/index.js:96:16
        at /home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/async/dist/async.js:421:16
        at iteratorCallback (/home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/async/dist/async.js:998:13)
        at /home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/async/dist/async.js:906:16
        at /home/hunter/oss/azure/azure-iot-samples-node-master/iot-hub/Tutorials/ConnectivityTests/node_modules/getos/index.js:91:18




    4.any example?


    Monday, September 3, 2018 11:28 AM

Answers

  • Hello Hunter,

    >>>"HostName=huntert1.azure-devices.net;DeviceId=test-docs-cert-device;x509=true"

    Your connection string has the right format. (Note: You need hide your hub name for security.)

    And for x509 authenticated device, you need specify the certificate and private key file like the following sample does:

    // String containing Hostname and Device Id in the following format:
    //  "HostName=<iothub_host_name>;DeviceId=<device_id>;x509=true"
    var connectionString = '<DEVICE CONNECTION STRING WITH x509=true>';
    var certFile = '<PATH-TO-CERTIFICATE-FILE>';
    var keyFile = '<PATH-TO-KEY-FILE>';
    var passphrase = '<KEY PASSPHRASE IF ANY>';
    
    // ...
    
     var options = {
       cert : fs.readFileSync(certFile, 'utf-8').toString(),
       key : fs.readFileSync(keyFile, 'utf-8').toString(),
       passphrase: passphrase
     };
    
    // Calling setOptions with the x509 certificate and key (and optionally, passphrase) will configure the client transport to use x509 when connecting to IoT Hub
    client.setOptions(options);

    You can have a try and let me know if it helps.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, September 4, 2018 1:19 AM
    Moderator

All replies

  • 3. I used the following command to generate the connectiong string.

      az iot hub generate-sas-token --device-id MyTestDevice --hub-name {YourIoTHubName}

    Monday, September 3, 2018 1:57 PM
  • Hello Hunter,

    >>>"HostName=huntert1.azure-devices.net;DeviceId=test-docs-cert-device;x509=true"

    Your connection string has the right format. (Note: You need hide your hub name for security.)

    And for x509 authenticated device, you need specify the certificate and private key file like the following sample does:

    // String containing Hostname and Device Id in the following format:
    //  "HostName=<iothub_host_name>;DeviceId=<device_id>;x509=true"
    var connectionString = '<DEVICE CONNECTION STRING WITH x509=true>';
    var certFile = '<PATH-TO-CERTIFICATE-FILE>';
    var keyFile = '<PATH-TO-KEY-FILE>';
    var passphrase = '<KEY PASSPHRASE IF ANY>';
    
    // ...
    
     var options = {
       cert : fs.readFileSync(certFile, 'utf-8').toString(),
       key : fs.readFileSync(keyFile, 'utf-8').toString(),
       passphrase: passphrase
     };
    
    // Calling setOptions with the x509 certificate and key (and optionally, passphrase) will configure the client transport to use x509 when connecting to IoT Hub
    client.setOptions(options);

    You can have a try and let me know if it helps.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, September 4, 2018 1:19 AM
    Moderator