<commit_before>#!/usr/bin/env node
//Dependencias Broker
var mosca = require('mosca');
//Dependencias WEB Server
var mqtt = require('mqtt');


var ascoltatore = {
  //using ascoltatore
  type: 'mongo',        
  url: 'mongodb://localhost:27017/mqtt',
  pubsubCollection: 'ascoltatori',
  mongo: {}
};

var moscaSettings = {
  port: 1883,
  backend: ascoltatore,
  persistence: {
    factory: mosca.persistence.Mongo,
    url: 'mongodb://localhost:27017/mqtt'
  }
};

var server = new mosca.Server(moscaSettings);
server.on('ready', setup);

server.on('clientConnected', function(client) {
    console.log('client connected', client.id);     
});

// fired when a message is received
server.on('published', function(packet, client) {
  console.log('Published', packet.topic);

});

//in case of an error
process.on("uncaughtException", function(error) {
  return console.log(error.stack);
});




// fired when the mqtt server is ready
function setup() {
  console.log('Mosca server is up and running')
}

//Server WEB

var socket = require('socket.io');

var mqttbroker = 'localhost';
var mqttport = 1883;

var io = socket.listen(3000);
var mqttclient = mqtt.createClient(mqttport, mqttbroker);



// Reduce socket.io debug output
io.set('log level', 0)

// Configuracion de respuestas de Socket.io. desde la web para el controlador
io.sockets.on('connection', function (socket) {
    socket.on('subscribe', function (data) {
        mqttclient.subscribe(data.topic);
    });
    socket.on('controlador', function (data) {
        publicarEnArduino(data);
    });
});

function publicarEnArduino(data){
    mqttclient.publish(data.topic , data.payload);
}
// FIN WEB-CONTROLADOR SOCKET.IO

// Mensajes para la web desde arduino
mqttclient.on('message', function(topic, payload) {
    io.sockets.emit('mqtt',
        {'topic'  : topic,
         'payload' : payload
        }
    );
});
//FIN MENSAJES PARA LA CONTROLADOR-WEB.


<commit_msg>Revert "se modifo el sketch de arduino y el serverMQ"<commit_after>#!/usr/bin/env node
//Dependencias Broker
var mosca = require('mosca');
//Dependencias WEB Server
var mqtt = require('mqtt');


var ascoltatore = {
  //using ascoltatore
  type: 'mongo',        
  url: 'mongodb://localhost:27017/mqtt',
  pubsubCollection: 'ascoltatori',
  mongo: {}
};

var moscaSettings = {
  port: 1883,
  backend: ascoltatore,
  persistence: {
    factory: mosca.persistence.Mongo,
    url: 'mongodb://localhost:27017/mqtt'
  }
};

var server = new mosca.Server(moscaSettings);
server.on('ready', setup);

server.on('clientConnected', function(client) {
    console.log('client connected', client.id);     
});

// fired when a message is received
server.on('published', function(packet, client) {
  console.log('Published', packet.topic);

});

//in case of an error
process.on("uncaughtException", function(error) {
  return console.log(error.stack);
});




// fired when the mqtt server is ready
function setup() {
  console.log('Mosca server is up and running')
}

//Server WEB

var socket = require('socket.io');

var mqttbroker = 'localhost';
var mqttport = 1883;

var io = socket.listen(3000);
var mqttclient = mqtt.createClient(mqttport, mqttbroker);



// Reduce socket.io debug output
io.set('log level', 0)

// Subscribe to topic
io.sockets.on('connection', function (socket) {
    socket.on('subscribe', function (data) {
        mqttclient.subscribe(data.topic);
    });
});

// Push the message to socket.io
mqttclient.on('message', function(topic, payload) {
    io.sockets.emit('mqtt',
        {'topic'  : topic,
         'payload' : payload
        }
    );
});




{'fraction_non_alphanumeric': 0.14962593516209477, 'fraction_numerical': 0.012745912995289554, 'mean_word_length': 3.682230869001297, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7435109', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1237, 'n_words': 292}