How to use the azure-iot-device.ModuleClient.fromEnvironment 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 Azure / azure-iot-sdk-node / device / samples / simple_sample_module_method.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

var Protocol = require('azure-iot-device-mqtt').Mqtt;
var ModuleClient = require('azure-iot-device').ModuleClient;

ModuleClient.fromEnvironment(Protocol, function (err, client) {
  if (err) {
    console.error("Could not create client: " + err.toString());
    process.exit(-1);
  } else {
    console.log('got client');

    client.on('error', function (err) {
      console.error(err.message);
    });

    // connect to the edge instance
    client.open(function (err) {
      if (err) {
        console.error('Could not connect: ' + err.message);
      } else {
        console.log('Client connected');
github Azure / azure-iot-sdk-node / device / samples / simple_sample_module_twin.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

var ModuleClient = require('azure-iot-device').ModuleClient;
var Protocol = require('azure-iot-device-mqtt').Mqtt;

ModuleClient.fromEnvironment(Protocol, function (err, client) {
  if (err) {
    console.error("Could not create client: " + err.toString());
    process.exit(-1);
  } else {
    console.log('got client');

    client.on('error', function (err) {
      console.error(err.message);
    });

    // connect to the edge instance
    client.open(function(err) {
      if (err) {
        console.error('could not open IotHub client');
      }  else {
        console.log('client opened');
github Azure / azure-iot-sdk-node / device / samples / simple_sample_module.js View on Github external
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

var Protocol = require('azure-iot-device-mqtt').Mqtt;
var ModuleClient = require('azure-iot-device').ModuleClient;
var Message = require('azure-iot-device').Message;

ModuleClient.fromEnvironment(Protocol, function (err, client) {
  if (err) {
    console.error("Could not create client: " + err.toString());
    process.exit(-1);
  } else {
    console.log('got client');

    client.on('error', function (err) {
      console.error(err.message);
    });

    client.open(function (err) {
      if (err) {
        console.error('Could not connect: ' + err.message);
      } else {
        console.log('Client connected');
github Azure / iotedge / edge-modules / node-sensor-sample / app.js View on Github external
function main() {
  ModuleClient.fromEnvironment(Protocol, (err, client) => {
    if (err) {
      console.error(`Error creating ModuleClient instance: ${err}`);
    } else {
      client.open(err => {
        if (err) {
          console.error(`Connection error: ${err}`);
        } else {
          // register event handler for incoming messages
          client.on("inputMessage", (inputName, msg) => {
            client.complete(msg, printResultFor("completed"));
            const data = Buffer.from(msg.data).toString();
            console.log(`<- Data: ${JSON.stringify(JSON.parse(data))}`);
          });

          client.onMethod("reset", (req, res) => {
            console.log(
github nebrius / johnny-five-iot-edge / modules / johnny-five / src / messaging.js View on Github external
function init(cb) {
  
  console.debug('Connecting to IoT Edge...');
  ModuleClient.fromEnvironment(Transport, (err, moduleClient) => {
    if (err) {
      console.error(`IoT Edge Connection error: ${err}`);
      cb(err);
    }
    client = moduleClient;
    console.debug('Connected to IoT Edge');
    configure(cb);
  });
}
github nebrius / johnny-five-iot-edge / modules / edge-blink / src / messaging.js View on Github external
function init(cb) {

  console.debug('Connecting to IoT Edge...');
  ModuleClient.fromEnvironment(Transport, (err, moduleClient) => {
    if (err) {
      console.error(`IoT Edge Connection error: ${err}`);
      cb(err);
    }
    client = moduleClient;
    console.debug('Connected to IoT Edge');
    configure(cb);
  });
}
github Azure / azure-iot-sdk-node / device / samples / module_invoke_method.js View on Github external
'use strict';


var ModuleClient = require('azure-iot-device').ModuleClient;
var Mqtt = require('azure-iot-device-mqtt').Mqtt;

ModuleClient.fromEnvironment(Mqtt, (err, client) => {
    if (err) {
        console.error(err.toString());
        process.exit(-1);
    } else {
        client.invokeMethod('pierreca-edge-test', 'methodTarget', {
            methodName: 'doSomethingInteresting',
            payload: 'foo',
            responseTimeoutInSeconds: 5,
            connectTimeoutInSeconds: 2
        }, (err, resp) => {
            if (err) {
                console.error(err.toString());
                process.exit(-1);
            } else {
                console.log(JSON.stringify(resp, null, 2));
                process.exit(0);
github Azure / iotedge / edge-modules / edge-ble / src / bleedgemodule.ts View on Github external
return new Promise((resolve, reject) => {
      ModuleClient.fromEnvironment(Transport, (err, client) => {
        if (err) {
          reject(err);
        } else {
          resolve(client);
        }
      });
    });
  }
github Azure / azure-iot-sdk-node / edge-e2e / wrapper / nodejs-server-server / glue / moduleGlue.js View on Github external
return glueUtils.makePromise('moduleConnectFromEnvironment', function(callback) {
    ModuleClient.fromEnvironment(glueUtils.transportFromType(transportType), function(err, client) {
      glueUtils.debugFunctionResult('ModuleClient.fromEnvironment', err);
      if (err) {
        callback(err);
      } else {
        debug('calling moduleClient.open');
        client.open(function(err) {
          glueUtils.debugFunctionResult('client.open', err);
          if (err) {
            callback(err);
          } else {
            var connectionId = objectCache.addObject('moduleClient', client);
            callback(null, {connectionId: connectionId});
          }
        });
      }
    });