Commit 36ef1f60db2b7f263ba4d4bd2989dc64be968a38

Authored by Guillaume
1 parent 1334aed2

MAJ site

site/accesBase.php
... ... @@ -207,7 +207,7 @@
207 207 return (int)$tab['version'];
208 208 }
209 209  
210   - function add($nom, $type, $raspberry, $numero, $unite)
  210 + function add($nom, $type, $raspberry, $numero, $unite, $version)
211 211 {
212 212 $db = connexion();
213 213 $query = "SELECT * FROM capteurs WHERE nom = '$nom' OR (raspberry = '$raspberry' AND numero = '$numero')";
... ... @@ -217,7 +217,7 @@
217 217 }
218 218 else
219 219 {
220   - $query = "INSERT INTO capteurs VALUES($numero, '$nom', '$raspberry', '$type', 0, '$unite')";
  220 + $query = "INSERT INTO capteurs VALUES($numero, '$nom', '$raspberry', '$type', 0, '$unite', $version)";
221 221 $result = pg_query($db, $query) or die("La requête a echoué : ".pg_last_error());
222 222 if (pg_affected_rows($result)!=0){
223 223 return True;
... ...
site/add.php
... ... @@ -20,7 +20,7 @@ session_start();
20 20 <br/>
21 21 <h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fas fa-history"></i> Historique</h1>
22 22 <?php
23   - if(add($_POST['nom'], $_POST['type'], $_POST['raspberry'], $_POST['numero'], $_POST['unite']))
  23 + if(add($_POST['nom'], $_POST['type'], $_POST['raspberry'], $_POST['numero'], $_POST['unite'], $_POST['version']))
24 24 {
25 25 ?>
26 26 <div class="alert alert-success" role="alert">
... ...
site/addSensor.php
... ... @@ -29,7 +29,18 @@
29 29 <td><label for="unite">Unite de mesure : </label></td>
30 30 <td><input type="text" id="unite" name="unite" /></td>
31 31 </tr>
32   -
  32 +
  33 + <tr>
  34 + <td><label for="version">Version : </lavel></td>
  35 + <td>
  36 + <select id="version" name="version">
  37 + <option value=0 selected>Arduino USB</option>
  38 + <option value=1>Arduino SPI</option>
  39 + <option value=2>Nucléo USB</option>
  40 + </select>
  41 + </td>
  42 + </tr>
  43 +
33 44 <tr>
34 45 <td></td>
35 46 <td><input type="submit" class="btn btn-dark" value="Ajouter le capteur"/></td>
... ...
site/ansibleSensor.php 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +$ini = "";
  2 +$arduino_simple = "[Arduino_init]\r\n";
  3 +$arduino_spi = "[Arduino_spi_init]\r\n";
  4 +$nucleo = "[Nucleo_init]\r\n";
  5 +
  6 +
  7 +
  8 +foreach($_POST['sensor'] as $sensor => $value)
  9 +{
  10 + $version = -1;
  11 + $val = explode(":", $value);
  12 +
  13 + if(count($types)<>0 && !in_array($val[2], $types)) {$err = true;}
  14 + else {$types[] = $val[2];}
  15 +
  16 + $version = getSensorVersion($val[0], $val[1]);
  17 + if($version == 0)
  18 + {
  19 + $a_simple = true;
  20 + $arduino_simple = $arduino_simple.$val[0]." capteur=".$val[1]."\n";
  21 + }
  22 + elseif($version == 1)
  23 + {
  24 + $a_spi = true;
  25 + $arduino_spi = $arduino_spi.$val[0]." capteur=".$val[1]."\n";
  26 + }
  27 + elseif($version == 2)
  28 + {
  29 + $n = true;
  30 + $nucleo = $nucleo.$val[0]." capteur=".$val[1]."\n";
  31 + }
  32 +}
  33 +
  34 +if($a_simple) {$ini = $ini.$arduino_simple."\n";}
  35 +if($a_spi) {$ini = $ini.$arduino_spi."\n";}
  36 +if($n) {$ini = $ini.$nucleo."\n";}
  37 +
  38 +if(!$err)
  39 +{
  40 + file_put_contents('upload/inventaire.ini', $ini);
  41 +}
0 42 \ No newline at end of file
... ...