25°C)) $v_jeedomIdPointGivre = "&id=208"; # point de givre # Fonction d'appel de l'URL Jeedom function f_callUrl($vf_url, $vf_id, $vf_valeur){ $v_ch = curl_init(); curl_setopt($v_ch, CURLOPT_URL, $vf_url.$vf_id.'&value='.$vf_valeur); curl_setopt($v_ch, CURLOPT_RETURNTRANSFER, 1); $v_ReturnUrl = curl_exec($v_ch); curl_close($v_ch); } # Debug error_reporting(E_ALL); ini_set('display_errors', 'on'); # Settings: General $device = "auto"; # Use 'auto' for automatic name from PASSKEY else uses the name $json_data_log = 0; # Activate the export to .json (données brutes + données calculées) $csv_data_log = 0; # Activate the export to .csv (données historisées, une ligne par relevé) $txt_data_log = 0; # Activate the export to .txt (uniquement les données reçues brutes) $txt_weewx = 0; # Activate the export to .txt for weewx driver # Settings: json, csv, txt and Weewx driver data log dir $json_data_logdir = "/var/www/html/pws"; # export au format json $csv_data_logdir = "/var/www/html/pws"; # export au format csv $txt_data_logdir = "/var/www/html/pws"; # export au format txt des données brutes reçues $txt_dir_weewx = "/var/www/html/pws"; # export au format Weewx # *** SETTINGS END *** # ******************** # Convert HTTP POST variables to json $weather_data = $_POST; # données brutes reçues de la station météo $weather_data_untouched = $weather_data; # on conserve les données initiales pour export brut $weather_data_forward = $_GET; $date_txt = date('Y-m-d'); # Conversion factors $f_mph_kmh = 1.60934; $f_mph_kts = 0.868976; $f_mph_ms = 0.44704; $f_in_hpa = 33.86; $f_in_mm = 25.4; # Get weather station identifier if requested if ( $device == "auto" ) { $device = "weather_" . $weather_data['PASSKEY']; } else { $device = "weather_" . $device ; } # Convert data # Temps @$weather_data['windchillc'] = round( ( $weather_data['windchillf'] - 32 ) * 5 / 9, 2 ); @$weather_data['tempc'] = round( ( $weather_data['tempf'] - 32 ) * 5 / 9, 2 ); @$weather_data['temp1c'] = round( ( $weather_data['temp1f'] - 32 ) * 5 / 9, 2 ); @$weather_data['temp2c'] = round( ( $weather_data['temp2f'] - 32 ) * 5 / 9, 2 ); @$weather_data['temp3c'] = round( ( $weather_data['temp3f'] - 32 ) * 5 / 9, 2 ); @$weather_data['tempinc'] = round( ( $weather_data['tempinf'] - 32 ) * 5 / 9, 2 ); @$weather_data['dewptc'] = round( ( $weather_data['dewptf'] - 32 ) * 5 / 9, 2 ); # Calcul de l'indice de chaleur par la formule de Steadman : @$weather_data['heatindexf'] = 0.5 * ($weather_data['tempf'] + 61 + (($weather_data['tempf']-68)*1.2) + ($weather_data['humidity']*0.094)); if ($weather_data['heatindexf'] > 80) # Indice obtenu > 80°F, on prends la formule de regression de Lans P. Rothfusz : { @$weather_data['heatindexf'] = -42.379 + 2.04901523 * $weather_data['tempf'] + 10.14333127 * $weather_data['humidity'] - 0.22475541 * $weather_data['tempf'] * $weather_data['humidity'] - 0.00683783 * $weather_data['tempf'] ** 2 - 0.05481717 * $weather_data['humidity'] ** 2 + 0.00122874 * $weather_data['tempf'] ** 2 * $weather_data['humidity'] + 0.00085282 * $weather_data['tempf'] * $weather_data['humidity'] ** 2 - 0.00000199 * $weather_data['tempf'] ** 2 * $weather_data['humidity'] ** 2; if ($weather_data['humidity'] < 13 AND $weather_data['tempf'] > 80 AND $weather_data['tempf'] < 112) { @$weather_data['heatindexf'] = @$weather_data['heatindexf'] - (((13-$weather_data['humidity'])/4)*sqrt((17-abs($weather_data['tempf']-95))/17)); } elseif ($weather_data['humidity'] > 85 AND $weather_data['tempf'] > 80 AND $weather_data['tempf'] < 87) { @$weather_data['heatindexf'] = @$weather_data['heatindexf'] + ((($weather_data['humidity']-85)/10) * ((87-$weather_data['tempf'])/5)); } } @$weather_data['heatindexc'] = round( ( $weather_data['heatindexf'] - 32 ) * 5 / 9, 2 ); # Speeds @$weather_data['windgustkmh'] = round( $weather_data['windgustmph'] * $f_mph_kmh, 2 ); @$weather_data['windspeedkmh'] = round( $weather_data['windspeedmph'] * $f_mph_kmh, 2 ); # Calcul température ressentie : @$weather_data['windchillc'] = round((13.12 + 0.6215 * @$weather_data['tempc'] - 11.37 * pow(@$weather_data['windspeedkmh'],0.16) + 0.3965 * @$weather_data['tempc'] * pow(@$weather_data['windspeedkmh'],0.16)), 1); @$weather_data['windchillf'] = round( ( $weather_data['windchillc'] * 9 / 5 ) + 32, 2 ); # Calcul point de rosée par la formule de Heinrich Gustav Magnus-Tetens: @$weather_data['dewptc'] = round(((pow(($weather_data['humidity']/100), 0.125))*(112+0.9*@$weather_data['tempc'])+(0.1*@$weather_data['tempc'])-112),2); @$weather_data['dewptf'] = round( ( $weather_data['dewptc'] * 9 / 5 ) + 32, 2 ); # Calcul point de givre, mais uniquement si la température est < 4°C # sinon ça n'a aucun sens, car on considère en effet qu'au-delà de 3°C # le sol n'est plus gelé, donc la rosée qui se dépose restera liquide : if ($weather_data['tempc'] < 4) { @$v_Tmpk = $weather_data['tempc'] + 273.15; @$v_PDRk = $weather_data['dewptc'] + 273.15; @$v_PDGk = $v_PDRk + (2671.02 / ((2954.61/$v_Tmpk) + (2.193665 * log($v_Tmpk)) - 13.3448)) - $v_Tmpk; @$weather_data['pointgivrec'] = round(($v_PDGk - 273.15), 2); } else { @$weather_data['pointgivrec'] = 0.00; } # Distances @$weather_data['rainratemm'] = round( $weather_data['rainratein'] * $f_in_mm, 2 ); @$weather_data['eventrainmm'] = round( $weather_data['eventrainin'] * $f_in_mm, 2 ); @$weather_data['hourlyrainmm'] = round( $weather_data['hourlyrainin'] * $f_in_mm, 2 ); @$weather_data['dailyrainmm'] = round( $weather_data['dailyrainin'] * $f_in_mm, 2 ); @$weather_data['weeklyrainmm'] = round( $weather_data['weeklyrainin'] * $f_in_mm, 2 ); @$weather_data['monthlyrainmm'] = round( $weather_data['monthlyrainin'] * $f_in_mm, 2 ); @$weather_data['totalrainmm'] = round( $weather_data['totalrainin'] * $f_in_mm, 2 ); # Baros @$weather_data['baromabshpa'] = round( $weather_data['baromabsin'] * $f_in_hpa, 2 ); @$weather_data['baromrelhpa'] = round( $weather_data['baromrelin'] * $f_in_hpa, 2 ); # Date and time @$weather_data['dateutc'] = gmdate("Y-m-d\TH:i:s\Z"); # Batteries if ( @$weather_data['wh80batt'] < 2.5 ) { @$weather_data['windBatteryStatus'] = 1.0 ; } if ( @$weather_data['wh80batt'] > 2.5 ) { @$weather_data['windBatteryStatus'] = 0.0 ; } @$weather_data['consBatteryVoltage'] = @$weather_data['wh80batt'] ; if ( @$weather_data['wh40batt'] < 1.0 ) { @$weather_data['rainBatteryStatus'] = 1.0 ; } if ( @$weather_data['wh40batt'] > 1.0 ) { @$weather_data['rainBatteryStatus'] = 0.0 ; } @$weather_data['supplyVoltage'] = @$weather_data['wh40batt'] ; if ( @$weather_data['soilbatt1'] < 1.0 ) { @$weather_data['txBatteryStatus'] = 1.0 ; } if ( @$weather_data['soilbatt1'] > 1.0 ) { @$weather_data['txBatteryStatus'] = 0.0 ; } @$weather_data['heatingVoltage'] = @$weather_data['soilbatt1'] ; @$weather_data['outTempBatteryStatus'] = @$weather_data['batt1'] ; # Transfert des données vers Jeedom : f_CallUrl($v_JeedomUrl, $v_jeedomIdUv, $weather_data['uv']); f_CallUrl($v_JeedomUrl, $v_JeedomIdRay, $weather_data['solarradiation']); f_CallUrl($v_JeedomUrl, $v_jeedomIdTempExt, $weather_data['tempc']); f_CallUrl($v_JeedomUrl, $v_jeedomIdHygroExt, $weather_data['humidity']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPressAbs, $weather_data['baromabshpa']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPressRel, $weather_data['baromrelhpa']); f_CallUrl($v_JeedomUrl, $v_jeedomIdVentDir, $weather_data['winddir']); f_CallUrl($v_JeedomUrl, $v_jeedomIdVentVit, $weather_data['windspeedkmh']); f_CallUrl($v_JeedomUrl, $v_jeedomIdVentRaf, $weather_data['windgustkmh']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPluieInst, $weather_data['eventrainmm']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPluieMoy, $weather_data['rainratemm']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPluieHeure, $weather_data['hourlyrainmm']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPluieJour, $weather_data['dailyrainmm']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPluieSem, $weather_data['weeklyrainmm']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPluieMois, $weather_data['monthlyrainmm']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPluieTot, $weather_data['totalrainmm']); f_CallUrl($v_JeedomUrl, $v_jeedomIdTempRess, $weather_data['windchillc']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPtRosee, $weather_data['dewptc']); f_CallUrl($v_JeedomUrl, $v_jeedomIdTempInt, $weather_data['tempinc']); f_CallUrl($v_JeedomUrl, $v_jeedomIdHygroInt, $weather_data['humidityin']); f_CallUrl($v_JeedomUrl, $v_jeedomIdBatterie, $weather_data['wh65batt']); f_CallUrl($v_JeedomUrl, $v_jeedomIdModele, $weather_data['model']); f_CallUrl($v_JeedomUrl, $v_jeedomIdFirmware, $weather_data['stationtype']); f_CallUrl($v_JeedomUrl, $v_jeedomIdFrequence, $weather_data['freq']); f_CallUrl($v_JeedomUrl, $v_jeedomIdHeatIndex, $weather_data['heatindexc']); f_CallUrl($v_JeedomUrl, $v_jeedomIdPointGivre, $weather_data['pointgivrec']); # Pack data into json format $weather_data_json = json_encode($weather_data); # données retouchées $weather_data_json_untouched = json_encode($weather_data_untouched); # données brutes # Write json stream to logfile if ( $json_data_log == 1 ) { #$json_data_logfile = $json_data_logdir . "/" . $device . ".json"; $json_data_logfile = $json_data_logdir . "/export.json"; $file = fopen($json_data_logfile, 'w'); fwrite($file, $weather_data_json); fclose($file); } # Write stream to csvfile if ( $csv_data_log == 1 ) { # $csv_data_logfile = $csv_data_logdir . "/" . $device . "_" . $date_txt . ".csv"; # nom de fichier avec la date et le device name $csv_data_logfile = $csv_data_logdir . "/export.csv"; # nom de fichier sans la date ni le device if (!file_exists($csv_data_logfile)) { $data = json_decode($weather_data_json); foreach($data as $key => $value) { $string .= $key . ','; } $string .= "\n"; file_put_contents($csv_data_logfile, $string, FILE_APPEND); } $file = fopen($csv_data_logfile, 'a'); fputcsv($file, $weather_data); fclose($file); } # Write untouched data to text file if ( $txt_data_log == 1 ) { $txt_data_logfile = $txt_data_logdir . "/export.txt"; $file = fopen($txt_data_logfile, 'w'); $txt_data = print_r($weather_data_untouched, TRUE); fwrite($file, $txt_data); fclose($file); } # Write stream to Weewx file if ( $txt_weewx == 1 ) { @$weather_data_weewx['outTemp'] = $weather_data['tempf'] ; @$weather_data_weewx['barometer'] = $weather_data['baromrelin'] ; @$weather_data_weewx['pressure'] = $weather_data['baromrelin'] ; @$weather_data_weewx['outHumidity'] = $weather_data['humidity'] ; @$weather_data_weewx['windSpeed'] = $weather_data['windspeedmph'] ; @$weather_data_weewx['windDir'] = $weather_data['winddir'] ; @$weather_data_weewx['windGust'] = $weather_data['windgustmph'] ; @$weather_data_weewx['rainRate'] = $weather_data['rainratein'] ; @$weather_data_weewx['rain_total'] = $weather_data['totalrainin'] ; @$weather_data_weewx['inTemp'] = $weather_data['tempinf'] ; @$weather_data_weewx['inHumidity'] = $weather_data['humidityin'] ; @$weather_data_weewx['radiation'] = $weather_data['solarradiation'] ; @$weather_data_weewx['UV'] = $weather_data['uv'] ; @$weather_data_weewx['windchill'] = $weather_data['windchillf'] ; @$weather_data_weewx['dewpoint'] = $weather_data['dewptf'] ; @$weather_data_weewx['pointgivrec'] = $weather_data['pointgivrec'] ; @$weather_data_weewx['extraTemp1'] = $weather_data['temp1f'] ; @$weather_data_weewx['extraHumid1'] = $weather_data['humidity1'] ; @$weather_data_weewx['extraTemp2'] = $weather_data['temp2f'] ; @$weather_data_weewx['extraHumid2'] = $weather_data['humidity2'] ; @$weather_data_weewx['extraTemp3'] = $weather_data['temp3f'] ; @$weather_data_weewx['extraHumid3'] = $weather_data['humidity3'] ; @$weather_data_weewx['soilTemp1'] = $weather_data['soilmoisture1'] ; @$weather_data_weewx['windBatteryStatus'] = $weather_data['windBatteryStatus'] ; @$weather_data_weewx['rainBatteryStatus'] = $weather_data['rainBatteryStatus'] ; @$weather_data_weewx['outTempBatteryStatus'] = $weather_data['batt1'] ; @$weather_data_weewx['consBatteryVoltage'] = $weather_data['consBatteryVoltage'] ; @$weather_data_weewx['supplyVoltage'] = $weather_data['supplyVoltage'] ; @$weather_data_weewx['heatingVoltage'] = $weather_data['heatingVoltage'] ; @$weather_data_weewx['txBatteryStatus'] = $weather_data['txBatteryStatus'] ; $stringa = "outTemp=" . @$weather_data_weewx['outTemp'] . "\nbarometer=" . @$weather_data_weewx['barometer'] . "\npressure=" . @$weather_data_weewx['pressure'] . "\noutHumidity=" . @$weather_data_weewx['outHumidity'] . "\nwindSpeed=" . @$weather_data_weewx['windSpeed'] . "\nwindDir=" . @$weather_data_weewx['windDir'] . "\nwindGust=" . @$weather_data_weewx['windGust'] . "\nrainRate=" . @$weather_data_weewx['rainRate'] . "\nrain_total=" . @$weather_data_weewx['rain_total'] . "\ninTemp=" . @$weather_data_weewx['inTemp'] . "\ninHumidity=" . @$weather_data_weewx['inHumidity'] . "\nradiation=" . @$weather_data_weewx['radiation'] . "\nUV=" . @$weather_data_weewx['UV'] . "\nwindchill=" . @$weather_data_weewx['windchill'] . "\ndewpoint=" . @$weather_data_weewx['dewpoint'] . "\nextraTemp1=" . @$weather_data_weewx['extraTemp1'] . "\nextraHumid1=" . @$weather_data_weewx['extraHumid1'] . "\nextraTemp2=" . @$weather_data_weewx['extraTemp2'] . "\nextraHumid2=" . @$weather_data_weewx['extraHumid2'] . "\nextraTemp3=" . @$weather_data_weewx['extraTemp3'] . "\nextraHumid3=" . @$weather_data_weewx['extraHumid3'] . "\nsoilTemp1=" . @$weather_data_weewx['soilTemp1'] . "\nwindBatteryStatus=" . @$weather_data_weewx['windBatteryStatus'] . "\nrainBatteryStatus=" . @$weather_data_weewx['rainBatteryStatus'] . "\noutTempBatteryStatus=" . @$weather_data_weewx['outTempBatteryStatus'] . "\nconsBatteryVoltage=" . @$weather_data_weewx['consBatteryVoltage'] . "\nsupplyVoltage=" . @$weather_data_weewx['supplyVoltage'] . "\ntxBatteryStatus=" . @$weather_data_weewx['txBatteryStatus'] . "\nheatingVoltage=" . @$weather_data_weewx['heatingVoltage'] . "\n"; $txt_weewx_logfile = $txt_dir_weewx . "/export_weewx.txt"; $file = fopen($txt_weewx_logfile, 'w'); fwrite($file, $stringa); fclose($file); } print("success\n"); ?>