<<< Adding a Ecowitt Data Source to WeeWX >>>
Configure HTML Server
Create Area to Accept Ecowitt Data
First create a directory on the Rasberry PI to where the Ecowitt data will be uploaded, I called mine ecowitt and set the permissions to world write just to be certain that all of the data will arrive
pi@raspberrypi:~ $ sudo su - root@weewx:~# mkdir /var/www/html/ecowitt root@weewx:~# chmod 777 /var/www/html/ecowitt pi@weewx:/var/www/html $ ls -al total 44 drwxr-xr-x 4 root root 4096 Jan 13 09:09 . drwxr-xr-x 3 root root 4096 Mar 22 2020 .. drwxrwxrwx 2 root root 12288 Jan 16 11:30 ecowitt -rw-r--r-- 1 root root 10701 Jan 12 17:22 index.html -rw-r--r-- 1 root root 70 Jan 13 08:56 mike.php drwxr-xr-x 5 root root 4096 Jan 16 11:30 MountWeather
Create PHP file to Accept Ecowitt Data
We configured the Ecowitt app to look for a file called index.php in this directory, so now we are going to create that file
The protocol used to HTTP POST the data is not easily found anywhere, you can deduce it from the source code of the Ecowitt http gateway on Github, but I followed the guide posted by Jonas, which instructs you how to set up index.php with the following code:
Note: that the directory we open is the directory that we have just created and is the only code that you may need to change
pi@raspberrypi:~ $ sudo su - root@weewx:~# vi /var/www/html/index.php <?php $date = date_create(); $handle = fopen("/var/www/html/ecowitt/" . date_timestamp_get($date), "w"); $result = print_r($_POST, true); print_r(error_get_last()); fwrite($handle, $result); fclose($handle); ?>
And now code should start to appear in the directory that we have just created, we can check thia as follows
pi@raspberrypi:~ $ ls -al /var/www/html/ecowitt/ total 28 drwxrwxrwx 2 root root 12288 Jan 16 12:27 . drwxr-xr-x 4 root root 4096 Jan 13 09:09 .. -rw-r--r-- 1 www-data www-data 338 Jan 16 12:25 1610799909 -rw-r--r-- 1 www-data www-data 338 Jan 16 12:26 1610799970 -rw-r--r-- 1 www-data www-data 338 Jan 16 12:27 1610800031