/**
 * Created by gwennael.buchet on 01/01/17.
 */
"use strict";

let keys = require("./secretKeys.js");
let mqtt = require('mqtt');

exports.init = function (mainCallback) {
	let shiftrClient = mqtt.connect(
		'mqtt://' + keys.SHIFTR_DEVICE_LOGIN + ':' + keys.SHIFTR_DEVICE_PWD + '@broker.shiftr.io', {
			clientId: 'Web Server'
		}
	);

	shiftrClient.on('connect', function () {
		console.log('shiftrClient has connected!');

		shiftrClient.subscribe(keys.SHIFTR_NAMESPACE);

		/*setInterval(function () {
			shiftrClient.publish(keys.SHIFTR_NAMESPACE, 'world');
		}, 1000);*/
	});

	shiftrClient.on('message', function (topic, message) {
		console.log('new message:', topic, message.toString());
		let json = JSON.parse(message);

		mainCallback(json.sender, json.quantity, "Shiftr.io");
	});
};

@@ -473,110 +473,8 @@
 CE);
-%0A%0A%09%09/*setInterval(function () %7B%0A%09%09%09shiftrClient.publish(keys.SHIFTR_NAMESPACE, 'world');%0A%09%09%7D, 1000);*/
 %0A%09%7D)

Clean code