2017-12-29 16 views
1

私はデバイスSDKAWS-IOTデバイスとジョブが同じプロセス内の接続を失い

const device = awsIot.device(config.DeviceOptions); 

を使用しての接続を持って、私は新しい仕事を使用することも必要ではその後、私が手

const jobs = awsIot.jobs(config.DeviceOptions); 

をSDK

connect 
offline 
connection lost - will attempt reconnection in 1 seconds... 
close 
reconnect 

ホw接続の問題がなく同じプロセスで両方を使用することは可能ですか?

独特のclientIdを持つべきである私は、AWSへの各接続に答えるために

var awsIot = require('aws-iot-device-sdk'); 
var SystemInfo = require('./trace/systeminfo'); 
// var JobsModule = require('./jobs/jobs'); 

var config = require('./config'); 

const device = awsIot.device(config.DeviceOptions); 
const jobs = awsIot.jobs(config.DeviceOptions); 

var timeout; 
var count = 0; 
const minimumDelay = 250; 


device.subscribe('topic_2'); 


device 
    .on('connect', function() { 
     console.log('connect'); 
    }); 
device 
    .on('close', function() { 
     console.log('close'); 
    }); 
device 
    .on('reconnect', function() { 
     console.log('reconnect'); 
    }); 
device 
    .on('offline', function() { 
     console.log('offline'); 
    }); 
device 
    .on('error', function (error) { 
     console.log('error', error); 
    }); 
device 
    .on('message', function (topic, payload) { 
     console.log('message', topic, payload.toString()); 
    }); 

答えて

0

以下のようにそれを使用しています。我々は

var device = awsIot.device({ 
    keyPath: <YourPrivateKeyPath>, 
    certPath: <YourCertificatePath>, 
    caPath: <YourRootCACertificatePath>, 
    clientId: 'device -'+thingName, 
     host: <YourCustomEndpoint> 
}); 

var thingShadows = awsIot.thingShadow({ 
    keyPath: <YourPrivateKeyPath>, 
    certPath: <YourCertificatePath>, 
    caPath: <YourRootCACertificatePath>, 
    clientId: 'thingShadows-'+thingName, 
     host: <YourCustomEndpoint> 
}); 

var jobs = awsIot.jobs({ 
    keyPath: <YourPrivateKeyPath>, 
    certPath: <YourCertificatePath>, 
    caPath: <YourRootCACertificatePath>, 
    clientId: 'jobs-'+thingName, 
     host: <YourCustomEndpoint> 
}); 
をやっているんでした何

あなたは、接続のために私たちが作成したよりも実行している独自のclientIdを影、デバイスと仕事をしている場合は

var thingShadows = awsIot.thingShadow({ 
    keyPath: <YourPrivateKeyPath>, 
    certPath: <YourCertificatePath>, 
    caPath: <YourRootCACertificatePath>, 
    clientId: <YourUniqueClientIdentifier>, 
     host: <YourCustomEndpoint> 
}); 

関連する問題