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:


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.


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.

$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


1 Like

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