<commit_before>const noble = require('noble');
const five = require('johnny-five');
const chipio = require('chip-io');

const minRssi = -70;
const maxRssi = -35;
const minBrightness = 5;
const maxBrightness = 254;
const rssiIncrement = (maxBrightness-minBrightness)/(maxRssi - minRssi);

var board = new five.Board({
  repl: false,
  io: new chipio()
});

var logError = function(error) {
  console.error(error);
}

board.on('ready', function() {
  var led = new chipio.StatusLed();
  var rssiIndicator = new five.Led(18);
  var sawBeacon = false;
  var previousRssi = minRssi;

  led.off();
  rssiIndicator.off();

  board.on('exit', function() {
    led.off();
    rssiIndicator.off();
  });

  setInterval(function(){
    if(!sawBeacon) {
      led.off();
      rssiIndicator.off();
    }
    sawBeacon = false;
  }, 1000);

  noble.on('stateChange', function(state) {
    if (state === 'poweredOn') {
      noble.startScanning(["bd4ac6100b4511e38ffd0800200c9a66"], true, logError);
    } else {
      noble.stopScanning();
    }
  });
  noble.on('stopScanning', function() {
    noble.startScanning(["bd4ac6100b4511e38ffd0800200c9a66"], true, logError);
  });
  noble.on('warning', logError);

  noble.on('discover', function(peripheral){
    if(sawBeacon && peripheral.rssi <= previousRssi) {
      return;
    }
    sawBeacon = true;
    previousRssi = peripheral.rssi;
    led.on();
    var rssi = Math.max(peripheral.rssi, minRssi);
    rssi = Math.min(peripheral.rssi, maxRssi);
    normalizedRssi =  (rssi-minRssi) * rssiIncrement;
    rssiIndicator.brightness(minBrightness + normalizedRssi);
  });
});<commit_msg>Add more details to error log<commit_after>const noble = require('noble');
const five = require('johnny-five');
const chipio = require('chip-io');

const minRssi = -70;
const maxRssi = -35;
const minBrightness = 5;
const maxBrightness = 254;
const rssiIncrement = (maxBrightness-minBrightness)/(maxRssi - minRssi);

var board = new five.Board({
  repl: false,
  io: new chipio()
});

var logError = function(msg) {
  return function(error) { console.error(msg, error) };
}

board.on('ready', function() {
  var led = new chipio.StatusLed();
  var rssiIndicator = new five.Led(18);
  var sawBeacon = false;
  var previousRssi = minRssi;

  led.off();
  rssiIndicator.off();

  board.on('exit', function() {
    led.off();
    rssiIndicator.off();
  });

  setInterval(function(){
    if(!sawBeacon) {
      led.off();
      rssiIndicator.off();
    }
    sawBeacon = false;
  }, 1000);

  noble.on('stateChange', function(state) {
    if (state === 'poweredOn') {
      noble.startScanning(["bd4ac6100b4511e38ffd0800200c9a66"], true, logError("Start scanning"));
    } else {
      noble.stopScanning();
    }
  });
  noble.on('stopScanning', function() {
    noble.startScanning(["bd4ac6100b4511e38ffd0800200c9a66"], true, logError("Resume scanning"));
  });
  noble.on('warning', logError("Noble warning"));

  noble.on('discover', function(peripheral){
    if(sawBeacon && peripheral.rssi <= previousRssi) {
      return;
    }
    sawBeacon = true;
    previousRssi = peripheral.rssi;
    led.on();
    var rssi = Math.max(peripheral.rssi, minRssi);
    rssi = Math.min(peripheral.rssi, maxRssi);
    normalizedRssi =  (rssi-minRssi) * rssiIncrement;
    rssiIndicator.brightness(minBrightness + normalizedRssi);
  });
});
{'fraction_non_alphanumeric': 0.15850746268656715, 'fraction_numerical': 0.03343283582089552, 'mean_word_length': 3.8285302593659942, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1288370', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1249, 'n_words': 225}