updateweatherstation.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. $sql = null;
  3. $con = mysqli_connect("localhost", "root", "R3M0T31", "cropmonitor");
  4. $action=(isset($_GET["action"])) ? $_GET["action"] : "";
  5. $ID=(isset($_GET["ID"])) ? $_GET["ID"] : "";
  6. $PASSWORD=(isset($_GET["PASSWORD"])) ? $_GET["PASSWORD"] : "";
  7. $dateutc=(isset($_GET["dateutc"])) ? $_GET["dateutc"] : "";
  8. $winddir=(isset($_GET["winddir"])) ? $_GET["winddir"] : "";
  9. $windspeedmph=(isset($_GET["windspeedmph"])) ? $_GET["windspeedmph"] : "";
  10. $windgustmph=(isset($_GET["windgustmph"])) ? $_GET["windgustmph"] : "";
  11. $windgustdir=(isset($_GET["windgustdir"])) ? $_GET["windgustdir"] : "";
  12. $windspdmph_avg2m=(isset($_GET["windspdmph_avg2m"])) ? $_GET["windspdmph_avg2m"] : "";
  13. $winddir_avg2m=(isset($_GET["winddir_avg2m"])) ? $_GET["winddir_avg2m"] : "";
  14. $windgustmph_10m=(isset($_GET["windgustmph_10m"])) ? $_GET["windgustmph_10m"] : "";
  15. $windgustdir_10m=(isset($_GET["windgustdir_10m"])) ? $_GET["windgustdir_10m"] : "";
  16. $humidity=(isset($_GET["humidity"])) ? $_GET["humidity"] : "";
  17. $dewptf=(isset($_GET["dewptf"])) ? $_GET["dewptf"] : "";
  18. $tempf=(isset($_GET["tempf"])) ? $_GET["tempf"] : "";
  19. $temp2f=(isset($_GET["temp2f"])) ? $_GET["temp2f"] : "";
  20. $temp3f=(isset($_GET["temp3f"])) ? $_GET["temp3f"] : "";
  21. $temp4f=(isset($_GET["temp4f"])) ? $_GET["temp4f"] : "";
  22. $rainin=(isset($_GET["rainin"])) ? $_GET["rainin"] : "";
  23. $dailyrainin=(isset($_GET["dailyrainin"])) ? $_GET["dailyrainin"] : "";
  24. $baromin=(isset($_GET["baromin"])) ? $_GET["baromin"] : "";
  25. $weather=(isset($_GET["weather"])) ? $_GET["weather"] : "";
  26. $clouds=(isset($_GET["clouds"])) ? $_GET["clouds"] : "";
  27. $soiltempf=(isset($_GET["soiltempf"])) ? $_GET["soiltempf"] : "";
  28. $soiltemp2f=(isset($_GET["soiltemp2f"])) ? $_GET["soiltemp2f"] : "";
  29. $soiltemp3f=(isset($_GET["soiltemp3f"])) ? $_GET["soiltemp3f"] : "";
  30. $soiltemp4f=(isset($_GET["soiltemp4f"])) ? $_GET["soiltemp4f"] : "";
  31. $soilmoisture=(isset($_GET["soilmoisture"])) ? $_GET["soilmoisture"] : "";
  32. $soilmoisture2=(isset($_GET["soilmoisture2"])) ? $_GET["soilmoisture2"] : "";
  33. $soilmoisture3=(isset($_GET["soilmoisture3"])) ? $_GET["soilmoisture3"] : "";
  34. $soilmoisture4=(isset($_GET["soilmoisture4"])) ? $_GET["soilmoisture4"] : "";
  35. $leafwetness=(isset($_GET["leafwetness"])) ? $_GET["leafwetness"] : "";
  36. $leafwetness2=(isset($_GET["leafwetness2"])) ? $_GET["leafwetness2"] : "";
  37. $solarradiation=(isset($_GET["solarradiation"])) ? $_GET["solarradiation"] : "";
  38. $UV=(isset($_GET["UV"])) ? $_GET["UV"] : "";
  39. $visibility=(isset($_GET["visibility"])) ? $_GET["visibility"] : "";
  40. $indoortempf=(isset($_GET["indoortempf"])) ? $_GET["indoortempf"] : "";
  41. $indoorhumidity=(isset($_GET["indoorhumidity"])) ? $_GET["indoorhumidity"] : "";
  42. //add current datetime if not given.
  43. if ($dateutc === "now"){
  44. $dateutc = gmdate("Y-m-d\TH%3Ai%3As\Z");
  45. } else {
  46. $dateutc;
  47. }
  48. // Check connection
  49. if (mysqli_connect_errno())
  50. {
  51. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  52. }
  53. $sql = mysqli_query($con, "INSERT INTO `weather_station`
  54. (
  55. action,
  56. ID,
  57. PASSWORD,
  58. dateutc,
  59. winddir,
  60. windspeedmph,
  61. windgustmph,
  62. windgustdir,
  63. windspdmph_avg2m,
  64. winddir_avg2m,
  65. windgustmph_10m,
  66. windgustdir_10m,
  67. humidity,
  68. dewptf,
  69. tempf,
  70. temp2f,
  71. temp3f,
  72. temp4f,
  73. rainin,
  74. dailyrainin,
  75. baromin,
  76. weather,
  77. clouds,
  78. soiltempf,
  79. soiltemp2f,
  80. soiltemp3f,
  81. soiltemp4f,
  82. soilmoisture,
  83. soilmoisture2,
  84. soilmoisture3,
  85. soilmoisture4,
  86. leafwetness,
  87. leafwetness2,
  88. solarradiation,
  89. UV,
  90. visibility,
  91. indoortempf,
  92. indoorhumidity
  93. )
  94. VALUES
  95. (
  96. '" . $action . "',
  97. '" . $ID . "',
  98. '" . $PASSWORD . "',
  99. '" . $dateutc . "',
  100. '" . $winddir . "',
  101. '" . $windspeedmph . "',
  102. '" . $windgustmph . "',
  103. '" . $windgustdir . "',
  104. '" . $windspdmph_avg2m . "',
  105. '" . $winddir_avg2m . "',
  106. '" . $windgustmph_10m . "',
  107. '" . $windgustdir_10m . "',
  108. '" . $humidity . "',
  109. '" . $dewptf . "',
  110. '" . $tempf . "',
  111. '" . $temp2f . "',
  112. '" . $temp3f . "',
  113. '" . $temp4f . "',
  114. '" . $rainin . "',
  115. '" . $dailyrainin . "',
  116. '" . $baromin . "',
  117. '" . $weather . "',
  118. '" . $clouds . "',
  119. '" . $soiltempf . "',
  120. '" . $soiltemp2f . "',
  121. '" . $soiltemp3f . "',
  122. '" . $soiltemp4f . "',
  123. '" . $soilmoisture . "',
  124. '" . $soilmoisture2 . "',
  125. '" . $soilmoisture3 . "',
  126. '" . $soilmoisture4 . "',
  127. '" . $leafwetness . "',
  128. '" . $leafwetness2 . "',
  129. '" . $solarradiation . "',
  130. '" . $UV . "',
  131. '" . $visibility . "',
  132. '" . $indoortempf . "',
  133. '" . $indoorhumidity . "'
  134. )
  135. ");
  136. if ($sql === TRUE)
  137. {
  138. echo "success"; //CHECKING
  139. } else {
  140. die(mysqli_error($con)); // TODO: better error handling
  141. //echo "User Profile incorrect";
  142. }
  143. mysqli_close($con);