2016-08-19 2 views
1
var awsIot = require('aws-iot-device-sdk'); 

    var myThingName = 'pi_2'; 
var fs, configurationFile; 

    configurationFile = './configuration.json'; 
    fs = require('fs'); 
    var args = JSON.parse(fs.readFileSync(configurationFile)); 
var thingShadows = awsIot.thingShadow({ 

    keyPath: args.privateKey, 
    certPath: args.clientCert, 
    caPath: args.caCert, 
    clientId: myThingName, 
    region: args.host 

}); 

thingShadows 
    .on('connect', function() { 

    console.log('connect'); 
device.subscribe('topic_1'); 


    device.publish('topic_2', JSON.stringify({ test_data: 1})); 
    }); 

tout en faisant cela a erreur: -ombre chose sur aws-IOT en utilisant Node.js obtenir un code error..also ci-joint pour reffrence

Error: getaddrinfo ENOTFOUND at errnoException (dns.js:37:11) at Object.onanswer [as oncomplete] (dns.js:124:16)

+0

Ici j'ai eu la réponse !!! Je viens de changer la région us-east-1 (N.Virginia) en eu-west-1 (Irlande). Cette erreur se produit en raison du serveur est occupé ou ne répond pas à partir de ce moment .. et également ajouter de nouveaux certificats dans mon programme –

Répondre

0

Voici mon code mis à jour pour la mise à jour chose ombres sur aws-IOT: -

var awsIot = require('aws-iot-device-sdk'); 
var myThingName = 'pi_2'; 
var thingShadows =awsIot.thingShadow({ 
keyPath: './private.pem.key', 
certPath: './certificate.pem.crt', 
caPath: './root-CA.crt', 
clientId: myThingName, 
region: 'ap-southeast-1' 
}); 
mythingstate = { 
"state": { 
"reported": { 
    "ip": "sagar"//update your state here. 
}`}`}` 

thingShadows.on('connect', function() { 
console.log("Connected..."); 
console.log("Registering..."); 
thingShadows.register(myThingName); 

// une mise à jour provoque droite suite d'une erreur de délai d'attente, donc nous attendons environ 2 secondes

setTimeout(function() { 
console.log("Updating my IP address..."); 
clientTokenIP = thingShadows.update(myThingName, mythingstate); 
console.log("Update:" + clientTokenIP); 
}, 2500); 
// Code below just logs messages for info/debugging 
thingShadows.on('status',function(thingName, stat, clientToken, 
stateObject) { 
console.log('received '+stat+' on '+thingName+': 
'+JSON.stringify(stateObject)); 
}); 
thingShadows.on('update',function(thingName, stateObject) { 
console.log('received update '+' on '+thingName+': '+`JSON.stringify(stateObject)); 
}); 
thingShadows.on('delta',function(thingName, stateObject) { 
console.log('received delta '+' on '+thingName+': '+`JSON.stringify(stateObject));`});` 

thingShadows.on('timeout',`function(thingName, clientToken) {` 
console.log('received timeout for '+ clientToken)`});` 

thingShadows.on('close', function() {` 
console.log('close'); 
}); 

thingShadows`.on('reconnect', function() {` 
console.log('reconnect'); 
}); 

thingShadows`.on('offline', function() { 
console.log('offline'); 
}); 

thingShadows`.on('error', function(error) { 
console.log('error', error); 
});`});`