2017-12-29 11 views
1

ich eine Verbindung habe das Gerät sdk zu verwendenaws-IOT-Gerät und Arbeitsplätze verlieren Verbindungen im gleichen Prozess

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

ich auch die neuen Arbeitsplätze sdk

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

dann i verwenden möge erhalten

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

ho w ist es möglich, beide im selben Prozess ohne die Verbindungsprobleme zu verwenden?

i verwenden Sie es wie unten

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()); 
    }); 

Antwort

0

Um jede Verbindung zu dem aws beantworten sollte eine eindeutige clientId hat.

Wenn Sie Schatten, Gerät und Job läuft, als wir für den Anschluss seine eigene einzigartige clientId erstellt

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

was wir haben getan haben, ist

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> 
}); 
Verwandte Themen