无法从epever读取数据到树莓派

时间:2019-09-05 01:17:12

标签: php raspberry-pi

我正在使用Raspberry-pi通过rs485从epever读取数据到USB。我正在使用此PHP文件读取数据。

<?php
    /*
    * PHP EpSolar Tracer Class (PhpEpsolarTracer) v0.9
    *
    */

    //EPEver tracer php library
    require_once 'PhpEpsolarTracer.php';
    //influxDB php client library
    require 'vendor/autoload.php';

    //Define IP of influxDB
    $host = 'localhost';

    $tracer = new PhpEpsolarTracer('/dev/ttyUSBACM0');
    $client = new InfluxDB\Client($host,8086,"root","root");

    $db = $client->selectDB("logger");

    //'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'

    Print "\n Realtime Data\n";

    if ($tracer->getRealtimeData()) {
        for ($i = 0; $i < count($tracer->realtimeData); $i++) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "http://localhost:8086/write?db=powerwall" );
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            $Item = $tracer->realtimeData[$i];
            $Key_Name = str_replace(" ","-",$tracer->realtimeKey[$i]);
            Print str_pad($i, 2, '0', STR_PAD_LEFT) . " " . $Key_Name . " " . $Item . "\n";
            curl_setopt($ch, CURLOPT_POSTFIELDS, "$Key_Name,unit=Realtime value=$Item" );
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
            $result = curl_exec ($ch);
        }
    } else 
        print "Cannot get RealTime Data\n";

    Print "\n Statistical Data\n";

    if ($tracer->getStatData()) {
        for ($i = 0; $i < count($tracer->statData); $i++) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "http://localhost:8086/write?db=powerwall" );
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            $Item = $tracer->statData[$i];
            $Key_Name = str_replace(" ","-",$tracer->statKey[$i]);
            $Key_Name = 'Stat-' . $Key_Name;
            Print str_pad($i, 2, '0', STR_PAD_LEFT) . " " . $Key_Name . " " . $Item . "\n";
            curl_setopt($ch, CURLOPT_POSTFIELDS, "$Key_Name,unit=statData value=$Item" );
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
            $result = curl_exec ($ch);
        }
    } else 
        print "Cannot get Statistical Data\n";
?>

运行此代码时,我收到错误消息:

  

无法获取实时数据

所以我在这里关注了这个问题: Modbus cant read data from epever tracer 1210a to raspberry

但是我没有这样做,我遇到了几个错误。

然后,我检查了树莓派的内核版本,并显示为

Linux raspberry pi 4.19.57-v7+ #1244 SMP Thu Jul 4 18:45:25 BST 2019   armv7l GNU/Linux

0 个答案:

没有答案