<commit_before>var RaspiCam = require("raspicam"),
	colors = require("colors"),
	Spacebrew = require('./sb-1.3.0').Spacebrew,
	sb,
	camera,
	config = require("./machine"),
	fs = require("fs");


var image_path = __dirname + "/files/";


// setup spacebrew
sb = new Spacebrew.Client( config.server, config.name, config.description );  // create spacebrew client object


// create the spacebrew subscription channels
//sb.addPublish("config", "string", "");	// publish config for handshake
//sb.addSubscribe("config", "boolean");	// subscription for config handshake


sb.addSubscribe("capture button", "boolean");	// subscription for taking snapshot
sb.addSubscribe("test button", "boolean");		// subscription for sending test snapshot


sb.addPublish("image", "binary");		// publish the serialized binary image data


sb.onBooleanMessage = onBooleanMessage;	
sb.onOpen = onOpen;

// connect to spacbrew
sb.connect();  


/**
 * Function that is called when Spacebrew connection is established
 */
function onOpen() {
	console.log( "Connected through Spacebrew as: " + sb.name() + "." );

	// initialize RaspiCam timelapse
	camera = new RaspiCam({
		mode: "photo",
		output: image_path + "image.png", // will change this before taking a picture
		encoding: "png",
		width: 640,
		height: 480,
		timeout: 0 // take snapshot immediately with 0 delay
	});

	camera.on("start", function( err, timestamp ){
		//console.log("snapshot taken at " + timestamp);
	});

	camera.on("read", function( err, timestamp, filename ){
		console.log("snapshot taken with filename: " + filename);

		setTimeout(function(){
			fs.readFile(image_path + filename, function(err, data) {
				var base64data = data.toString('base64');
				console.log('sending base 64 with length' + base64data.length);

				var message = {
					filename: filename,
					binary: base64data
				};

				sb.send("image", "binary", message.toString('base64'));
			});
		}, 2000);
	});

	camera.on("data", function( err, timestamp, filename ){
		fs.readFile(image_path + filename, function(err, data) {
			var base64data = data.toString('base64');<commit_msg>err handling<commit_after>var RaspiCam = require("raspicam"),
	colors = require("colors"),
	Spacebrew = require('./sb-1.3.0').Spacebrew,
	sb,
	camera,
	config = require("./machine"),
	fs = require("fs");


var image_path = __dirname + "/files/";


// setup spacebrew
sb = new Spacebrew.Client( config.server, config.name, config.description );  // create spacebrew client object


// create the spacebrew subscription channels
//sb.addPublish("config", "string", "");	// publish config for handshake
//sb.addSubscribe("config", "boolean");	// subscription for config handshake


sb.addSubscribe("capture button", "boolean");	// subscription for taking snapshot
sb.addSubscribe("test button", "boolean");		// subscription for sending test snapshot


sb.addPublish("image", "binary");		// publish the serialized binary image data


sb.onBooleanMessage = onBooleanMessage;	
sb.onOpen = onOpen;

// connect to spacbrew
sb.connect();  


/**
 * Function that is called when Spacebrew connection is established
 */
function onOpen() {
	console.log( "Connected through Spacebrew as: " + sb.name() + "." );

	// initialize RaspiCam timelapse
	camera = new RaspiCam({
		mode: "photo",
		output: image_path + "image.png", // will change this before taking a picture
		encoding: "png",
		width: 640,
		height: 480,
		timeout: 0 // take snapshot immediately with 0 delay
	});

	camera.on("start", function( err, timestamp ){
		//console.log("snapshot taken at " + timestamp);
	});

	camera.on("read", function( err, timestamp, filename ){
		console.log("snapshot taken with filename: " + filename);

		setTimeout(function(){
			fs.readFile(image_path + filename, function(err, data) {
				if(err){
					console.log('Error attempting to read captured file with msg: '+ err);
					return false;
				}
				var base64data = data.toString('base64');
				console.log('sending base 64 with length' + base64data.length);

				var message = {
					filename: filename,
					binary: base64data
				};

				sb.send("image", "binary", message.toString('base64'));
			});
		}, 2000);
	});

	camera.on("data", function( err, timestamp, filename ){
		fs.readFile(image_path + filename, function(err, data) {
			var base64data = data.toString('base64');
{'fraction_non_alphanumeric': 0.1497116493656286, 'fraction_numerical': 0.014302191464821222, 'mean_word_length': 4.036004645760744, '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': '541007', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1269, 'n_words': 372}