Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
process.exit();
}
if (argv.db) {
MongoClient = require('mongodb').MongoClient;
// TODO: maybe add a mongouri config paramter to the config.json so people can set this explicitly
var mongoUri = process.env.MONGOLAB_URI|| process.env.MONGOHQ_URI || 'mongodb://127.0.0.1:27017/' + argv.db;
MongoClient.connect(mongoUri, function(err, db) {
if(err) throw err;
dbo=db.db(argv.db);
collectionS = dbo.collection('tesla_stream');
collectionA = dbo.collection('tesla_aux');
});
}
if (argv.awsiot) {
var device = awsIot.device({
keyPath: creds.awsiot.keyPath, //path to your AWS Private Key
certPath: creds.awsiot.certPath, //path to your AWS Public Key
caPath: creds.awsiot.caPath, //path tp your AWS Root Certificate
clientId: creds.awsiot.clientId, //Your AWS IoT Client ID
region: creds.awsiot.region //The AWS region in whcih your IoT account is registered
});
if (!argv.topic) {
console.log('No AWS IOT topic specified. Using teslams/{id} where {id} is the vehicle id of the car');
argv.topic = 'teslams';
}
//
// Device is an instance returned by mqtt.Client(), see mqtt.js for full
// documentation.
//
device.on('connect', function() {
ulog('awsiot device connected!');
const awsIot = require("aws-iot-device-sdk");
const turf = require("@turf/along").default;
const route = require("./route.json");
const device = awsIot.device({
keyPath: "./harness-private.pem.key",
certPath: "./harness-certificate.pem.crt",
caPath: "./AmazonRootCA1.pem",
clientId: "testing",
host: "$$INSERT$$"
});
device.on("connect", () => {
console.log("connected");
runTest();
// * Uncomment this out to subscribe
// * Then uncomment the message event handler below
// device.subscribe("assetingest");
});
device.on("reconnect", () => {
constructor(getKeysResponse: GetKeysResponse) {
this.device = new awsIot.device({
region: getKeysResponse.region,
protocol: "wss",
// debug: true,
clientId: getKeysResponse.identityId,
accessKeyId: getKeysResponse.accessKeyId,
secretKey: getKeysResponse.secretAccessKey,
sessionToken: getKeysResponse.sessionToken,
port: 443,
host: getKeysResponse.iotEndpoint
});
if (getKeysResponse) {
this.identityId = getKeysResponse.identityId || "";
}
this.device.on("error", err => {
//
// Initialize our configuration.
//
AWS.config.region = AWSConfiguration.region;
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: AWSConfiguration.poolId
});
//
// Create the AWS IoT device object. Note that the credentials must be
// initialized with empty strings; when we successfully authenticate to
// the Cognito Identity Pool, the credentials will be dynamically updated.
//
const mqttClient = AWSIoTData.device({
//
// Set the AWS region we will operate in.
//
region: AWS.config.region,
//
////Set the AWS IoT Host Endpoint
host:AWSConfiguration.host,
//
// Use the clientId created earlier.
//
clientId: clientId,
//
// Connect via secure WebSocket
//
protocol: 'wss',
//
//
// Initialize our configuration.
//
AWS.config.region = AWSConfiguration.region;
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: AWSConfiguration.poolId
});
//
// Create the AWS IoT device object. Note that the credentials must be
// initialized with empty strings; when we successfully authenticate to
// the Cognito Identity Pool, the credentials will be dynamically updated.
//
const mqttClient = AWSIoTData.device({
//
// Set the AWS region we will operate in.
//
region: AWS.config.region,
//
// Set the AWS IoT Host Endpoint
// //
host:AWSConfiguration.host,
//
// Use the clientId created earlier.
//
clientId: clientId,
//
// Connect via secure WebSocket
//
protocol: 'wss',
app.setup = function() {
app.device = awsIot.device({
keyPath: __dirname + "/certs/MagicMirror.private.key",
certPath: __dirname + "/certs/MagicMirror.cert.pem",
caPath: __dirname + "/certs/root-CA.crt",
clientId: "MirrorMirror" + (new Date().getTime()),
region: "us-east-1",
host: "YOURID.iot.us-east-1.amazonaws.com",
});
app.device.on('connect', function() {
console.log('connect');
});
app.device.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
});
}
app.setup = function() {
app.device = awsIot.device({
keyPath: __dirname + "/certs/MagicMirror.private.key",
certPath: __dirname + "/certs/MagicMirror.cert.pem",
caPath: __dirname + "/certs/root-CA.crt",
clientId: "MagicMirror" + (new Date().getTime()),
region: "us-east-1",
host: "YOURID.iot.us-east-1.amazonaws.com",
});
/**
* AWS IoT - Connecting MagicMirror as a device to our AWS IoT topics
*/
console.log("Attempt to connect to AWS ");
app.device.on("connect", function() {
console.log("Connected to AWS IoT");
app.device.subscribe(app.TOPIC_TEXT);
**************************/
var awsIot = require("aws-iot-device-sdk");
var config = require("./device.json");
const commandLineArgs = require('command-line-args');
const optionDefinitions = [
{ name: 'verbose', alias: 'v', type: Boolean, defaultValue: false },
{ name: 'region', alias: 'r', type: String, defaultValue: config.region },
{ name: 'unitid', alias: 'u', type: String, defaultValue: config.deviceId }
];
const options = commandLineArgs(optionDefinitions);
var data = [];
try {
var device = awsIot.device({
keyPath: "cert/private.pem.key",
certPath: "cert/certificate.pem.crt",
caPath: "cert/root.pem.crt",
clientId: options.unitid,
region: options.region
});
var topic = "test/"+options.unitid;
var messages = [
{"line1":"I :heart: beer!","line2":"How about you?"},
{"line1":"Step right up...","line2":"and grab a beer!"},
{"line1":"What a beautiful","line2":"day for a beer!"},
{"line1":"HEY! YOU!","line2":"Want a beer?"}
]
var caPath = path.join(awsCerts, '/root-CA.crt');
self.log("Using the certificates that are presented as follows:");
self.log(" - keyPath : " + keyPath);
self.log(" - certPath : " + certPath);
self.log(" - caPath : " + caPath);
if (n.mode == "shadow") {
self.device = require('aws-iot-device-sdk').thingShadow({
keyPath : keyPath,
certPath : certPath,
caPath : caPath,
clientId : clientId,
host : self.endpoint,
protocol: 'mqtts'
});
} else {
self.device = require('aws-iot-device-sdk').device({
keyPath : keyPath,
certPath : certPath,
caPath : caPath,
clientId : clientId,
host : self.endpoint,
protocol: 'mqtts'
});
}
if (self.device) {
self.device.on('connect', function() {
callback('connected');
});
self.device.on('reconnect', function() {
callback('reconnected');
});
self.device.on('error', function(error) {
.then(key => {
adapter.log.debug(`URL key is ${JSON.stringify(key)}, clientId: ${clientId}`);
connectStarted = Date.now();
device = new DeviceModule({
privateKey: new Buffer(certs.private),
clientCert: new Buffer(certs.certificate),
caCert: fs.readFileSync(__dirname + '/keys/root-CA.crt'),
clientId,
username: 'ioBroker',
host: adapter.config.cloudUrl,
debug: !!adapter.config.debug,
baseReconnectTimeMs: 5000,
keepalive: 60
});
device.subscribe('command/' + clientId + '/#');
device.on('connect', onConnect);
device.on('close', onDisconnect);
device.on('reconnect', () => adapter.log.debug('reconnect'));
device.on('offline', () => adapter.log.debug('offline'));