Azure / azure-iot-sdk-node

A Node.js SDK for connecting devices to Microsoft Azure IoT services
https://docs.microsoft.com/en-us/azure/iot-hub/
Other
262 stars 227 forks source link

[Technical Question] How can we set Proxy setting for Provisioning of IOT device #1140

Closed RohitashavSoni closed 2 years ago

RohitashavSoni commented 2 years ago

We are trying to setup a DPS service for Azure Iot hub, we want to setup proxy for Provisioning through X509, In the Sample code : "register_x509.js"

We are using "var Transport = require('azure-iot-provisioning-device-mqtt').MqttWs;" library. In that, there is function call "setTransportOptions" and we sending our proxy agent as a permeant there :

`var transport = new Transport(); transport.setTransportOptions({webSocketAgent:new HttpsProxyAgent(process.env.HTTP_PROXY)}) var securityClient = new X509Security(registrationId, deviceCert); var deviceClient = ProvisioningDeviceClient.create( provisioningHost, idScope, transport, securityClient );

// Register the device. Do not force a re-registration. deviceClient.register(function (err, result) { if (err) { console.log("error registering device: " + err); } else { console.log("registration succeeded"); console.log("assigned hub=" + result.assignedHub); console.log("deviceId=" + result.deviceId); }`

Connection it's not happening, the initial tunneling is not happening. We also saw in documentation that Azure SDK has a proxy filter which automatically take Proxy variable from environment, we tried that as well but still no connection. Can please suggest a way for this use case.

Error we received : UnhandledPromiseRejectionWarning: Error: socket hang up

AshokPeddakotla-MSFT commented 2 years ago

Posted here as well : https://stackoverflow.com/questions/72989683/how-can-we-set-proxy-setting-for-provisioning-of-azure-iot-device