Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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');
// 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');
// 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');
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(
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);
});
}
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);
});
}
'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);
return new Promise((resolve, reject) => {
ModuleClient.fromEnvironment(Transport, (err, client) => {
if (err) {
reject(err);
} else {
resolve(client);
}
});
});
}
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});
}
});
}
});