Convert FTP upload to HTTP upload of realtime.txt from Meteobridge

I’ve been using FTP to upload my Meteobridge data to realtime.txt in the PWS weather template until today. For some as yet unanswerd reason from my hosting support, FTP no longer allows files to be deleted/renamed from external FTP access.

As I understand it the Meteobridge setup for the PWS template is to upload the template to the Meteobridge and then schedule a FTP push service from the Meteobridge to the PWS/realtime.txt file. In the background it is uploading to mb_realtime.txt and then renaming to realtime.txt.

I wondered if a HTTP push might do the job? This was my solution. I created a PHP script, borrowed from the Weather34 template, that takes a comma separated list of weather fields and writes it out as a realtime.txt file. This script looks like this:

<?php ini_set ('display_errors', 'Off');error_reporting(E_ALL); $filename = "realtime.txt";if( isset($_GET['d']) ) {$string=$_GET['d'];file_put_contents($filename, str_replace(",","\n",$string));header('Content-Type: text/plain');echo "success";} ?>

The meteobridge HTTP service looks like this:

https://<domain>/pws/livedata.php?d=[DD]/[MM]/[YYYY],[hh]:[mm]:[ss],[th*temp-act:--],[th*hum-act.0:--],[th*dew-act:--],[wind*avgwind-act:--],[wind*wind-act:--],[wind*dir-act:--],[rain*rate-act:--],[rain*total-daysum:--],[thb*seapress-act:--],[wind*dir-act=endir:--],[wind*wind-act=bft.0:--],m/s,C,hPa,mm,--,[thb*seapress-delta60:--],[rain*total-monthsum:--],[rain*total-yearsum:--],[rain*total-ydaysum:--],[thb*temp-act:--],[thb*hum-act:--],[wind*chill-act:--],[th*temp-delta60:--],[th*temp-dmax:--],[th*temp-dmaxtime.ij:--]:[th*temp-dmaxtime.kl:--],[th*temp-dmin:--],[th*temp-dmintime.ij:--]:[th*temp-dmintime.kl:--],[wind*avgwind-dmax:--],[wind*avgwind-dmaxtime.ij:--]:[wind*avgwind-dmaxtime.kl:--],[wind*wind-dmax:--],[wind*wind-dmaxtime.ij:--]:[wind*wind-dmaxtime.kl:--],[thb*seapress-dmax:--],[thb*seapress-dmaxtime.ij:--]:[thb*seapress-dmaxtime.kl:--],[thb*seapress-dmin:--],[thb*seapress-dmintime.ij:--]:[thb*seapress-dmintime.kl:--],[mbsystem-swversion:--],[mbsystem-buildnum:--],[wind*wind-max10:--],[th*heatindex:--],--,[uv*index-act:--],[sol*evo:--],[sol*rad-act:--],[wind*dir-avg10:--],[rain*total-sum60:--],--,[mbsystem-isday:--],--,[wind*dir-avg10:--],--,m,--,[mbsystem-daylength:--],--,--,[uv0index-dmax:--]

It does the same job but removes FTP. Has anyone else had to do such a workaround?

1 Like

Hi jasonmfarrow,

Yes, others are doing that also.
F.i. direct custom upload from users with an ecowitt station works in the same way.
The pwsxWD/ecowitt/index.php script is the receiving script for those users.

HTTP upload is also faster and takes less resources compared to FTP.

But you should add one extra “check” field which contents you can check if not some script-kiddy is trying to do nasty things.

Succes,
Wim

What are the details of check are you suggesting, Wim?

Ecowitt sends a standard string with the device hardware id (MAC address) with as name “PASSKEY”

The first time a device uploads that MAC address is encode and stored in the ecowitt folder.

All uploads will now checked, they should have the same PASSKEY field.
A

$pass_k_stored = './my_check.txt';
if (file_exists ($pass_k_stored)  )
     {  $passkey1 = file_get_contents ($pass_k_stored); }
else {  $passkey1 = false;}

if (array_key_exists ('PASSKEY',$_POST) )      
     {  if     (base64_encode ($_POST['PASSKEY']) == $passkey1) # upload is allowed as passkey is correct. 
             {  $data_stored = $filename1;                      # set the file to store the upload
                unset ($_REQUEST['PASSKEY']);}                  # remove passkey from upload

        elseif ($passkey1 == false)                             # we did not upload to thise webserver in the past
             {  $string = base64_encode ($_POST['PASSKEY']);    # encode passkey
                $result = file_put_contents ($pass_k_stored,$string);   # save in local file
                }

Succes,
Wim

1 Like

Understood. I’ll give it a look. Cheers.