I have created a notification system but i have a problem. I dont know if my (if else) is working beacause he is not writing the text in my DB could anyone help me pls. The code is quiet messy sorry for that.
What the code shoul do.
I have an arduino which has a few sensors. He sends the data in my db. When it gets send it also checks if my remperature is for example too low or too high but my problem is that he isnt checking it so he puts the data in but doesnt write for example optimal or Temperature too low as written in my if else condition.
<?php
include ('connection.php');
$id = "1";
$humidity = $_GET["humidity"]?? "";
$lichtsen = $_GET["lichtsen"]?? "";
$bodenhumidity = $_GET["bodenhumidity"]??"";
$temperature = $_GET["temperature"]??"";
$sql_insert = "INSERT INTO daten (Luftfeuchtigkeit,Lichtverhältnis,Bodenfeuchtigkeit,Temperatur,fi_idStation) VALUES ('$humidity', '$lichtsen', '$bodenhumidity', '$temperature', '$id')";
$sqlsel = mysqli_query($con, "SELECT * from benachrichtigung WHERE fi_idstation = '$id' ");
$rows = mysqli_fetch_array($sqlsel);
$humin = $rows['LuftfeuchtigkeitMIN'];
$humax = $rows['LuftfeuchtigkeitMAX'];
$lichtmin = $rows['LichtverhältnisMIN'];
$lichtmax = $rows['LichtverhältnisMAX'];
$bodenmin = $rows['BodenfeuchtigkeitMIN'];
$bodenmax = $rows['BodenfeuchtigkeitMAX'];
$tempmin = $rows['TemperaturMIN'];
$tempmax = $rows['TemperaturMAX'];
if($humidity <= $humin){
mysqli_query($con, "UPDATE benachrichtigung set Lufttext = Feuchtigkeit zu niedrig where fi_idStation = '$id'");
}
else {
mysqli_query($con, "UPDATE benachrichtigung set Lufttext = optimal where fi_idStation = '$id'");
}
if($humidity >= $humax){
mysqli_query($con, "UPDATE benachrichtigung set Lufttext = Feuchtigkeit zu hoch where fi_idStation = '$id'");
}
else{
mysqli_query($con, "UPDATE benachrichtigung set Lufttext = optimal where fi_idStation = '$id'");
}
if($lichtsen <= $lichtmin){
mysqli_query($con, "UPDATE benachrichtigung set Lichtttext = Es ist zu dunkel where fi_idStation = '$id'");
}
else{
mysqli_query($con, "UPDATE benachrichtigung set Lichtttext = optimal where fi_idStation = '$id'");
}
if($lichtsen >= $lichtmax){
mysqli_query($con, "UPDATE benachrichtigung set Lichtttext = Es ist zu hell where fi_idStation = '$id'");
}
else{
mysqli_query($con, "UPDATE benachrichtigung set Lichtttext = optimal where fi_idStation = '$id'");
}
if($bodenhumidity <= $bodenmin){
mysqli_query($con, "UPDATE benachrichtigung set Feuchttext = Der Boden ist zu trocken where fi_idStation = '$id'");
}
else{
mysqli_query($con, "UPDATE benachrichtigung set Feuchttext = optimal where fi_idStation = '$id'");
}
if($bodenhumidity >= $bodenmax){
mysqli_query($con, "UPDATE benachrichtigung set Feuchttext = Der Boden ist zu feucht where fi_idStation = '$id'");
}
else{
mysqli_query($con, "UPDATE benachrichtigung set Feuchttext = optimal where fi_idStation = '$id'");
}
if($temperature <= $tempmin){
mysqli_query($con, "UPDATE benachrichtigung set Temperaturtext = Es ist zu kalt where fi_idStation = '$id'");
}
else{
mysqli_query($con, "UPDATE benachrichtigung set Temperaturtext = optimal where fi_idStation = '$id'");
}
if($temperature >= $tempmax){
mysqli_query($con, "UPDATE benachrichtigung set Temperaturtext = Es ist zu warm where fi_idStation = '$id'");
}
else{
mysqli_query($con, "UPDATE benachrichtigung set Temperaturtext = optimal where fi_idStation = '$id'");
}
mysqli_close($con);
?>
Aucun commentaire:
Enregistrer un commentaire