Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*
// PARTICLE PHOTON USERS
// Add the following definition for the Particle plugin for Johnny-Five
var Particle = require("particle-io");
var token = 'YOUR PARTICLE ACCESS TOKEN HERE';
*/
var location = process.env.DEVICE_LOCATION || 'GIVE A NAME TO THE LOCATION OF THE THING';
var connectionString = process.env.IOTHUB_CONN || 'YOUR IOT HUB DEVICE-SPECIFIC CONNECTION STRING HERE';
// Create an Azure IoT client that will manage the connection to your IoT Hub
// The client is created in the context of an Azure IoT device, which is why
// you use a device-specific connection string.
var client = clientFromConnectionString(connectionString);
var deviceId = device.ConnectionString.parse(connectionString).DeviceId;
// Create a Johnny-Five board instance to represent your Particle Photon
// Board is simply an abstraction of the physical hardware, whether is is a
// Photon, Arduino, Raspberry Pi or other boards.
var board = new five.Board();
/*
// PARTICLE PHOTON USERS
// When creating a Board instance for the Photon you must specify the token and device ID
// for your Photon using the Particle-IO Plugin for Johnny-five.
// Replace the Board instantiation with the following:
var board = new five.Board({
io: new Particle({
token: token,
deviceId: 'YOUR PARTICLE PHOTON DEVICE IS OR ALIAS'
})
}).then(deviceInfo => {
const key = deviceInfo.authentication.SymmetricKey.primaryKey;
const connectionString = util.format(this.deviceConnectionString, devEUI, key);
const client = amqp.clientFromConnectionString(connectionString);
return new Promise((resolve, reject) => {
client.open(err => {
if (err) {
reject(err);
} else {
this.devices[devEUI] = client;
resolve(client);
}
});
});
});
}
return new Promise((resolve, reject) => {
let deviceAmqp = require('azure-iot-device-amqp');
let client = deviceAmqp.clientFromConnectionString(process.env.DEVICE_CONN_STRING);
client.open(err => {
if (err) reject(err);
resolve(client);
});
})
}
}).then(deviceInfo => {
const key = deviceInfo.authentication.symmetricKey.primaryKey
const connectionString = util.format(this.deviceConnectionString, deviceId, key)
const client = amqp.clientFromConnectionString(connectionString)
return new Promise((resolve, reject) => {
client.open(err => {
if (err) {
reject(err)
} else {
this.devices[deviceId] = client
resolve(client)
}
})
})
})
}
import * as five from 'johnny-five';
import * as raspi from 'raspi-io';
import * as Camera from 'camerapi';
import * as oxford from 'project-oxford';
import * as fs from 'fs';
import * as device from 'azure-iot-device';
import * as deviceAmqp from 'azure-iot-device-amqp';
let cogClient = new oxford.Client('d7889254b9244ec1ba54e8cf154ff359');
let connectionString = 'HostName=iot-workshop-hub.azure-devices.net;DeviceId=device1;SharedAccessKey=zyislRKCFj5k916xvNRyB0JPihQpad/56tzTMZMWpdk=';
let hubClient = deviceAmqp.clientFromConnectionString(connectionString);
//establishing connection to gpio
log('establishing connection to gpio...');
let board = new five.Board({ io: new raspi() });
board.on('ready', () => {
let led = new five.Led('GPIO26');
let button = new five.Button('GPIO20');
led.stop().off();
//open connection to iot hub
log('connecting to iot hub...');
hubClient.open(err => {
if (err)
log(err.message)
else {
log('READY');