premier commit
This commit is contained in:
50
code/teleinfo.php
Normal file
50
code/teleinfo.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* teleinfo - traite des trames d'informations de télérelevé
|
||||
*/
|
||||
|
||||
|
||||
// Obtenez le chemin absolu du répertoire courant
|
||||
$basePath = __DIR__;
|
||||
|
||||
// Inclure le fichier de configuration
|
||||
|
||||
function lireTrameConso($handle)
|
||||
{
|
||||
$currentChar = '';
|
||||
$currentTrame = '';
|
||||
$trameData = '';
|
||||
|
||||
while ($currentChar != chr(2)) {
|
||||
$currentChar = fread($handle, 1);
|
||||
if ($currentChar == chr(10)) {
|
||||
$currentTrame .= ',';
|
||||
} elseif ($currentChar != chr(2) && $currentChar != chr(13)) {
|
||||
$currentTrame .= $currentChar;
|
||||
}
|
||||
}
|
||||
$currentTrame .= 'TIMESTAMP ' . time() . "\n";
|
||||
return $currentTrame;
|
||||
}
|
||||
|
||||
$handle = fopen('/dev/ttyAMA0', "r");
|
||||
|
||||
if ($handle) {
|
||||
while (true) {
|
||||
$dateJour = date('Ymd');
|
||||
$trame = lireTrameConso($handle);
|
||||
|
||||
// Utiliser le chemin du fichier CSV à partir de la configuration
|
||||
$fp = fopen($basePath . '/../data/teleinfo_' . $dateJour . '.csv', 'a');
|
||||
if ($fp) {
|
||||
fwrite($fp, $trame);
|
||||
fclose($fp);
|
||||
} else {
|
||||
echo "Erreur : Impossible d'ouvrir le fichier CSV pour écriture.";
|
||||
}
|
||||
}
|
||||
fclose($handle);
|
||||
} else {
|
||||
echo "Erreur : Impossible d'ouvrir le fichier /dev/ttyAMA0.";
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user