Ankündigung

Einklappen
Keine Ankündigung bisher.

EDOMI - LBS - Diskussion

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • gulp2k
    antwortet
    Nabend
    Bin gerade dabei meinen nächsten LBS zu bauen der meine Wärmepumpe abfragt.
    Soweit so gut, es läuft in einem reinen PHP Script.

    gaert
    Jetzt stellt sich mir die Frage zur Einbindung in Edomi.
    Ich kann theroretisch ca 100 Werte abfragen und Ausgeben.
    Selektiv per EingangX=1 einen entsprechenden Wert an AusgangX auszugeben macht glaube ich wenig Sinn.
    Die Performance der Abfrage selbst ist auch kein Problem da ich alle Werte in einem Request auf einmal Abfragen kann.

    Mir stellt sich die Fragen ob es Sinnvoll ist pauschal 100 Ausgänge jedesmal zu befüllen oder die Werte in einem String("Wert1;Wert2;Wert3;use") in einem Ausgang auszugeben.?!

    Ich tendiere zu ersterm da man dann leichter die Werte die man wirklich braucht abgreifen kann ohne eine Kaskade von anderen LBS um das ganze zu parsen.

    Was denkt die Mehrheit was besser ist?

    Gruß
    Michael

    Einen Kommentar schreiben:


  • gulp2k
    antwortet
    Doppelpost
    Zuletzt geändert von gulp2k; 07.03.2017, 21:36.

    Einen Kommentar schreiben:


  • gulp2k
    antwortet
    Zitat von wintermute Beitrag anzeigen
    Ich habe benoetigte Libs sofern es ging immer direkt mit dem Baustein-Code verkuppelt (und dann bei Bedarf angepasst). Ich finde die Notwendigkeit etwas nachinstallieren zu muessen extrem unkomfortabel und meide unter allen moeglichen Umstaenden Bausteine die nicht "einfach-so" funktionieren sondern zusaetzliche, womoeglich sogar manuelle (ausserhalb von yum), Paketinstallationen erfordern.
    War das "Verkuppeln" aus irgendwelchen Gruenden nicht moeglich, habe ich den Baustein anders konzeptioniert oder einfach verworfen.
    Das ist aber nur "meine Meinung"
    Ich bin eigendlich voll bei dir ABER irgendwo einen 2. "Server" laufefn zu lassen der Werte in Edomi reinschießt wegen einer externen lib halte ich auch nicht für besser.
    Aber ihr habt beide Rechte damit das es nicht ideal ist. Deswegen wollte ich auch erst mal Fragen ob es vielleicht einen besseren Weg gibt den ich nur noch nicht gefunde habe... bin ja erst seit ca 2 Woche bei Edomi

    Ich denke ich werde jetzt erstmal wie André vorgeschlagen hat vorgehen.

    Btw, vielleicht bin ich auch nur zu doof aber wo kann ich meine Signatur ändern?
    Im Profil kann ich nur den Status ändern aber das ist ja was anderes?!

    Grüße
    Michael

    Einen Kommentar schreiben:


  • wintermute
    antwortet
    Ich habe benoetigte Libs sofern es ging immer direkt mit dem Baustein-Code verkuppelt (und dann bei Bedarf angepasst). Ich finde die Notwendigkeit etwas nachinstallieren zu muessen extrem unkomfortabel und meide unter allen moeglichen Umstaenden Bausteine die nicht "einfach-so" funktionieren sondern zusaetzliche, womoeglich sogar manuelle (ausserhalb von yum), Paketinstallationen erfordern.
    War das "Verkuppeln" aus irgendwelchen Gruenden nicht moeglich, habe ich den Baustein anders konzeptioniert oder einfach verworfen.
    Das ist aber nur "meine Meinung"

    Einen Kommentar schreiben:


  • jonofe
    antwortet
    Ich habe bislang zwei Varianten verwendet
    1. Libs mit ins ZIP und in der Hilfe beschreiben was wo und wie installiert werden muss.
    2. Wenn die libs z.B. auf github liegen, dann kann man auch ein Installskript im ZIP mitliefern und in der Hilfe beschreiben, wo man dieses hinkopieren muss und wie man es starten muss. Dieses Skript sollte dann die komplette Installation machen.
    Hoffe das hilft.

    Einen Kommentar schreiben:


  • gulp2k
    antwortet
    Bin mit der ersten Version soweit mal fertig.
    Was ist der beste weg abhängige Libs mit zu geben?
    Hänge ich die als Zip mit dran und hoffe das jeder weiß wohin man die entpackt oder gibt es einen besseren weg?

    Einen Kommentar schreiben:


  • gulp2k
    antwortet
    Könnte ich das hier mit mal als Standard vorschlagen?
    Finde das nämlich so recht sinnig und es muss ja nicht jeder das Rad ständig neu erfinden!

    Ich fände das währe eine super Ergänzung im Wiki für Devs

    Einen Kommentar schreiben:


  • jonofe
    antwortet
    Zitat von gulp2k Beitrag anzeigen

    2. Frage.

    Gibt es irgendeinen Standard für Variabeln 100-106? Ich hab die jetzt in mehren LBS gesehen aber nirgends wo das irgendwie "Offiziel" dokumentiert ist.
    Nein gibt es nicht. Es ist "mein" Standard für die von mir entwickelten LBS. Dazu gehören die Error Handler Funktionen, die Logging Funktionen und die Variablen 100-106.

    Einen Kommentar schreiben:


  • gulp2k
    antwortet
    Update:

    Hab das Problem "gelöst"...
    Es lag an dem Custom Error Handler denn ich geborgt hatte, der hat wohl die Warnungen die normalerweise unterdrückt werden wieder angezeigt.
    Ich werde jetzt bis auf weiteres die Files die Warnungen erzeugen im Error Handler Filtern.

    Oder gibt es irgendwelche Einwände?

    2. Frage.

    Gibt es irgendeinen Standard für Variabeln 100-106? Ich hab die jetzt in mehren LBS gesehen aber nirgends wo das irgendwie "Offiziel" dokumentiert ist.

    Einen Kommentar schreiben:


  • gulp2k
    antwortet
    Hab in den anderen LBS keinen großen unterschied gefunden.
    Ich vermute es hat was mit
    PHP-Code:
    PhpType::bytes2signedInt($recData
    zu tun.
    Das ist wohl eine statische Methode in der lib und irgendwie passt der Kontext nicht...
    Kenn mich aber mit PHP zu wenig aus um das wirklich nachvollziehen zu können

    Einen Kommentar schreiben:


  • gulp2k
    antwortet
    Hier der Code, bitte nicht hauen, ist noch nicht fertig und das Logging hab ich schamlos vom UDP Receiver geklaut

    PHP-Code:
    ###[DEF]###
    [name =     ModBus Master ]
    [e#1 trigger=         Autostart #init=1]
    [e#2 important=         Host #init=e3dc.knx.pattison.de] ModBus Slave IP or Host
    [e#3 optional=         Port #init=502] Modbus Port
    [e#4 =         Mode #init=1] 0 UDP, 1 TCP
    [e#5 optional=         SlaveID #init=0] not used
    [e#6 =         Logging #init=8]
    [e#7 =        Loop #init=0]
    [e#8 =        Delay #init=1000]
    [e#9 important=         Address1 #init=40072]
    [e#10 important=     Length1 #init=1] #Word size=2bytes
    [e#11 important=     Type1 #init=0] 0=Int, 1=uInt, 2=String
    [e#12 important=        Function1 #init=3]
    [e#13 option=Address2]
    [e#14 option=Length2]
    [e#15 option=Type2]
    [e#16 option=Function2 #init=3]
    [a#1 = Value1]
    [a#2 = Value2]

    [v#1             = 0 ]
    [v#2             = 0 ]
    [v#3             = 0 ]
    [v#100           = 0.1 ]
    [v#101           = 19001030 ]
    [v#102           = ModBusMaster ]
    [v#103           = 0 ]
    [v#104           = 0 ]
    [v#105           = 0 ]
    ###[/DEF]###


    ###[HELP]###
    E1: Autostart, Default=1
    E2: Host or IP of Modbus Slave
    E3: Port (Currently not used)
    E4: Mode: 0=UDP, 1=TCP
    E5: Modbus Slave ID, Default=0
    E6: Logging, 0=none, 8=Debuggen
    E7: Loop, Default=0, 0=False=Run once,1=True=Run till Edomi END
    E8: Delay between runs in ms, Default=1000 (1sec)
    E9: Address of 1 Datapoint
    E10: Lenght to read 1, Default=1 (1=1 Dword=2 Bytes)
    E11: Type of Data returned 1, 0=Int, 1=uInt, 2=Float, 3=Byte, 4=Bit, 5=String
    E12: Function to use (Currently only FC3 Read_Multiple_Registers is implemented)
    E13: Optional (see E9)
    E14: Optional (see E10)
    E15: Optional (see E11)
    E16: Optional (see E12)

    V1: Indicator whether daemon is running
    V2: PID of EXEC Daemon
    V3: Array of used Inputs
    V100: Version
    V101: LBS Number
    V102: Log file name
    V103: Log level
    V104: One log file per LBS instance
    V105: log ID in each log entry

    ###[/HELP]###

    ###[LBS]###
    <?
    function LB_LBSID_logging($id, $msg, $var = NULL, $priority = 8)
    {
        $E = getLogicEingangDataAll($id);
        $logLevel = getLogicElementVar($id, 103);
        if (is_int($priority) && $priority <= $logLevel && $priority > 0) {
            $logLevelNames = array(
                'none',
                'emerg',
                'alert',
                'crit',
                'err',
                'warning',
                'notice',
                'info',
                'debug'
            );
            $version = getLogicElementVar($id, 100);
            $lbsNo = getLogicElementVar($id, 101);
            $logName = getLogicElementVar($id, 102) . "-LBS$lbsNo";
            $logName = preg_replace('/ /', '', $logName);
            if (logic_getVar($id, 104))
                $logName .= "-$id";
            if (logic_getVar($id, 105) == 1)
                $msg .= " ($id)";
            strpos($_SERVER['SCRIPT_NAME'], $lbsNo) ? $scriptname = 'EXE' . $lbsNo : $scriptname = 'LBS' . $lbsNo;
            writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t" . $msg);
            if (isset($var)) {
                writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t================ ARRAY/OBJECT START ================");
                writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t" . json_encode($var));
                writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t================ ARRAY/OBJECT  END  ================");
            }
        }
    }

    function LB_LBSID($id) {
      if ($E=getLogicEingangDataAll($id)) {
          setLogicElementVar($id, 103, $E[6]['value']); // set loglevel to #VAR 103
            LB_LBSID_logging($id, 'LBS started');
            $activeInputs=array();
            if ($E[9]['value']!=""){
                $activeInputs[]=9;
            }
            if ($E[13]['value']!=""){
                $activeInputs[]=13;
            }
            setLogicElementVar($id,3,implode(";",$activeInputs));     
       if (getLogicElementVar($id,1)!=1) {
        setLogicElementVar($id,1,1);                      //setzt V1=1, um einen mehrfachen Start des EXEC-Scripts zu verhindern
        callLogicFunctionExec(LBSID,$id);                 //EXEC-Script starten (garantiert nur einmalig)
      }
       LB_LBSID_logging($id, 'LBS ended');
     }
    }
    ?>
    ###[/LBS]###
    ###[EXEC]###
    <?
    require(dirname(__FILE__)."/../../../../main/include/php/incl_lbsexec.php");
    require_once(dirname(__FILE__)."/../../../../main/include/php/ModbusMaster.php");
    set_time_limit(0);                                       //Wichtig! Script soll endlos laufen
    sql_connect();
    logging($id, "START ModbusMaster Daemon");
    setLogicElementVar($id, 2, getmypid());
    //
    // error_off() : switch off error reporting
    // error_on() : switch on error reporting
    //
    function myErrorHandler($errno, $errstr, $errfile, $errline)
    {
        global $id;
        logging($id, "File: $errfile | Error: $errno | Line: $errline | $errstr ");
    }

    function error_off()
    {
        $error_handler = set_error_handler("myErrorHandler");
        error_reporting(0);
    }

    function error_on()
    {
        restore_error_handler();
        error_reporting(E_ALL);
    }

    function logging($id, $msg, $var = NULL, $priority = 8)
    {
        //$E = getLogicEingangDataAll($id);
        $logLevel = getLogicElementVar($id, 103);
        if (is_int($priority) && $priority <= $logLevel && $priority > 0) {
            $logLevelNames = array(
                'none',
                'emerg',
                'alert',
                'crit',
                'err',
                'warning',
                'notice',
                'info',
                'debug'
            );
            $version = getLogicElementVar($id, 100);
            $lbsNo = getLogicElementVar($id, 101);
            $logName = getLogicElementVar($id, 102) . "-LBS$lbsNo";
            $logName = preg_replace('/ /', '_', $logName);
            if (logic_getVar($id, 104) == 1)
                $logName .= "-$id";
            if (logic_getVar($id, 105) == 1)
                $msg .= " ($id)";
            strpos($_SERVER['SCRIPT_NAME'], $lbsNo) ? $scriptname = 'EXE' . $lbsNo : $scriptname = 'LBS' . $lbsNo;
            writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t" . $msg);
            if (isset($var)) {
                writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t================ ARRAY/OBJECT START ================");
                writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t" . json_encode($var));
                writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t================ ARRAY/OBJECT  END  ================");
            }
        }
    }


    date_default_timezone_set('Europe/Berlin');

    error_off();
    //writeToTraceLog(0,true,'ModBus-Script gestartet');        //Demonstration: TraceLog zum Debuggen nutzen
    //while (getSysInfo(1)>=1) {
      //eigener Programm-Code...
    //  usleep(1000*10);                                      //z.B. 10ms warten - wichtig, um die CPU-Last zu begrenzen!
    //}


    if ($E=getLogicEingangDataAll($id)) {

        $v3=getLogicElementVar($id, 3);
    $inputs=explode(";",$v3);
    $querys=array();
    for($i = 0, $groesse = count($inputs); $i < $groesse; ++$i) {
       $query=Array('address'=>$E[$inputs[$i]],'length'=>$E[$inputs[$i]+1],'type'=>$E[$inputs[$i]+2],'function'=>$E[$inputs[$i]+3]);
       logging($id,"Query:" . $query);
       $querys[]=$query;
    }
    logging($id,"Querys:" . $querys);


        // Create Modbus object

        $modbus = new ModbusMaster($E[2]['value'], ($E[4]['value']==0 ? "UDP" : "TCP"));

        try {
            // FC 3
            $recData = $modbus->readMultipleRegisters(0, $E[9]['value'], $E[10]['value']);
        }
        catch (Exception $e) {
            // Print error information if any
            logging($id, "Modbus Error: ", $modbus);
            logging($id, "Modbus Error: ", $e);
            exit;
        }
        // Print status information
        logging($id,"Status:" . $modbus);

        // Print read data
        logging($id, "Data:" . PhpType::bytes2signedInt($recData));
        setLogicLinkAusgang($id,1,PhpType::bytes2signedInt($recData));

    }

    logging($id, "STOP ModbusMaster Daemon");
    error_on();
    sql_disconnect();
    ?>
    ###[/EXEC]###
    Hier das Log:
    2017-02-27 17:10:51 594310 26721 debug LBS19001030 [v0.1]: LBS started
    2017-02-27 17:10:51 596863 26721 debug LBS19001030 [v0.1]: LBS ended
    2017-02-27 17:10:51 617880 26730 debug EXE19001030 [v0.1]: START ModbusMaster Daemon
    2017-02-27 17:10:51 618695 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/www/data/liveproject/lbs/EXE19001030.php | Error: 8 | Line: 77 | Undefined variable: E
    2017-02-27 17:10:51 618917 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/www/data/liveproject/lbs/EXE19001030.php | Error: 8 | Line: 77 | Undefined variable: E
    2017-02-27 17:10:51 619091 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/www/data/liveproject/lbs/EXE19001030.php | Error: 8 | Line: 77 | Undefined variable: E
    2017-02-27 17:10:51 619272 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/www/data/liveproject/lbs/EXE19001030.php | Error: 8 | Line: 77 | Undefined variable: E
    2017-02-27 17:10:51 619469 26730 debug EXE19001030 [v0.1]: Query:Array
    2017-02-27 17:10:51 619637 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/www/data/liveproject/lbs/EXE19001030.php | Error: 8 | Line: 77 | Undefined variable: E
    2017-02-27 17:10:51 619791 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/www/data/liveproject/lbs/EXE19001030.php | Error: 8 | Line: 77 | Undefined variable: E
    2017-02-27 17:10:51 619977 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/www/data/liveproject/lbs/EXE19001030.php | Error: 8 | Line: 77 | Undefined variable: E
    2017-02-27 17:10:51 620132 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/www/data/liveproject/lbs/EXE19001030.php | Error: 8 | Line: 77 | Undefined variable: E
    2017-02-27 17:10:51 620281 26730 debug EXE19001030 [v0.1]: Query:Array
    2017-02-27 17:10:51 620452 26730 debug EXE19001030 [v0.1]: Querys:Array
    2017-02-27 17:10:51 623610 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/ModbusMaster.php | Error: 2048 | Line: 477 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 623804 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/ModbusMaster.php | Error: 2048 | Line: 479 | Non-static method IecType::iecINT() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 623994 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/IecType.php | Error: 2048 | Line: 51 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 624159 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/IecType.php | Error: 2048 | Line: 52 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 624336 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/ModbusMaster.php | Error: 2048 | Line: 480 | Non-static method IecType::iecINT() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 624515 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/IecType.php | Error: 2048 | Line: 51 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 624680 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/IecType.php | Error: 2048 | Line: 52 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 624861 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/ModbusMaster.php | Error: 2048 | Line: 484 | Non-static method IecType::iecINT() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 625044 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/IecType.php | Error: 2048 | Line: 51 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 625214 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/IecType.php | Error: 2048 | Line: 52 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 625392 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/ModbusMaster.php | Error: 2048 | Line: 485 | Non-static method IecType::iecINT() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 625562 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/IecType.php | Error: 2048 | Line: 51 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 625731 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/IecType.php | Error: 2048 | Line: 52 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 625905 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/ModbusMaster.php | Error: 2048 | Line: 486 | Non-static method IecType::iecINT() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 626077 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/IecType.php | Error: 2048 | Line: 51 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 626228 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/IecType.php | Error: 2048 | Line: 52 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 626393 26730 debug EXE19001030 [v0.1]: File: /usr/local/edomi/main/include/php/ModbusMaster.php | Error: 2048 | Line: 487 | Non-static method IecType::iecBYTE() should not be called statically, assuming $this from incompatible context
    2017-02-27 17:10:51 629018 26730 debug EXE19001030 [v0.1]: Status:<pre>readMultipleRegisters: START[LF]Connected[LF]Packet: bd7d0000000600039c880001[LF]Send[LF]Wait data ... [LF]Data received[LF]Packet: bd7d000000050003020e39[LF]Modbus response error code: NOERROR[LF]Disconnected[LF]readMultipleRegisters: DONE[LF]</pre>
    2017-02-27 17:10:51 629250 26730 debug EXE19001030 [v0.1]: Data:3641
    2017-02-27 17:10:51 629554 26730 debug EXE19001030 [v0.1]: STOP ModbusMaster Daemon

    Einen Kommentar schreiben:


  • jonofe
    antwortet
    Zitat von gulp2k Beitrag anzeigen
    Glaube ich nicht wenn ich das gleiche in ein php script auf dem Edomi server packe und per php -f modbus.php aufrufe geht es ohne Fehler durch.
    Dann lad doch mal das LBS Skript hoch zusammen mit dem Fehlerlog.

    Einen Kommentar schreiben:


  • WagoKlemme
    antwortet
    Es gibt Bausteine von mir für Modbus 19000041 und 19000048, allerdings ungepflegt, da ich komplett auf KNX gewechselt bin. Aber vielleicht als Vergleich ...

    Einen Kommentar schreiben:


  • gulp2k
    antwortet
    Glaube ich nicht wenn ich das gleiche in ein php script auf dem Edomi server packe und per php -f modbus.php aufrufe geht es ohne Fehler durch.

    Einen Kommentar schreiben:


  • jonofe
    antwortet
    Ich vermute eher, dass die Library eine höhere PHP Version als 5.3.3 voraussetzt. Kann das sein?

    Einen Kommentar schreiben:

Lädt...
X