Beispiel #1
0
    if ($plug_module_output[$nb] == "") {
        $plug_module_output[$nb] = 1;
    }
    $plug_sensor[$nb] = get_plug_regul_sensor($nb, $main_error);
    $plug_count_sensor[$nb] = count(explode("-", $plug_regul_sensor[$nb]));
}
// Write file plug01 plug02...
if (isset($sd_card) && !empty($sd_card)) {
    if (isset($submit_plugs) && !empty($submit_plugs)) {
        // build conf plug array
        $plugconf = create_plugconf_from_database($GLOBALS['NB_MAX_PLUG'], $main_error);
        if (count($plugconf) > 0) {
            if (!check_sd_card($sd_card)) {
                $main_error[] = __('ERROR_WRITE_SD_PLUGCONF');
            } else {
                if (!write_plugconf($plugconf, $sd_card)) {
                    $main_error[] = __('ERROR_WRITE_SD_PLUGCONF');
                }
            }
        }
        //write pluga file
        if (!check_sd_card($sd_card)) {
            $main_error[] = __('ERROR_WRITE_SD_PLUGA');
        } else {
            if (!write_pluga($sd_card, $main_error)) {
                $main_error[] = __('ERROR_WRITE_SD_PLUGA');
            }
        }
    }
}
// Retrieve plug's informations from the database
Beispiel #2
0
function check_and_update_sd_card($sd_card = "", &$main_info_tab, &$main_error_tab)
{
    // Check and update path
    $logs = "{$sd_card}/logs";
    $cnf = "{$sd_card}/cnf";
    $plg = "{$cnf}/plg";
    $prg = "{$cnf}/prg";
    $bin = "{$sd_card}/bin";
    $recordfrequency = "1";
    $updatefrequency = "1";
    // If we are in cultipi mode, create file systeme structure
    if (!is_dir($sd_card)) {
        mkdir($sd_card);
    }
    if (!is_dir($sd_card . "/bulckyPi")) {
        mkdir($sd_card . "/bulckyPi");
    }
    if (!is_dir($sd_card . "/serverAcqSensorV2")) {
        mkdir($sd_card . "/serverAcqSensorV2");
    }
    if (!is_dir($sd_card . "/serverHisto")) {
        mkdir($sd_card . "/serverHisto");
    }
    if (!is_dir($sd_card . "/serverLog")) {
        mkdir($sd_card . "/serverLog");
    }
    if (!is_dir($sd_card . "/serverPlugUpdate")) {
        mkdir($sd_card . "/serverPlugUpdate");
    }
    if (!is_dir($sd_card . "/serverPlugUpdate/prg")) {
        mkdir($sd_card . "/serverPlugUpdate/prg");
    }
    if (!is_dir($sd_card . "/serverPlugUpdate/plg")) {
        mkdir($sd_card . "/serverPlugUpdate/plg");
    }
    if (!is_dir($sd_card . "/serverMail")) {
        mkdir($sd_card . "/serverMail");
    }
    if (!is_dir($sd_card . "/serverCultibox")) {
        mkdir($sd_card . "/serverCultibox");
    }
    if (!is_dir($sd_card . "/serverSupervision")) {
        mkdir($sd_card . "/serverSupervision");
    }
    if (!is_dir($sd_card . "/serverIrrigation")) {
        mkdir($sd_card . "/serverIrrigation");
    }
    // Create cultipi conf.xml file
    $paramListCultipiConf[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['bulckyPi']);
    create_conf_XML($sd_card . "/bulckyPi/conf.xml", $paramListCultipiConf);
    // Create cultipi start.xml file
    $paramListCultipiStart[] = array('name' => "serverLog", 'waitAfterUS' => "1000", 'pathexe' => "tclsh", 'path' => "./serverLog/serverLog.tcl", 'xmlconf' => "./serverLog/conf.xml");
    $paramListCultipiStart[] = array('name' => "serverAcqSensorV2", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverAcqSensorV2/serverAcqSensorV2.tcl", 'xmlconf' => "./serverAcqSensorV2/conf.xml");
    $paramListCultipiStart[] = array('name' => "serverPlugUpdate", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverPlugUpdate/serverPlugUpdate.tcl", 'xmlconf' => "./serverPlugUpdate/conf.xml");
    $paramListCultipiStart[] = array('name' => "serverCultibox", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverCultibox/serverCultibox.tcl", 'xmlconf' => "./serverCultibox/conf.xml");
    $paramListCultipiStart[] = array('name' => "serverMail", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverMail/serverMail.tcl", 'xmlconf' => "./serverMail/conf.xml");
    $paramListCultipiStart[] = array('name' => "serverSupervision", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverSupervision/serverSupervision.tcl", 'xmlconf' => "./serverSupervision/conf.xml");
    // If there are some plugins to add in start.xml , add it
    foreach ($GLOBALS['PLUGIN'] as $plugin) {
        // Check if function exists
        if (function_exists($plugin . '\\addInStartXMLCultiCore')) {
            // Add parameters
            $paramListCultipiStart[] = call_user_func($plugin . '\\addInStartXMLCultiCore');
        }
    }
    $paramListCultipiStart[] = array('name' => "serverHisto", 'waitAfterUS' => "1000", 'pathexe' => "tclsh", 'path' => "./serverHisto/serverHisto.tcl", 'xmlconf' => "./serverHisto/conf.xml");
    create_conf_XML($sd_card . "/bulckyPi/start.xml", $paramListCultipiStart, "starts");
    // Server acq sensor
    sensors\serverAcqSensorV2_createXMLConf();
    // Server plug update
    $paramListServerPlugUpdate[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['serverPlugUpdate']);
    $paramListServerPlugUpdate[] = array("name" => "wireless_freq_plug_update", "value" => "{$updatefrequency}");
    $paramListServerPlugUpdate[] = array("name" => "pwm_output", "value" => $GLOBALS['PWM_OUTPUT']);
    // Add network slave
    //  <item name="module_CULTIPI,ip,0" ip="192.168.1.10" />
    if ($GLOBALS['CULTIPI']['USE_REMOTE_SLAVE'] == 1) {
        for ($index = 0; $index < $GLOBALS['CULTIPI']['REMOTE_NB_SLAVE']; $index++) {
            $paramListServerPlugUpdate[] = array("name" => "module_CULTIPI,ip," . $index, "ip" => $GLOBALS['CULTIPI']['REMOTE_SLAVE']["IP_" . $index]);
        }
    }
    create_conf_XML($sd_card . "/serverPlugUpdate/conf.xml", $paramListServerPlugUpdate);
    // Server histo
    $paramListServerHisto[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['serverHisto']);
    $paramListServerHisto[] = array("name" => "logPeriode", "valInSec" => $recordfrequency * 60);
    $paramListServerHisto[] = array("name" => "pathMySQL", "path" => "/usr/bin/mysql");
    create_conf_XML($sd_card . "/serverHisto/conf.xml", $paramListServerHisto);
    // Server log
    $paramListServerLog[] = array("name" => "logPath", "logfile" => "/var/log/cultipi");
    $paramListServerLog[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['serverLog']);
    create_conf_XML($sd_card . "/serverLog/conf.xml", $paramListServerLog);
    // Create conf for mail
    // Made when user save it conf
    // Create conf for supervision
    $paramListSupervision[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['serverSupervision']);
    $paramListSupervision[] = array("name" => "nbProcess", "value" => 0);
    create_conf_XML($sd_card . "/serverSupervision/conf.xml", $paramListSupervision);
    // For each process create an XML
    /*
    $paramListSupervisionProcess[] = array (
        "name" => "action",
        "level" => "checkPing"
    );    
    $paramListSupervisionProcess[] = array (
        "name" => "nbIP",
        "level" => "1"
    );
    $paramListSupervisionProcess[] = array (
        "name" => "IP,0",
        "level" => "8.8.8.8"
    );
    $paramListSupervisionProcess[] = array (
        "name" => "timeMax",
        "level" => "30"
    ); 
    $paramListSupervisionProcess[] = array (
        "name" => "error,action",
        "level" => "sendMail info@bulck.fr"
    );
    create_conf_XML($sd_card . "/serverSupervision/process_0.xml" , $paramListSupervisionProcess);
    */
    $paramListCultibox[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['serverCultibox']);
    $paramListCultibox[] = array("name" => "updateFreq", "level" => "6");
    create_conf_XML($sd_card . "/serverCultibox/conf.xml", $paramListCultibox);
    configuration\serverEmail_createXMLConf();
    $program = "";
    $conf_uptodate = true;
    $program_index = array();
    programs\get_program_index_info($program_index);
    $confsave_prog = true;
    foreach ($program_index as $key => $value) {
        // Read from database program
        $program = create_program_from_database($main_error, $value['program_idx']);
        $fileName = $sd_card . "/serverPlugUpdate/prg/" . "plu" . $value['plugv_filename'];
        if (!compare_program($program, $fileName)) {
            $conf_uptodate = false;
            if (!save_program_on_sd($fileName, $program)) {
                $confsave_prog = false;
            }
        }
    }
    //For plugv
    $program = create_program_from_database($main_error);
    $fileName = $sd_card . "/serverPlugUpdate/prg/" . "plugv";
    if (!save_program_on_sd($fileName, $program)) {
        $main_error_tab[] = __('ERROR_WRITE_PROGRAM');
        return ERROR_WRITE_PROGRAM;
    }
    if (!write_pluga($sd_card, $main_error)) {
        $main_error_tab[] = __('ERROR_COPY_PLUGA');
        return ERROR_COPY_PLUGA;
    }
    $plugconf = create_plugconf_from_database($GLOBALS['NB_MAX_PLUG'], $main_error);
    if (count($plugconf) > 0) {
        if (!write_plugconf($plugconf, $sd_card)) {
            $main_error_tab[] = __('ERROR_COPY_PLUG_CONF');
            return ERROR_COPY_PLUG_CONF;
        }
    }
    $data = array();
    calendar\read_event_from_db($data);
    $plgidx = create_plgidx($data);
    if (count($plgidx) > 0) {
        if (!write_plgidx($plgidx, $sd_card)) {
            $main_error_tab[] = __('ERROR_COPY_PLGIDX');
            return ERROR_COPY_PLGIDX;
        }
    } else {
        if (!check_and_copy_plgidx($sd_card)) {
            $main_error_tab[] = __('ERROR_COPY_TPL');
            return ERROR_COPY_TPL;
        }
    }
    if (!$conf_uptodate) {
        // Infor user that programms have been updated
        $main_info_tab[] = __('UPDATED_PROGRAM');
        return 0;
    }
    // Conf was up to date
    return 1;
}