How to use the azure-iot-device.Client function in azure-iot-device

To help you get started, we’ve selected a few azure-iot-device examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andriyadi / Win10IoT-AzureIotHub-SmartLamp / SmartLamp / server.js View on Github external
function deviceIsReady(dev) {
    lamp.setIotHubDevice(dev);
    
    if (!dev.authentication || !dev.authentication.SymmetricKey) {
        return;
    }

    //create Azure IoT Hub conn string for a device
    var connStr = "HostName=" + iothubRegistry.config.host + ";CredentialScope=Device;DeviceId=" + dev.deviceId + ";SharedAccessKey=" + dev.authentication.SymmetricKey.primaryKey;
    lamp.setIotHubConnectionString(connStr);
    
    //set client    
    iothubClient = new iothubDev.Client(connStr, new iothub.Https());
    
    //register metadata first
    var metadataMsg = new iothubDev.Message(JSON.stringify(lamp.getMetadata()));
    iothubClient.sendEvent(metadataMsg, printResultFor('send'));
    
    // start telemetry data send routing
    setInterval(sendTelemetryData, 10000);

    //listen for notif
    setInterval(function () {
        if (!isWaiting) waitForNotifications();
    }, 1000);
}