Using aws-iot-device-sdk-v2 package in a node.js app I am trying to connect new Iot device.
When using static credentials aws-iot-device-sdk-v2 package is working fine and giving proper response.
const CONFIG = {
endpoint: ***,
key: ***,
cert: ***,
client_id: ***,
topic: ***,
verbosity: ***,
ca_file: ***,
}
var clientID = 'webapp-' + this.uniqueId() + new Date().getTime();
const client_bootstrap = new io.ClientBootstrap();
const config_builder = iot.AwsIotMqttConnectionConfigBuilder.new_mtls_builder_from_path(CONFIG.cert, CONFIG.key);
config_builder.with_certificate_authority_from_path(undefined, CONFIG.ca_file);
config_builder.with_clean_session(false);
config_builder.with_client_id(clientID);
config_builder.with_endpoint(CONFIG.endpoint);
// Keep node running forever
setInterval(() => {}, 1 << 30);
const config = config_builder.build();
const client = new mqtt.MqttClient(client_bootstrap);
const connection = client.new_connection(config);
await connection.connect();
await this.subscribe(connection);
async subscribe (connection) {
await connection.subscribe(CONFIG.topic, mqtt.QoS.AtLeastOnce, (topic, payload) => {
try {
console.log('Got message: ', topic);
const json = decoder.decode(payload);
console.log(`Got payload: ${json}`)
const message = JSON.parse(json);
} catch(_) {}
});
}
question from:
https://stackoverflow.com/questions/65884555/how-to-create-iot-device-to-aws-using-aws-iot-device-sdk-v2-package 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…