<commit_before>#!/usr/bin/env node
/*
 * Created by <NAME> ©2016
 * Sources:
 * - https://www.npmjs.com/package/mqtt
 * - https://mosquitto.org/
 *
 */

var fs = require('fs');
var util = require('util');
var mqtt = require('mqtt');
//var express = require('express');
var hsl2rgb = require('hsv-rgb');

//additionally write console.log to log file
var log_file = fs.createWriteStream(__dirname + '/debug.log', {flags: 'w'});
var log_stdout = process.stdout;
console.log = function (d) { //
    log_file.write(util.format(d) + '\n');
    log_stdout.write(util.format(d) + '\n');
};

//SOCKET
const server = require('./server');
const io = server.io;

//MQTT stuff
var client = mqtt.connect('mqtt://192.168.178.168');
var domain = "RGB-LED-control";
var topicRegistration = domain + "/registration";
var topicACK = domain + "/ack/+";
var topicControl = domain + "/data/RGB/";
var topicFade = domain + "/data/fade/";

var devices = {
    "18:FE:34:CC:FC:EA": {room: 1},
    "18:FE:34:D4:2E:BD": {room: 2},
    "5C:CF:7F:88:1B:5D": {room: 3},
    "18:FE:34:D3:F5:7F": {room: 4},
    "5C:CF:7F:8B:F0:70": {room: 5}, //Leandros nodeMCU
    "5C:CF:7F:1B:6F:85": {room: 6},
    "5C:CF:7F:8B:C5:03": {room: 7},
    "5C:CF:7F:88:1A:13": {room: 8},
    "5C:CF:7F:88:1D:A0": {room: 12},
    "5C:CF:7F:88:1E:04": {room: 14},
    "5C:CF:7F:8B:C9:C4": {room: 83},
    "5C:CF:7F:88:1B:28": {room: 84},
};

// deviceObjs is for properties that can't be serialized to json, e.g. intervals
var deviceObjs = {};
Object.keys(devices).forEach(device => deviceObjs[device] = {});

var sets = {
    "all": Object.keys(devices),
    "segment1": Object.keys(devices).slice(0, 4),
    "segment2": Object.keys(devices).slice(4, 8),
    "segment3": Object.keys(devices).slice(8)
};

function sendRGB(mac, rgb) {
    client.publish(topicControl + mac, rgb);
    console.log(mac + " <set " + rgb);
}

function sendFade(mac, rgb, fadeTime) //
{
    var fadeStr = rgb + ";" + fadeTime;
    client.publish(topicFade + mac, fadeStr);
    console.log(mac + " <fade " + rgb + " in " + fadeTime + "ms");<commit_msg>save rgb value in device object<commit_after>#!/usr/bin/env node
/*
 * Created by <NAME> ©2016
 * Sources:
 * - https://www.npmjs.com/package/mqtt
 * - https://mosquitto.org/
 *
 */

var fs = require('fs');
var util = require('util');
var mqtt = require('mqtt');
//var express = require('express');
var hsl2rgb = require('hsv-rgb');

//additionally write console.log to log file
var log_file = fs.createWriteStream(__dirname + '/debug.log', {flags: 'w'});
var log_stdout = process.stdout;
console.log = function (d) { //
    log_file.write(util.format(d) + '\n');
    log_stdout.write(util.format(d) + '\n');
};

//SOCKET
const server = require('./server');
const io = server.io;

//MQTT stuff
var client = mqtt.connect('mqtt://192.168.178.168');
var domain = "RGB-LED-control";
var topicRegistration = domain + "/registration";
var topicACK = domain + "/ack/+";
var topicControl = domain + "/data/RGB/";
var topicFade = domain + "/data/fade/";

var devices = {
    "18:FE:34:CC:FC:EA": {room: 1},
    "18:FE:34:D4:2E:BD": {room: 2},
    "5C:CF:7F:88:1B:5D": {room: 3},
    "18:FE:34:D3:F5:7F": {room: 4},
    "5C:CF:7F:8B:F0:70": {room: 5}, //Leandros nodeMCU
    "5C:CF:7F:1B:6F:85": {room: 6},
    "5C:CF:7F:8B:C5:03": {room: 7},
    "5C:CF:7F:88:1A:13": {room: 8},
    "5C:CF:7F:88:1D:A0": {room: 12},
    "5C:CF:7F:88:1E:04": {room: 14},
    "5C:CF:7F:8B:C9:C4": {room: 83},
    "5C:CF:7F:88:1B:28": {room: 84},
};

// deviceObjs is for properties that can't be serialized to json, e.g. intervals
var deviceObjs = {};
Object.keys(devices).forEach(device => deviceObjs[device] = {});

var sets = {
    "all": Object.keys(devices),
    "segment1": Object.keys(devices).slice(0, 4),
    "segment2": Object.keys(devices).slice(4, 8),
    "segment3": Object.keys(devices).slice(8)
};

function sendRGB(mac, rgb) {
    client.publish(topicControl + mac, rgb);
    console.log(mac + " <set " + rgb);
}

function sendFade(mac, rgb, fadeTime) //
{
    devices[mac].color = rgb;
    var fadeStr = rgb + ";" + fadeTime;
    client.publish(topicFade + mac, fadeStr);
    console.log(mac + " <fade " + rgb + " in " + fadeTime + "ms");
{'fraction_non_alphanumeric': 0.21860133206470028, 'fraction_numerical': 0.05423406279733587, 'mean_word_length': 3.8333333333333335, 'pattern_counts': {'":': 32, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, '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': '1267285', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1699, 'n_words': 348}