Ankündigung

Einklappen
Keine Ankündigung bisher.

Hilfe bei LBS-Debugging - LBS 19000935

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

    Hilfe bei LBS-Debugging - LBS 19000935

    Hallo Zusammen,

    ich hätte mal eine Frage an die PHP-Experten hier im Forum. Ich habe einen LBS (um)geschrieben um die API von Husqvarna nutzen zu können.
    http://service.knx-user-forum.de/?co...ad&id=19000935

    Jetzt habe ich festgestellt, dass sich nach und nach der RAM füllt und der EXEC-Prozess des LBS dafür verantwortlich ist. Da ich das ganze nur auf Basis eines anderen LBS von adaptiert habe, weiß ich nicht so recht, an welcher stelle es hapert.

    Wer hat eine Idee wodurch der RAM vollläuft?

    Hier der EXEC-Teil:

    PHP-Code:
    <?php
    require (dirname(__FILE__) . "/../../../../main/include/php/incl_lbsexec.php");
    set_time_limit(0);
    //Wichtig! Script soll endlos laufen
    sql_connect();
    logging($id"Husqvarna Automower Connect Daemon started"null5);
    $E logic_getInputs($id);
    $cyclecounter $E[11]['value'];
    // start with max value, so a cycle is immidiatelly triggerd
    while (getSysInfo(1) >= && getLogicElementVar($id99) == 0) {
        
    $E logic_getInputs($id);
        
    $cmd getLogicElementVar($id5);
        
    setLogicElementVar($id50);

        if (
    $cyclecounter $E[11]['value'] && $cmd == 0) {
            
    sleep(1);
            
    $cyclecounter++;
        } else {
            
    $cyclecounter 0;
            
    logging($id"Husqvarna Automower Connect Cycle started"null8);

            if (
    $E) {

                
    $username $E[2]['value'];
                
    $password $E[3]['value'];
                
    $mower_num $E[4]['value'];

                
    error_off();
                
    $session_husqvarna = new husqvarna_api();
                
    $session_husqvarna->login($username$password);
                
    error_on();
                
    logging($id"new husqvarna_api"null8);
                if (
    $session_husqvarna == NULL) {
                    
    logging($id'$session_husqvarna is NULL'null1);
                } else {
                    
    error_off();
                    
    $mowers $session_husqvarna->list_robots();
                    
    $mower NULL;
                    if (
    count($mowers) < $mower_num)
                        
    logging($id"mower not found - looking for mower number $mower_num, total found " count($mowers), null3);
                    else {
                        
    $keys array_keys($mowers);
                        
    $mower $mowers[$keys[$mower_num 1]];
                    }
                    
    error_on();
                    
    logging($id"mower found"null8);
                }

                if (
    is_null($mower)) {
                    
    $cyclecounter $E[11]['value'];
                    
    logging($id"restart cycle"null8);
                    
    sleep(10);
                } else {
                    switch (
    $cmd) {
                        case 
    :
                            
    $session_husqvarna->control($mower->id'START');
                            
    logging($id"Send command START"null5);
                            break;
                        case 
    :
                            
    $session_husqvarna->control($mower->id'STOP');
                            
    logging($id"Send command STOP"null5);
                            break;
                        case 
    :
                            
    $session_husqvarna->control($mower->id'PARK');
                            
    logging($id"Send command PARK"null5);
                            break;
                    }

                    
    $mower_is_valid true;
                    if (
    $cmd 0) {
                        
    logging($id"get mower after command"null5);
                        
    error_off();
                        
    $session_husqvarna = new husqvarna_api();
                        
    $session_husqvarna->login($username$password);
                        
    error_on();
                        if (
    $session_husqvarna == NULL) {
                            
    logging($id"husqvarna is NULL"null1);
                        } else {
                            
    error_off();
                            
    $mowers $session_husqvarna->list_robots();
                            
    $mower NULL;
                            if (
    count($mowers) < $mower_num) {
                                
    logging($id"mower not found - looking for mower number $mower_num, total found " count($mowers), null3);
                            } else {
                                
    $keys array_keys($mowers);
                                
    $mower $mowers[$keys[$mower_num 1]];
                            }
                            
    error_on();
                            
    logging($id"mower found v2"null8);
                        }

                        if (
    is_null($mower)) {
                            
    logging($id"mower is NULL"null1);
                            
    $cyclecounter $E[11]['value'];
                            
    sleep(10);
                            
    $mower_is_valid false;
                        }
                    }

                    if (
    $mower_is_valid) {

                        
    logic_setOutput($id1$mower->name);

                        
    $mowerstate $session_husqvarna->get_status($mower->id);

                        
    logic_setOutput($id2$mowerstate->valueFound);
                        
    logic_setOutput($id3$mowerstate->batteryPercent);
                        
    logic_setOutput($id4$mowerstate->connected);
                        
    logic_setOutput($id5$mowerstate->lastErrorCode);
                        
    logic_setOutput($id6$mowerstate->lastErrorCodeTimestamp);
                        
    logic_setOutput($id7$mowerstate->mowerStatus);
                        
    logic_setOutput($id8$mowerstate->nextStartSource);
                        
    logic_setOutput($id9$mowerstate->nextStartTimestamp);
                        
    logic_setOutput($id10$mowerstate->operatingMode);
                        
    logic_setOutput($id11round($mowerstate->storedTimestamp 10000));
                        
    logic_setOutput($id12json_encode($mowerstate->lastLocations));
                    }

                    
    logging($id"Husqvarna Automower Connect Cycle exit"null8);
                }
            }
        }
    }
    sql_disconnect();
    logging($id"Husqvarna Automower Connect Daemon exit"null5);

    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($id103);
        if (
    is_int($priority) && $priority <= $logLevel && $priority 0) {
            
    $logLevelNames = array('none''emerg''alert''crit''err''warning''notice''info''debug');
            
    $version getLogicElementVar($id100);
            
    $lbsNo getLogicElementVar($id101);
            
    $logName getLogicElementVar($id102) . ' --- LBS' $lbsNo;
            
    strpos($_SERVER['SCRIPT_NAME'], $lbsNo) ? $scriptname 'EXE' $lbsNo $scriptname 'LBS' $lbsNo;
            
    writeToCustomLog($logNamestr_pad($logLevelNames[$logLevel], 7), $scriptname " [v$version]:\t" $msg);

            if (
    is_object($var))
                
    $var get_object_vars($var);
    // transfer object into array
            
    if (is_array($var)) {// print out array
                
    writeToCustomLog($logNamestr_pad($logLevelNames[$logLevel], 7), $scriptname " [v$version]:\t================ ARRAY/OBJECT START ================");
                foreach (
    $var as $index => $line)
                    
    writeToCustomLog($logNamestr_pad($logLevelNames[$logLevel], 7), $scriptname " [v$version]:\t" $index " => " $line);
                
    writeToCustomLog($logNamestr_pad($logLevelNames[$logLevel], 7), $scriptname " [v$version]:\t================ ARRAY/OBJECT END ================");
            }
        }
    }

    class 
    husqvarna_api {

        protected 
    $url_api_im 'https://iam-api.dss.husqvarnagroup.net/api/v3/';
        protected 
    $url_api_track 'https://amc-api.dss.husqvarnagroup.net/v1/';
        protected 
    $username;
        protected 
    $password;
        protected 
    $token;
        protected 
    $provider;

        function 
    login($username$password) {
            
    $this->username $username;
            
    $this->password $password;
            
    $fields["data"]["attributes"]["username"] = $this->username;
            
    $fields["data"]["attributes"]["password"] = $this->password;
            
    $fields["data"]["type"] = "token";
            
    $result $this->post_api("token"$fields);
            if (
    $result !== false) {
                
    $this->token $result->data->id;
                
    $this->provider $result->data->attributes->provider;
                return 
    true;
            }
            return 
    false;
        }

        private function 
    get_headers($fields null) {
            if (isset(
    $this->token)) {
                
    $generique_headers = array('Content-type: application/json''Accept: application/json''Authorization: Bearer ' $this->token'Authorization-Provider: ' $this->provider);
            } else {
                
    $generique_headers = array('Content-type: application/json''Accept: application/json');
            }
            if (isset(
    $fields)) {
                
    $custom_headers = array('Content-Length: ' strlen(json_encode($fields)));
            } else {
                
    $custom_headers = array();
            }
            return 
    array_merge($generique_headers$custom_headers);
        }

        private function 
    post_api($page$fields null) {
            
    $session curl_init();

            
    curl_setopt($sessionCURLOPT_URL$this->url_api_im $page);
            
    curl_setopt($sessionCURLOPT_HTTPHEADER$this->get_headers($fields));
            
    curl_setopt($sessionCURLOPT_POSTtrue);
            
    curl_setopt($sessionCURLOPT_RETURNTRANSFERtrue);
            if (isset(
    $fields)) {
                
    curl_setopt($sessionCURLOPT_POSTFIELDSjson_encode($fields));
            }
            
    $json curl_exec($session);
            
    curl_close($session);
    // throw new Exception(__('La livebox ne repond pas a la demande de cookie.', __FILE__));
            
    return json_decode($json);
        }

        private function 
    get_api($page$fields null) {
            
    $session curl_init();

            
    curl_setopt($sessionCURLOPT_URL$this->url_api_track $page);
            
    curl_setopt($sessionCURLOPT_HTTPHEADER$this->get_headers($fields));
            
    curl_setopt($sessionCURLOPT_RETURNTRANSFERtrue);
            if (isset(
    $fields)) {
                
    curl_setopt($sessionCURLOPT_POSTFIELDSjson_encode($fields));
            }
            
    $json curl_exec($session);
            
    curl_close($session);
    // throw new Exception(__('La livebox ne repond pas a la demande de cookie.', __FILE__));
            
    return json_decode($json);
        }

        private function 
    del_api($page) {
            
    $session curl_init();

            
    curl_setopt($sessionCURLOPT_URL$this->url_api_im $page);
            
    curl_setopt($sessionCURLOPT_HTTPHEADER$this->get_headers());
            
    curl_setopt($sessionCURLOPT_CUSTOMREQUEST"DELETE");
            
    curl_setopt($sessionCURLOPT_RETURNTRANSFERtrue);
            
    $json curl_exec($session);
            
    curl_close($session);
    // throw new Exception(__('La livebox ne repond pas a la demande de cookie.', __FILE__));
            
    return json_decode($json);
        }

        function 
    logout() {
            
    $result $this->del_api("token/" $this->token);
            if (
    $result !== false) {
                unset(
    $this->token);
                unset(
    $this->provider);
                return 
    true;
            }
            return 
    false;
        }

        function 
    list_robots() {
            
    $list_robot = array();
            foreach (
    $this->get_api("mowers") as $robot) {
                
    $list_robot[$robot->id] = $robot;
            }
            return 
    $list_robot;
        }

        function 
    get_status($mover_id) {

            return 
    $this->get_api("mowers/" $mover_id "/status");
        }

        function 
    get_geofence($mover_id) {

            return 
    $this->get_api("mowers/" $mover_id "/geofence");
        }

        function 
    control($mover_id$command) {
            if (
    in_array($command, array('PARK''STOP''START'))) {
                return 
    $this->get_api("mowers/" $mover_id "/control", array("action" => $command));
            }
        }

    }
    Gruß
    Stefan

    #2
    Ist bestimmt curl dran schuld. Such mal im Forum, ich hab irgendwo beschrieben wie man eine aktuellere Version nachinstallieren kann...

    Kommentar

    Lädt...
    X