<commit_before><?php
/**
 * Simple interface to CBW relay boxes
 * 
 * (c) 2016 <NAME> (david at davidus dot sk) www.davidus.sk
 */

// app base path
$basePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;

// include classes
include $basePath . 'class' . DIRECTORY_SEPARATOR . 'CBW.php';
include $basePath . 'class' . DIRECTORY_SEPARATOR . 'Email.php';

// read in config file
$configFile = $basePath . 'conf' . DIRECTORY_SEPARATOR . 'config.json';
$sensorData = array();

if (file_exists($configFile) && is_readable($configFile)) {
	$jsonConfig = file_get_contents($configFile);
	$sensorData = json_decode($jsonConfig, true);
	
	if (empty($sensorData)) {
		die("No valid data found in '{$configFile}'!\r\n");
	}
} else {
	die("Config file '{$configFile}' is not accessible!\r\n");
}

// process the file and get sensor values
$cbw = new CBW();
$result = $cbw->getValues($sensorData);

// few sanity checks
if ($result && !empty($sensorData)) {
	foreach ($sensorData as $sensor => $data) {
		echo "{$sensor}> ";

		// do we have a value
		if (isset($data['value'])) {
			echo "Name: {$data['name']}, Value: {$data['value']} {$data['units']}\r\n";

			// did we cross the lower threshold?
			if (isset($data['thresholdLow']) && ($data['thresholdLow'] !== false) && ($data['value'] <= $data['thresholdLow'])) {
				echo "\tAlarm for low threshold of {$data['thresholdLow']} {$data['units']}";

				if (!empty($data['notify']) && is_array($data['notify'])) {
					$email = new Email();

					if ($email->ready) {
						$email->message("Notification for {$data['name']}", "Current value of {$data['value']} {$data['units']} is below your low threshold of {$data['thresholdLow']} {$data['units']}");

						foreach ($data['notify'] as $address) {
							$email->addAddress($address);
						}

						$email->send();
					}
				}//if
			}
			
			// did we cross the upper treshold?
			if (isset($data['thresholdHigh']) && ($data['thresholdHigh'] !== false) && ($data['value'] >= $data['thresholdHigh'])) {
				echo "\tAlarm for high threshold of {$data['thresholdHold']} {$data['units']}";
				
				if (!empty($data['notify']) && is_array($data['notify'])) {
					$email = new Email();<commit_msg>Added email support<commit_after><?php
/**
 * Simple interface to CBW relay boxes
 * 
 * (c) 2016 <NAME> (david at davidus dot sk) www.davidus.sk
 */

// app base path
$basePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;

// include classes
include $basePath . 'class' . DIRECTORY_SEPARATOR . 'CBW.php';
include $basePath . 'class' . DIRECTORY_SEPARATOR . 'Email.php';

// read in config file
$configFile = $basePath . 'conf' . DIRECTORY_SEPARATOR . 'config.json';
$sensorData = array();

if (file_exists($configFile) && is_readable($configFile)) {
	$jsonConfig = file_get_contents($configFile);
	$sensorData = json_decode($jsonConfig, true);
	
	if (empty($sensorData)) {
		die("No valid data found in '{$configFile}'!\r\n");
	}
} else {
	die("Config file '{$configFile}' is not accessible!\r\n");
}

// process the file and get sensor values
$cbw = new CBW();
$result = $cbw->getValues($sensorData);

// few sanity checks
if ($result && !empty($sensorData)) {
	foreach ($sensorData as $sensor => $data) {
		echo "{$sensor}> ";

		// do we have a value
		if (isset($data['value'])) {
			echo "Name: {$data['name']}, Value: {$data['value']} {$data['units']}\r\n";

			// did we cross the lower threshold?
			if (isset($data['thresholdLow']) && ($data['thresholdLow'] !== false) && ($data['value'] <= $data['thresholdLow'])) {
				echo "\tAlarm for low threshold of {$data['thresholdLow']} {$data['units']}";

				if (!empty($data['notify']) && is_array($data['notify'])) {
					$email = new Email();

					if ($email->ready) {
						$email->message("Notification for {$data['name']}", "Current value of {$data['value']} {$data['units']} is below your low threshold of {$data['thresholdLow']} {$data['units']}");

						foreach ($data['notify'] as $address) {
							$email->addAddress($address);
						}

						$email->send();
					}
				}//if
			}
			
			// did we cross the upper treshold?
			if (isset($data['thresholdHigh']) && ($data['thresholdHigh'] !== false) && ($data['value'] >= $data['thresholdHigh'])) {
				echo "\tAlarm for high threshold of {$data['thresholdHigh']} {$data['units']}";
				
				if (!empty($data['notify']) && is_array($data['notify'])) {
					$email = new Email();
{'fraction_non_alphanumeric': 0.21081081081081082, 'fraction_numerical': 0.0018018018018018018, 'mean_word_length': 4.110471806674338, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2672630', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1420, 'n_words': 369}