tbibard/teleinfo-recorder

记录EDF电子计量表的电信信息帧

0.1.6 2014-01-29 08:43 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:27:10 UTC


README

TeleinfoRecorder,记录EDF电子计量表的电信信息帧。读取的帧可以记录在文件(如csv格式)或数据库(通过PDO)或Cosm.com或Sen.se等平台。

电信信息的技术规范:ERDF-NOI-CPT_02E

有许多方案可以实现自己的电信信息解调器,作者部分使用了www.suiviconso.fr的解调器,连接到Raspberry Pi。

注意

目前这是电信信息帧数据的部分管理(高峰/低谷时段)。

先决条件

  • PHP 5.3或更高版本
  • [可选] PHPUnit 3.5+ 用于执行测试

安装

TeleinfoRecorder可在Packagist上找到(tbibard/teleinfo-recorder),因此可以通过Composer进行安装。

{
    "require": {
        "tbibard/teleinfo-recorder": "0.1.*"
    }
}
composer install

如果您不使用Composer,您可以通过GitHub获取代码,并使用兼容PSR-0的自动加载器(例如Symfony2 ClassLoader组件)来加载TeleinfoRecorder的类。

使用

<?php
require 'vendor/autoload.php';

use TeleinfoRecorder\Recorder;
use TeleinfoRecorder\Handler\StreamHandler;
use TeleinfoRecorder\Handler\PdoHandler;
use TeleinfoRecorder\Processor\CopyProcessor;
use TeleinfoRecorder\Processor\VariationLastProcessor;
use TeleinfoRecorder\Processor\SumFieldsProcessor;

try {
    $recorder = new Recorder();

    // StreamHandler
    $recorder->pushHandler(new StreamHandler('/path/teleinfo.csv'));

    // PdoHandler
    $dbh = new PDO('mysql:dbname=teleinfo;host=localhost', 'teleinfo', 'teleinfo-password');
    $recorder->pushHandler(new PdoHandler($dbh, 'Teleinfo'));

    // Ajout de processors
    // Copy processor: copie simplement un index de l'enregistrement vers un autre index
    $copy = new CopyProcessor('HCHP');
    $recorder->pushProcessor($copy, 'IndexHP');

    // Variation processor: calcul la différence entre le relevé courant et le précédent
    $variationHCHC = new VariationLastProcessor('HCHC', __DIR__, 60);
    $variationHCHP = new VariationLastProcessor('HCHP', __DIR__, 60);
    $recorder->pushProcessor($variationHCHC, 'HCvariation');
    $recorder->pushProcessor($variationHCHP, 'HPvariation');

    // Sum processor: calcul la somme de deux index du relevé
    $sumconso = new SumFieldsProcessor(array('HCvariation', 'HPvariation'));
    $recorder->pushProcessor($sumconso, 'CONSO');

    // Write record
    $recorder->write();
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}

处理器

  • Stream: 文件记录
  • PdoHandler: 通过PDO记录到数据库
  • CosmFeedHandler: 在Cosm.com平台上记录到feed
  • SenseFeedHandler: 在Sen.se平台上记录到feed

处理器

  • Copy: 允许复制记录的索引到新索引
  • SumFields: 允许累加某些索引的值
  • VariationLast: 允许获取自上次抄表以来的差异。

文档

查看doc文件夹以获取更多详细信息。

作者

Thomas Bibard - thomas.bibard@neblion.net - https://twitter.com/tbibard

许可证

TeleinfoRecorder采用MIT许可证 - 请参阅LICENSE文件以获取更多详细信息。

致谢

这个库受到了Monolog库的启发。