Jon
(Jon Murphy)
8
Got one for phpfina also! The code is from something Trystan wrote and then I modified slightly for my needs:
#!/usr/bin/php
<?php
$time_start = microtime(true);
// Directory of phpfina feeds, see: settings.php
chdir ('/home/pi/data/myApps');
$dir = "/home/pi/data/phpfina/";
// Feed id to read:
$feedid = 2;
//----------------------------------------------------
// read meta data
$meta = new stdClass();
$metafile = fopen($dir.$feedid.".meta", 'rb');
fseek($metafile,8);
$tmp = unpack("I",fread($metafile,4));
$meta->interval = $tmp[1];
$tmp = unpack("I",fread($metafile,4));
$meta->start_time = $tmp[1];
fclose($metafile);
$fh = fopen($dir."$feedid.dat", 'rb');
$filesize = filesize($dir."$feedid.dat");
$npoints = floor($filesize / 4.0);
$csv_file = "feed_" .$feedid. ".meta.csv";
$fp = fopen($csv_file, 'w');
for ($i=0; $i<$npoints; $i++)
{
$val = unpack("f",fread($fh,4));
$time = $meta->start_time + $i * $meta->interval;
$value = $val[1];
$array = array($time, $value);
if (!is_nan($value))
{
fputcsv($fp, $array);
//print $time."\t".$value."\n";
}
//print $time."\t".$value."\n";
}
fclose($fp);
print "feedDB: " .$dir.$feedid.".meta\n";
print "csv_file: " .$csv_file."\n";
print "filesize: " .$filesize."\n";
print "npoints: " .$npoints."\n\n";
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "Ran in $time seconds\n";
?>
All of the apps/scripts I add are placed in a “myApps” directory. Make sure you change these three lines for your needs:
chdir ('/home/pi/data/myApps');
$dir = "/home/pi/data/phpfina/";
$feedid = 2;
I know there is some data in mySQL (maybe some settings?!?) but I don’t believe it is the data you are looking for.