Ejemplo n.º 1
0
    if ($sensorlist[$i]['type'] == 'power') {
        $info = "";
        $info = $zibase->getSensorInfo($sensorlist[$i]['id']);
        updateProbe($sensorlist[$i], $info, $link, 'conso');
        $query = "CREATE TABLE IF NOT EXISTS `conso_" . $sensorlist[$i]['name'] . "` (`date` datetime NOT NULL, `conso` float NOT NULL, `conso_total` float NOT NULL, PRIMARY KEY (`date`))ENGINE=InnoDB DEFAULT CHARSET=latin1;";
        mysql_query($query, $link);
    }
    $i++;
}
$actionlist = $zibase->getActuatorList($idzibase, $tokenzibase);
$actionnb = count($actionlist);
$i = 0;
while ($i < $actionnb) {
    $info = "";
    $info = $zibase->getSensorInfo($actionlist[$i]['id']);
    updateProbe($actionlist[$i], $info, $link, 'actioneur');
    $query = "CREATE TABLE IF NOT EXISTS `periph_" . $actionlist[$i]['name'] . "` (`date` datetime NOT NULL, `actif` TINYINT(1) NOT NULL, PRIMARY KEY (`date`)) ENGINE=InnoDB DEFAULT CHARSET=latin1";
    mysql_query($query, $link);
    $i++;
}
$actionlist = $zibase->getSensorList($idzibase, $tokenzibase);
$actionnb = count($actionlist);
$i = 0;
while ($i < $actionnb) {
    $info = "";
    $info = $zibase->getSensorInfo($actionlist[$i]['id']);
    updateProbe($actionlist[$i], $info, $link, 'capteur');
    $query = "CREATE TABLE IF NOT EXISTS `periph_" . $actionlist[$i]['name'] . "` (`date` datetime NOT NULL, `actif` TINYINT(1) NOT NULL, PRIMARY KEY (`date`)) ENGINE=InnoDB DEFAULT CHARSET=latin1";
    mysql_query($query, $link);
    $i++;
}
Ejemplo n.º 2
0
/**
 * Cree ou met a jour une sonde
 * @param $pSensorInfo descriptif du capteur venant de la zibase
 * @param $pZibaseInfo l'etat du capteur dans la zibase
 * @param $pLink lien vers la base de donnee
 * @param $pType type du capteur
 */
function updateProbe($pSensorInfo, $pZibaseInfo, $pLink, $pType)
{
    $queryDB = "SELECT * FROM peripheriques WHERE nom = '" . $pSensorInfo['name'] . "'";
    $res_queryDB = mysql_query($queryDB, $pLink);
    if (mysql_numrows($res_queryDB) > 0) {
        // Le capteur existe deja en base
        $data = mysql_fetch_assoc($res_queryDB);
        // Construit la liste des attributs a mettre a jour
        $updatedValues = array();
        if ($pSensorInfo['id'] != $data['id']) {
            array_push($updatedValues, " id = '" . $pSensorInfo['id'] . "' ");
        }
        if ($pSensorInfo['icon'] != $data['logo']) {
            array_push($updatedValues, " logo = '" . $pSensorInfo['icon'] . "' ");
        }
        if (isset($pSensorInfo['protocol'])) {
            if ($pSensorInfo['protocol'] != $data['protocol']) {
                array_push($updatedValues, " protocol = '" . $pSensorInfo['protocol'] . "' ");
            }
        }
        // analyse des attributs lies a la batterie
        $updatedValues = array_merge($updatedValues, updateBattery($data, $pZibaseInfo));
        // Envoie de la requete uniquement si necessaire
        if (count($updatedValues) > 0) {
            $query = "UPDATE peripheriques SET ";
            $query = $query . implode(", ", $updatedValues);
            $query = $query . " WHERE nom = '" . $pSensorInfo['name'] . "'";
            // echo $query . "\n";
            mysql_query($query, $pLink);
        }
    } else {
        // Nouveau capteur
        $query = "INSERT INTO peripheriques (periph, nom, id) VALUES ('" . $pType . "', '" . $pSensorInfo['name'] . "', '" . $pSensorInfo['id'] . "')";
        mysql_query($query, $pLink);
        // Appel a nouveau la fonction pour mettre a jour les autres champs
        updateProbe($pSensorInfo, $pZibaseInfo, $pLink, $pType);
    }
}