3 ###########################################################################################
4 # Set the username and password to use. The read_user should only be allowed to read data #
5 # from the database, while the write_user will probably need to read and write. #
6 ###########################################################################################
7 include
'/usr/local/share/brigadoon/apache/db_passwords.php';
22 function DbConnect( $DbFunction, $ConnectionType =
'mysqli' )
32 $db =
'WeatherStation';
36 if ( $ConnectionType ==
'mysqli' )
41 elseif ( $ConnectionType ==
'pdo' )
50 header(
"HTTP/1.0 400 Unable to Open Database");
57 header(
"HTTP/1.0 400 Unrecognised Driver Type");
72 ##################################################################################################################
73 # Used to Determine the Parameters being Passed to This Program #
74 ##################################################################################################################
75 $parameters = json_encode($_POST);
77 ###############################
78 # Used for Debugging Purposes #
79 ###############################
82 ##################################################################################################################
83 # Read the Weather Station's Username and Password, the action to be carried out and the Date of the Observation #
84 # as these are mandatory parameters required to save the readings. This not determine if this is a valid message #
85 # but it does determine if it at least has the minimum parameters required. #
86 ##################################################################################################################
87 $readings = json_decode( $parameters,
true );
89 if ( $readings[
'PASSKEY'] )
91 $passkey = $readings[
'PASSKEY'];
94 if ( $readings[
'dateutc'] )
96 $date_utc = $readings[
'dateutc'];
99 ###################################################################
100 # If the Two (2) Mandatory Fields Are There, Process the Reading #
101 ###################################################################
102 if ( $passkey && $date_utc )
105 ##########################################################
106 # Create a Database Connection #
107 ##########################################################
110 $connection =
DbConnect(
'WRITE',
'pdo' );
113 ##########################################################
114 # Extract Readings from the Parameters passed in POST #
115 ##########################################################
116 if ( $readings[
'stationtype'] !=
'' )
118 $software_type = $readings[
'stationtype'];
121 if ( $readings[
'model'] !=
'' )
123 $model = $readings[
'model'];
126 if ( $readings[
'freq'] !=
'' )
128 $freq = $readings[
'freq'];
131 ##########################################################
132 # Extract the Indoor Temperature #
133 ##########################################################
134 if ( $readings[
'tempinf'] )
136 $indoor_temp = ($readings[
'tempinf'] - 32.0) * 0.555555556;
139 ##########################################################
140 # Extract the Outdoor Temperature #
141 ##########################################################
142 if ($readings[
'tempf'] )
144 $outdoor_temp = ($readings[
'tempf'] - 32.0) * 0.555555556;
147 ##########################################################
148 # Extract the Dew Point Temperature #
149 ##########################################################
150 if ($readings[
'dewptf'] )
152 $dew_point = ($readings[
'dewptf'] - 32.0) * 0.555555556;
155 ##########################################################
156 # Extract the Wind Chill Temperature #
157 ##########################################################
158 if ( $readings[
'windchillf'] )
160 $windchill = ($readings[
'windchillf'] - 32.0) * 0.555555556;
163 ##########################################################
164 # Extract the Indoor Relative Humidity #
165 ##########################################################
166 if ( $readings[
'humidityin'] )
168 $indoor_humidity = $readings[
'humidityin'];
171 ##########################################################
172 # Extract the Outdoor Relative Humidity #
173 ##########################################################
174 if ( $readings[
'humidity'] )
176 $outdoor_humidity = $readings[
'humidity'];
179 ##########################################################
180 # Extract the Wind Speed #
181 ##########################################################
182 if ( $readings[
'windspeedmph'] )
184 $wind_speed = $readings[
'windspeedmph'] * 1.609344;
187 ##########################################################
188 # Extract the Wind Speed #
189 ##########################################################
190 if ( $readings[
'windspdmph_avg10m'] )
192 $wind_speed_avg10m = $readings[
'windspdmph_avg10m'] * 1.609344;
195 ##########################################################
196 # Extract the Wind Gust Speed #
197 ##########################################################
198 if ( $readings[
'windgustmph'] )
200 $wind_gust = $readings[
'windgustmph'] * 1.609344;
203 ##########################################################
204 # Extract the Max Daily Wind Gust Speed #
205 ##########################################################
206 if ( $readings[
'maxdailygust'] )
208 $wind_gust_max_daily = $readings[
'maxdailygust'] * 1.609344;
211 ##########################################################
212 # Extract the Wind Direction #
213 ##########################################################
214 if ( $readings[
'winddir'] )
216 $wind_direction = $readings[
'winddir'];
219 ##########################################################
220 # Extract the Wind Direction #
221 ##########################################################
222 if ( $readings[
'windspdmph_avg10m'] )
224 $wind_direction_avg10m = $readings[
'windspdmph_avg10m'];
227 ##########################################################
228 # Extract the Local Barometric Pressure #
229 ##########################################################
230 if ( $readings[
'baromabsin'] )
232 $absolute_barometer = $readings[
'baromabsin'] * 33.8639;
235 ##########################################################
236 # Extract the MSL Barometric Pressure #
237 ##########################################################
238 if ( $readings[
'baromrelin'] )
240 $relative_barometer = $readings[
'baromrelin'] * 33.8639;
243 ##########################################################
244 # Extract the Rainfall Rate #
245 ##########################################################
247 if ( $readings[
'rainratein'] )
249 $rain_rate = $readings[
'rainratein'] * 25.4;
252 ##########################################################
253 # Extract the Rainfall Event #
254 ##########################################################
255 if( $readings[
'eventrainin'] )
257 $rain_event = $readings[
'eventrainin'] * 25.4;
260 ##########################################################
261 # Extract the Hourly Rainfall #
262 ##########################################################
263 if ( $readings[
'hourlyrainin'] )
265 $rain_hourly = $readings[
'hourlyrainin'] * 25.4;
268 ##########################################################
269 # Extract the Daily Rainfall #
270 ##########################################################
271 if ( $readings[
'dailyrainin'] )
273 $rain_daily = $readings[
'dailyrainin'] * 25.4;
276 ##########################################################
277 # Extract the Weekly Rainfall #
278 ##########################################################
279 if ( $readings[
'weeklyrainin'] )
281 $rain_weekly = $readings[
'weeklyrainin'] * 25.4;
284 ##########################################################
285 # Extract the Monthly Rainfall #
286 ##########################################################
287 if ( $readings[
'monthlyrainin'] )
289 $rain_monthly = $readings[
'monthlyrainin'] * 25.4;
292 ##########################################################
293 # Extract the Yearly Rainfall #
294 ##########################################################
295 if ( $readings[
'yearlyrainin'] )
297 $rain_yearly = $readings[
'yearlyrainin'] * 25.4;
300 ##########################################################
301 # Extract the Solar Radiation #
302 ##########################################################
303 if ( $readings[
'solarradiation'] )
305 $power = $readings[
'solarradiation'];
308 ##########################################################
309 # Extract the UV Index #
310 ##########################################################
311 if ( $readings[
'uv'] !=
'' )
313 $uv_index = $readings[
'uv'];
316 ##########################################################
317 # Extract the Extra Temp/Humidity Sensors #
318 ##########################################################
320 if ( $readings[
'temp1f'] )
322 $temperature1 = ($readings[
'temp1f'] - 32.0) * 0.555555556;
325 if ( $readings[
'temp2f'] )
327 $temperature2 = ($readings[
'temp2f'] - 32.0) * 0.555555556;
330 if ( $readings[
'temp3f'] )
332 $temperature3 = ($readings[
'temp3f'] - 32.0) * 0.555555556;
335 if ( $readings[
'temp4f'] )
337 $temperature4 = ($readings[
'temp4f'] - 32.0) * 0.555555556;
340 if ( $readings[
'temp5f'] )
342 $temperature5 = ($readings[
'temp5f'] - 32.0) * 0.555555556;
345 if ( $readings[
'temp6f'] )
347 $temperature6 = ($readings[
'temp6f'] - 32.0) * 0.555555556;
350 if ( $readings[
'temp7f'] )
352 $temperature7 = ($readings[
'temp7f'] - 32.0) * 0.555555556;
355 if ( $readings[
'temp8f'] )
357 $temperature8 = ($readings[
'temp8f'] - 32.0) * 0.555555556;
360 if ( $readings[
'humidity1'] )
362 $humidity1 = $readings[
'humidity1'];
365 if ( $readings[
'humidity2'] )
367 $humidity2 = $readings[
'humidity2'];
370 if ( $readings[
'humidity3'] )
372 $humidity3 = $readings[
'humidity3'];
375 if ( $readings[
'humidity4'] )
377 $humidity4 = $readings[
'humidity4'];
380 if ( $readings[
'humidity5'] )
382 $humidity5 = $readings[
'humidity5'];
385 if ( $readings[
'humidity6'] )
387 $humidity6 = $readings[
'humidity6'];
390 if ( $readings[
'humidity7'] )
392 $humidity7 = $readings[
'humidity7'];
395 if ( $readings[
'humidity8'] )
397 $humidity1 = $readings[
'humidity8'];
400 ##########################################################
401 # Extract the Soil Moisture Readings #
402 ##########################################################
404 if ( $readings[
'soilmoisture1'] )
406 $moisture_soil_1 = $readings[
'soilmoisture1'];
409 if ( $readings[
'soilmoisture2'] )
411 $moisture_soil_2 = $readings[
'soilmoisture2'];
414 if ( $readings[
'soilmoisture3'] )
416 $moisture_soil_3 = $readings[
'soilmoisture3'];
419 if ( $readings[
'soilmoisture4'] )
421 $moisture_soil_4 = $readings[
'soilmoisture4'];
424 if ( $readings[
'soilmoisture5'] )
426 $moisture_soil_5 = $readings[
'soilmoisture5'];
429 if ( $readings[
'soilmoisture6'] )
431 $moisture_soil_6 = $readings[
'soilmoisture6'];
434 if ( $readings[
'soilmoisture7'] )
436 $moisture_soil_7 = $readings[
'soilmoisture7'];
439 if ( $readings[
'soilmoisture8'] )
441 $moisture_soil_8 = $readings[
'soilmoisture8'];
444 ##########################################################
445 # Extract the Battery States #
446 ##########################################################
448 if ( $readings[
'wh65batt'] )
450 $battery_wh65 = $readings[
'wh65batt'];
453 if ( $readings[
'wh25batt'] )
455 $battery_wh25 = $readings[
'wh25batt'];
458 if ( $readings[
'batt1'] )
460 $battery_1 = $readings[
'batt1'];
463 if ( $readings[
'batt2'] )
465 $battery_2 = $readings[
'batt2'];
468 if ( $readings[
'batt3'] )
470 $battery_3 = $readings[
'batt3'];
473 if ( $readings[
'batt4'] )
475 $battery_4 = $readings[
'batt4'];
478 if ( $readings[
'batt5'] )
480 $battery_5 = $readings[
'batt5'];
483 if ( $readings[
'batt6'] )
485 $battery_6 = $readings[
'batt6'];
488 if ( $readings[
'batt7'] )
490 $battery_7 = $readings[
'batt7'];
493 if ( $readings[
'batt8'] )
495 $battery_8 = $readings[
'batt8'];
498 ############################################################
499 # Old versions of the firmware may use "Siolbatt", while #
500 # later versions will use "soilbatt", so include both #
501 # just in case. There are so many models and versions that #
502 # it is simpler to try anything based on model numbers. #
503 ############################################################
505 if ( $readings[
'Siolbatt1'] !=
'' )
507 $battery_moisture_soil_1 = $readings[
'Siolbatt1'];
510 if ( $readings[
'Siolbatt2'] !=
'' )
512 $battery_moisture_soil_2 = $readings[
'Siolbatt2'];
515 if ( $readings[
'Siolbatt3'] !=
'' )
517 $battery_moisture_soil_3 = $readings[
'Siolbatt3'];
520 if ( $readings[
'Siolbatt4'] !=
'' )
522 $battery_moisture_soil_4 = $readings[
'Siolbatt4'];
525 if ( $readings[
'Siolbatt5'] !=
'' )
527 $battery_moisture_soil_5 = $readings[
'Siolbatt5'];
530 if ( $readings[
'Siolbatt6'] !=
'' )
532 $battery_moisture_soil_6 = $readings[
'Siolbatt6'];
535 if ( $readings[
'Siolbatt7'] !=
'' )
537 $battery_moisture_soil_7 = $readings[
'Siolbatt7'];
540 if ( $readings[
'Siolbatt8'] !=
'' )
542 $battery_moisture_soil_8 = $readings[
'Siolbatt8'];
545 if ( $readings[
'soilbatt1'] !=
'' )
547 $battery_moisture_soil_1 = $readings[
'soilbatt1'];
550 if ( $readings[
'soilbatt2'] !=
'' )
552 $battery_moisture_soil_2 = $readings[
'soilbatt2'];
555 if ( $readings[
'soilbatt3'] !=
'' )
557 $battery_moisture_soil_3 = $readings[
'soilbatt3'];
560 if ( $readings[
'soilbatt4'] !=
'' )
562 $battery_moisture_soil_4 = $readings[
'soilbatt4'];
565 if ( $readings[
'soilbatt5'] !=
'' )
567 $battery_moisture_soil_5 = $readings[
'soilbatt5'];
570 if ( $readings[
'soilbatt6'] !=
'' )
572 $battery_moisture_soil_6 = $readings[
'soilbatt6'];
575 if ( $readings[
'soilbatt7'] !=
'' )
577 $battery_moisture_soil_7 = $readings[
'soilbatt7'];
580 if ( $readings[
'soilbatt8'] !=
'' )
582 $battery_moisture_soil_8 = $readings[
'soilbatt8'];
585 if ( $readings[
'pm25batt1'] !=
'' )
587 $option_pm25_battery_1 = $readings[
'pm25batt1'];
590 if ( $readings[
'pm25batt2'] !=
'' )
592 $option_pm25_battery_2 = $readings[
'pm25batt2'];
595 if ( $readings[
'pm25batt3'] !=
'' )
597 $option_pm25_battery_3 = $readings[
'pm25batt3'];
600 if ( $readings[
'pm25batt4'] !=
'' )
602 $option_pm25_battery_4 = $readings[
'pm25batt4'];
605 #########################################################################
606 # Process any PM2.5 Sensors that are connected to the weather station #
608 #########################################################################
610 if ( $readings[
'pm25_ch1'] !=
'' )
612 $option_pm25_ch1 = $readings[
'pm25_ch1'];
615 if ( $readings[
'pm25_avg_24h_ch1'] !=
'' )
617 $option_pm25_avg_24h_ch1 = $readings[
'pm25_avg_24h_ch1'];
620 if ( $readings[
'pm25_ch2'] !=
'' )
622 $option_pm25_ch2 = $readings[
'pm25_ch2'];
625 if ( $readings[
'pm25_avg_24h_ch2'] !=
'' )
627 $option_pm25_avg_24h_ch2 = $readings[
'pm25_avg_24h_ch2'];
630 if ( $readings[
'pm25_ch3'] !=
'' )
632 $option_pm25_ch3 = $readings[
'pm25_ch3'];
635 if ( $readings[
'pm25_avg_24h_ch3'] !=
'' )
637 $option_pm25_avg_24h_ch3 = $readings[
'pm25_avg_24h_ch3'];
640 if ( $readings[
'pm25_ch4'] !=
'' )
642 $option_pm25_ch4 = $readings[
'pm25_ch4'];
645 if ( $readings[
'pm25_avg_24h_ch4'] !=
'' )
647 $option_pm25_avg_24h_ch4 = $readings[
'pm25_avg_24h_ch4'];
650 #########################################################################
651 # If Dew Point is not provided, estimate the Dew Point using the method #
652 # by Arden Buck in Journal of Applied Meteorology and Climatology. This #
653 # method is accurate for the temperature range -40C to +50C. #
654 #########################################################################
655 if ( !isset( $dewpoint ) )
657 if ( $outdoor_temp >= 0.0 )
659 $a = 6.1121; $b = 17.368; $c = 238.88; $d = 234.5;
663 $a = 6.1121; $b = 17.966; $c = 247.15; $d = 234.5;
665 $ym = log( ($outdoor_humidity/100.0) * exp( ($b-$outdoor_temp/$d)*($outdoor_temp/($c+$outdoor_temp) ) ) );
666 $dew_point = $c*$ym/($b-$ym);
669 #########################################################################
670 # If Windchill Temperature is not provided, estimate the Windchill Temp #
671 # using the Australian Bureau Of Meteorology Apparent Temperature (AT) #
672 # method calculated for an adult walking outdoors in the shade. #
673 #########################################################################
674 if ( !isset( $windchill ) )
676 $v = $wind_speed * 0.2777778; $e = ($outdoor_humidity/100.0)*6.105*exp( (17.27*$outdoor_temp)/(237.7+$outdoor_temp) );
677 $windchill = $outdoor_temp + 0.33*$e - 0.7*$v - 4.0;
680 ########################################################################
681 # Find the Station Index From the Ecowitt Passkey #
682 # The station index is the key identifying the station in all records. #
683 # Also determine if non-essential fields like the battery states and #
684 # the identification strings are required. If they are not required, #
685 # those fields are not sent, reducing the database storage required. #
686 # If the fields are not defined in the database are sent, it will #
687 # result in the entire observation being discarded. If the fields #
688 # exist in the database, but are not sent, they will be recorded as a #
689 # NULL in the database, but the other readings will be recorded as #
691 ########################################################################
694 $station_query =
"select station_index, trim_readings from station where ecowitt_passkey= '$passkey';";
695 $result = $connection->query($station_query);
696 $row_count = $result->rowCount();
697 if ( $row_count != 1)
702 foreach ($connection->query($station_query) as $row )
704 $station_index = $row[
'station_index'];
705 $trim_readings = $row[
'trim_readings'];
708 ###############################################################
709 # Create the SQL INSERT Statement based on readings provided. #
710 ###############################################################
712 $field_string =
"station_index, date_utc";
713 $value_string = $station_index .
',\'' . $date_utc .
'\'';
715 $field_string_battery =
"station_index, date_utc";
716 $value_string_battery = $station_index .
',\'' . $date_utc .
'\'';
718 $field_string_version =
"station_index, date_utc";
719 $value_string_version = $station_index .
',\'' . $date_utc .
'\'';
722 if ( isset($indoor_temp) )
724 $field_string .=
", temperature_internal";
725 $value_string .=
", " . $indoor_temp;
728 if ( isset($outdoor_temp) )
730 $field_string .=
", temperature_external";
731 $value_string .=
", " . $outdoor_temp;
734 if ( isset($dew_point) )
736 $field_string .=
", dew_point";
737 $value_string .=
", " . $dew_point;
740 if ( isset($windchill) )
742 $field_string .=
", wind_chill_temp";
743 $value_string .=
", " . $windchill;
746 if ( isset($outdoor_humidity) )
748 $field_string .=
", humidity_external";
749 $value_string .=
", " . $outdoor_humidity;
752 if ( isset($indoor_humidity) )
754 $field_string .=
", humidity_internal";
755 $value_string .=
", " . $indoor_humidity;
758 if ( isset($wind_speed) )
760 $field_string .=
", wind_speed";
761 $value_string .=
", " . $wind_speed;
764 if ( isset($wind_speed_avg10m) )
766 $field_string .=
", wind_speed_avg10m";
767 $value_string .=
", " . $wind_speed_avg10m;
770 if ( isset($wind_gust) )
772 $field_string .=
", wind_gust";
773 $value_string .=
", " . $wind_gust;
776 if ( isset($wind_gust_max_daily) )
778 $field_string .=
", wind_gust_max_daily";
779 $value_string .=
", " . $wind_gust_max_daily;
782 if ( isset($wind_direction) )
784 $field_string .=
", wind_direction";
785 $value_string .=
", " . $wind_direction;
788 if ( isset($wind_direction_avg10m) )
790 $field_string .=
", wind_direction_avg10m";
791 $value_string .=
", " . $wind_direction_avg10m;
794 if ( isset($absolute_barometer) )
796 $field_string .=
", barometer_absolute";
797 $value_string .=
", " . $absolute_barometer;
800 if ( isset($relative_barometer) )
802 $field_string .=
", barometer_relative";
803 $value_string .=
", " . $relative_barometer;
806 if ( isset($rain_rate) )
808 $field_string .=
", rainfall_rate";
809 $value_string .=
", " . $rain_rate;
812 if ( isset($rain_event) )
814 $field_string .=
", rainfall_event";
815 $value_string .=
", " . $rain_event;
818 if ( isset($rain_hourly) )
820 $field_string .=
", rainfall_hour";
821 $value_string .=
", " . $rain_hourly;
824 if ( isset($rain_daily) )
826 $field_string .=
", rainfall_day";
827 $value_string .=
", " . $rain_daily;
830 if ( isset($rain_weekly) )
832 $field_string .=
", rainfall_week";
833 $value_string .=
", " . $rain_weekly;
836 if ( isset($rain_monthly) )
838 $field_string .=
", rainfall_month";
839 $value_string .=
", " . $rain_monthly;
842 if ( isset($rain_yearly) )
844 $field_string .=
", rainfall_year";
845 $value_string .=
", " . $rain_yearly;
850 $field_string .=
", power";
851 $value_string .=
", " . $power;
854 if ( isset($uv_index) )
856 $field_string .=
", uv_index";
857 $value_string .=
", " . $uv_index;
860 if ( isset($temperature1) )
862 $field_string .=
", temperature_1";
863 $value_string .=
", " . $temperature1;
866 if ( isset($temperature2) )
868 $field_string .=
", temperature_2";
869 $value_string .=
", " . $temperature2;
872 if ( isset($temperature3) )
874 $field_string .=
", temperature_3";
875 $value_string .=
", " . $temperature3;
878 if ( isset($temperature4) )
880 $field_string .=
", temperature_4";
881 $value_string .=
", " . $temperature4;
884 if ( isset($temperature5) )
886 $field_string .=
", temperature_5";
887 $value_string .=
", " . $temperature5;
890 if ( isset($temperature6) )
892 $field_string .=
", temperature_6";
893 $value_string .=
", " . $temperature6;
896 if ( isset($temperature7) )
898 $field_string .=
", temperature_7";
899 $value_string .=
", " . $temperature7;
902 if ( isset($temperature8) )
904 $field_string .=
", temperature_8";
905 $value_string .=
", " . $temperature8;
908 if ( isset($humidity1) )
910 $field_string .=
", humidity_1";
911 $value_string .=
", " . $humidity1;
914 if ( isset($humidity2) )
916 $field_string .=
", humidity_2";
917 $value_string .=
", " . $humidity2;
920 if ( isset($humidity3) )
922 $field_string .=
", humidity_3";
923 $value_string .=
", " . $humidity3;
926 if ( isset($humidity4) )
928 $field_string .=
", humidity_4";
929 $value_string .=
", " . $humidity4;
932 if ( isset($humidity5) )
934 $field_string .=
", humidity_5";
935 $value_string .=
", " . $humidity5;
938 if ( isset($humidity6) )
940 $field_string .=
", humidity_6";
941 $value_string .=
", " . $humidity6;
944 if ( isset($humidity7) )
946 $field_string .=
", humidity_7";
947 $value_string .=
", " . $humidity7;
950 if ( isset($humidity8) )
952 $field_string .=
", humidity_8";
953 $value_string .=
", " . $humidity8;
956 if ( isset( $moisture_soil_1 ) )
958 $field_string .=
", moisture_soil_1";
959 $value_string .=
", " . $moisture_soil_1;
962 if ( isset( $moisture_soil_2 ) )
964 $field_string .=
", moisture_soil_2";
965 $value_string .=
", " . $moisture_soil_2;
968 if ( isset( $moisture_soil_3 ) )
970 $field_string .=
", moisture_soil_3";
971 $value_string .=
", " . $soil_moisture3;
974 if ( isset( $moisture_soil_4 ) )
976 $field_string .=
", moisture_soil_4";
977 $value_string .=
", " . $soil_moisture4;
980 if ( isset( $moisture_soil_5 ) )
982 $field_string .=
", moisture_soil_5";
983 $value_string .=
", " . $soil_moisture5;
986 if ( isset( $moisture_soil_6 ) )
988 $field_string .=
", moisture_soil_6";
989 $value_string .=
", " . $soil_moisture6;
992 if ( isset( $moisture_soil_7 ) )
994 $field_string .=
", moisture_soil_7";
995 $value_string .=
", " . $soil_moisture7;
998 if ( isset( $moisture_soil_8 ) )
1000 $field_string .=
", moisture_soil_8";
1001 $value_string .=
", " . $soil_moisture8;
1004 if ( $option_pm25_ch1 !=
'' )
1006 $field_string .=
", air_quality_P25_1";
1007 $value_string .=
", " . $option_pm25_ch1;
1010 if ( $option_pm25_avg_24h_ch1 !=
'' )
1012 $field_string .=
", air_quality_AQI_1";
1013 $value_string .=
", " . $option_pm25_avg_24h_ch1;
1016 if ( $option_pm25_ch2 !=
'' )
1018 $field_string .=
", air_quality_P25_2";
1019 $value_string .=
", " . $option_pm25_ch2;
1022 if ( $option_pm25_avg_24h_ch2 !=
'' )
1024 $field_string .=
", air_quality_AQI_2";
1025 $value_string .=
", " . $option_pm25_avg_24h_ch2;
1028 if ( $option_pm25_ch3 !=
'' )
1030 $field_string .=
", air_quality_P25_3";
1031 $value_string .=
", " . $option_pm25_ch3;
1034 if ( $option_pm25_avg_24h_ch3 !=
'' )
1036 $field_string .=
", air_quality_AQI_3";
1037 $value_string .=
", " . $option_pm25_avg_24h_ch3;
1040 if ( $option_pm25_ch4 !=
'' )
1042 $field_string .=
", air_quality_P25_4";
1043 $value_string .=
", " . $option_pm25_ch4;
1046 if ( $option_pm25_avg_24h_ch4 !=
'' )
1048 $field_string .=
", air_quality_AQI_4";
1049 $value_string .=
", " . $option_pm25_avg_24h_ch4;
1053 if ( $trim_readings != 1 )
1056 if ( $battery_1 !=
'' )
1058 $field_string_battery .=
", battery_temp_humidity_1";
1059 $value_string_battery .=
", " . $battery_1;
1062 if ( isset($battery_2) )
1064 $field_string_battery .=
", battery_temp_humidity_2";
1065 $value_string_battery .=
", " . $battery_2;
1068 if ( isset($battery_3) )
1070 $field_string_battery .=
", battery_temp_humidity_3";
1071 $value_string_battery .=
", " . $battery_3;
1074 if ( isset($battery_4) )
1076 $field_string_battery .=
", battery_temp_humidity_4";
1077 $value_string_battery .=
", " . $battery_4;
1080 if ( isset($battery_5) )
1082 $field_string_battery .=
", battery_temp_humidity_5";
1083 $value_string_battery .=
", " . $battery_5;
1086 if ( isset($battery_6) )
1088 $field_string_battery .=
", battery_temp_humidity_6";
1089 $value_string_battery .=
", " . $battery_6;
1092 if ( isset($battery_7) )
1094 $field_string_battery .=
", battery_temp_humidity_7";
1095 $value_string_battery .=
", " . $battery_7;
1098 if ( isset($battery_8) )
1100 $field_string_battery .=
", battery_temp_humidity_8";
1101 $value_string_battery .=
", " . $battery_8;
1104 if ( isset($battery_moisture_soil_1 ) )
1106 $field_string_battery .=
", battery_moisture_soil_1";
1107 $value_string_battery .=
", " . $battery_moisture_soil_1;
1110 if ( isset($battery_moisture_soil_2 ) )
1112 $field_string_battery .=
", battery_moisture_soil_2";
1113 $value_string_battery .=
", " . $battery_moisture_soil_2;
1116 if ( isset($battery_moisture_soil_3 ) )
1118 $field_string_battery .=
", battery_moisture_soil_3";
1119 $value_string_battery .=
", " . $battery_moisture_soil_3;
1122 if ( isset($battery_moisture_soil_4 ) )
1124 $field_string_battery .=
", battery_moisture_soil_4";
1125 $value_string_battery .=
", " . $battery_moisture_soil_4;
1128 if ( isset($battery_moisture_soil_5 ) )
1130 $field_string_battery .=
", battery_moisture_soil_5";
1131 $value_string_battery .=
", " . $battery_moisture_soil_5;
1134 if ( isset($battery_moisture_soil_6 ) )
1136 $field_string_battery .=
", battery_moisture_soil_6";
1137 $value_string_battery .=
", " . $battery_moisture_soil_6;
1140 if ( isset($battery_moisture_soil_7 ) )
1142 $field_string_battery .=
", battery_moisture_soil_6";
1143 $value_string_battery .=
", " . $battery_moisture_soil_7;
1146 if ( isset($battery_moisture_soil_8 ) )
1148 $field_string_battery .=
", battery_moisture_soil_8";
1149 $value_string_battery .=
", " . $battery_moisture_soil_8;
1152 if ( isset($option_pm25_battery_1 ) )
1154 $field_string_battery .=
", option_pm25_battery_1";
1155 $value_string_battery .=
", " . $option_pm25_battery_1;
1158 if ( isset($option_pm25_battery_2 ) )
1160 $field_string_battery .=
", option_pm25_battery_2";
1161 $value_string_battery .=
", " . $option_pm25_battery_2;
1164 if ( isset($option_pm25_battery_3 ) )
1166 $field_string_battery .=
", option_pm25_battery_3";
1167 $value_string_battery .=
", " . $option_pm25_battery_3;
1170 if ( isset($option_pm25_battery_4 ) )
1172 $field_string_battery .=
", option_pm25_battery_4";
1173 $value_string_battery .=
", " . $option_pm25_battery_4;
1176 if ( isset($battery_wh65) )
1178 $field_string_battery .=
", battery_wh65";
1179 $value_string_battery .=
", " . $battery_wh65;
1182 if ( isset($battery_wh25) )
1184 $field_string_battery .=
", battery_wh25";
1185 $value_string_battery .=
", " . $battery_wh25;
1188 if ( isset($software_type ) )
1190 $field_string_version .=
", software_type";
1191 $value_string_version .=
", '" . $software_type .
"'";
1194 if ( isset( $model ) )
1196 $field_string_version .=
", station_model";
1197 $value_string_version .=
", '" . $model .
"'";
1200 if ( isset( $freq ) )
1202 $field_string_version .=
", frequency";
1203 $value_string_version .=
", '" . $freq .
"'";
1206 $insert_query =
"insert into WeatherStation.ws_obs( " . $field_string .
" ) values( " . $value_string .
" );";
1207 $insert_query_battery =
"insert into WeatherStation.ws_battery( " . $field_string_battery .
" ) values( " . $value_string_battery .
" );";
1208 $insert_query_option =
"insert into WeatherStation.ws_version( " . $field_string_version .
" ) values( " . $value_string_version .
" );";
1210 ###############################
1211 # Used for Debugging Purposes #
1212 ###############################
1213 $query =
"\n\n$insert_query";
1216 # Insert the Observation Into the database
1217 $statement = $connection->prepare( $insert_query );
1218 $statement->execute();
1221 if ( $trim_readings != 1 )
1223 $statement_battery = $connection->prepare( $insert_query_battery );
1224 $statement_battery->execute();
1226 ###############################
1227 # Used for Debugging Purposes #
1228 ###############################
1229 $query_option =
"\n\n$insert_query_battery";
1232 ###############################
1233 # Used for Debugging Purposes #
1234 ###############################
1235 $query_option =
"\n\n$insert_query_option";
1238 $statement_option = $connection->prepare( $insert_query_option );
1239 $statement_option->execute();
1242 $connection->commit();
1243 header(
"HTTP/1.0 200 Success" );
SaveObservation()
Save the Incoming Observation to the WeatherStation Database.
DbConnect( $DbFunction, $ConnectionType='mysqli')
Make a Connection to a MariaDB/MySQL Database.