<?php

date_default_timezone_set('Europe/Amsterdam');

echo '"',date("Y-m-d H:i:s", time ()),'"',';'; // zelfgemaakte tijd voor de grafiek en de database select recdatetime
	$engine = '192.168.1.18';  
	$port = '81';
	$connection = fsockopen($engine, $port); 
	

	$line[1] = fgets($connection, 55);
	
	$appnr = (substr($line[1],0,22));
	if(!($appnr == '/KMP5 KA6U001585396111')){exit;} //if not /KMP5 KA6U001585396111 restart telnetsessie
 	//exec('http://127.0.0.1/telnet2.php');
	
	echo '"', substr($line['1'],0,22),'"',';'; // nu voor gegevens nog niet belangrijk maar kan voor trigger gebruikt worden app nummer /KMP5 KA6U001585396111
	$line[2] = fgets($connection, 55);
	//echo '"', substr($line['2'],1,2),'"',';'; // zie boven spatie
	$line[3] = fgets($connection, 55);
	//echo '"', substr($line['3'],11,34),'"',';';// zie boven app nummer2
	$line[4] = fgets($connection, 55);
	//if (substr($line['4'],10,9) = 0)) {file_get_contents('http://127.0.0.1/telnet2.php') ;}
	echo '"', substr($line['4'],11,4),'"',';';// verbruik laag T1
	$line[5] = fgets($connection, 55);
	echo '"', substr($line['5'],11,4),'"',';';//verbruik hoog T2
	$line[6] = fgets($connection, 55);
	echo '"', substr($line['6'],11,4),'"',';'; //teruglever laag T1
	$line[7] = fgets($connection, 55);
	echo '"', substr($line['7'],11,4),'"',';'; //teruglever hoog T2
	$line[8] = fgets($connection, 55);
	echo '"', substr($line['8'],15,1),'"',';'; // teller 1_2
	$line[9] = fgets($connection, 55);
	echo '"', substr($line['9'],13,4),'"',';'; // verbruik
	$line[10] = fgets($connection, 55);
	echo '"', substr($line['10'],13,4),'"',';'; //oplever
	$line[11] = fgets($connection, 55);
	//echo '"', substr($line['11'],11,3),'"',';'; //max toegestaan vermogen 999A 
	$line[12] = fgets($connection, 55);
	echo '"', substr($line['12'],12,1),'"',';'; // switch_pos day /night
	$line[13] = fgets($connection, 55);
	//echo '"', substr($line['13'],11,2),'"',';'; //iets 
	$line[14] = fgets($connection, 55);
	//echo '"', substr($line['14'],11,2),'"',';'; //iets
	$line[15] = fgets($connection, 55);
	//echo '"', substr($line['15'],11,1),'"',';';// aantal app
	$line[16] = fgets($connection, 55);
	//echo '"', substr($line['16'],11,34),'"',';';
	$line[17] = fgets($connection, 55);
	echo '"','20',substr($line['17'],11,2),'-',substr($line['17'],13,2),'-',substr($line['17'],15,2),' ',substr($line['17'],17,2),':',substr($line['17'],19,2),':',substr($line['17'],21,2),'"',';'; //string gesplitst datum tijd gasmeter 1 maal per uur
	$line[18] = fgets($connection, 55);
	//echo '"', substr($line['17'],25,2),'"',';';
	$line[19] = fgets($connection, 55);
	//echo '"', substr($line['17'],29,2),'"',';';
	$line[20] = fgets($connection, 55);
	//echo '"', substr($line['17'],33,1),'"',';';
	$line[21] = fgets($connection, 55);
	echo '"', substr($line['18'],1,9),'"',';'; //gas teller stand
	$line[22] = fgets($connection, 55);
	//echo '"', substr($line['17'],48,2),'"',';'; // onnodige data
	$line[23] = fgets($connection, 55);
	//echo '"', substr($line['19'],11,1),'"',';';
	echo '"',date("Y-m-d"),'"',';';// voor gebtuik in grafiek
	echo '"',date("H:i"),'"',';'; //voor gebruik in grafiek
		

fclose($connection);

?>