Webcam Block - WU dropping them
- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Webcam Block - WU dropping them
WU support finally admitted on wxforum today that they are dropping webcams completely due to staff cutbacks and constant problems with their webcam system. I've uploaded my webcam images to WU for years and referenced a URL to WU to display them in my webcam block in MT. It looks like that's no longer going to be available as an option. My webcam uploads to WU started failing a couple of days ago - along with a whole bunch of other folks all around me.
Here is my problem. The ftp option built into my webcams works fine to send images to my own server. The issue is I have no control over naming those image files as well as limited control over the directory they upload to. I'm only interested in the most recent image to display in the block. The image name has date/time information added to the end of each file name. In the example below I uploaded the file to my /camera1 directory and the camera ftp adds the additional sub-directories to the string. To the jpg file name 'Schedule' it adds the date/time of the upload _20171111-121247. To the next file 5 minutes later it added _20171111-121747 to the file name, and so on.
How do I get the most recent image, rename it, and place it to a specific URL that I can use in the webcam block? I use a Meteobridge to update data to my api in case that offers a usable service to do it.
http://www.highlandlakesweather.net/cam ... 121249.jpg
Here is my problem. The ftp option built into my webcams works fine to send images to my own server. The issue is I have no control over naming those image files as well as limited control over the directory they upload to. I'm only interested in the most recent image to display in the block. The image name has date/time information added to the end of each file name. In the example below I uploaded the file to my /camera1 directory and the camera ftp adds the additional sub-directories to the string. To the jpg file name 'Schedule' it adds the date/time of the upload _20171111-121247. To the next file 5 minutes later it added _20171111-121747 to the file name, and so on.
How do I get the most recent image, rename it, and place it to a specific URL that I can use in the webcam block? I use a Meteobridge to update data to my api in case that offers a usable service to do it.
http://www.highlandlakesweather.net/cam ... 121249.jpg
Dave G

- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Help php experts. I understand very little about php. I'm an old html guy. I found this just now on wxforum, and I see Jachym contributed at one point. If I create a php file with this code and place it in the directory where my images are uploading (see the post above), will it find the latest jpg and rename it image.jpg whenever it is executed? I can then create an event on my Meteobridge to execute that script on a schedule, and I will have the latest 'image.jpg' displaying in my webcam block with a URL to it. Here is a copy/paste from that forum:
This simple script will find jpg's in the folder where the script is and save the latest as image.jpg, can be used with a cron-job.
<?php
if ($images = glob("*.jpg") ) {
rsort($images);
$img = $images[0];
$newfile = 'image.jpg';
copy($img, $newfile);
}
?>
This simple script will find jpg's in the folder where the script is and save the latest as image.jpg, can be used with a cron-job.
<?php
if ($images = glob("*.jpg") ) {
rsort($images);
$img = $images[0];
$newfile = 'image.jpg';
copy($img, $newfile);
}
?>
Dave G

- Jachym
- Site Admin

- Posts: 1686
- Joined: Fri Aug 18, 2017 10:12 pm
- Location: Brno, Czech Republic
- Station model: WH1080
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Yes, this should work, it could theoretically be implemented directly in the webcam update script
- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Thanks Jachym. Since for now I'm only interested in the current image I can setup a 'script execution' on my Meteobridge which is basically the same as a cron job to update the image, correct? I'll just need to periodically delete the old images in the directory. I think I saw somewhere on that forum a script to automatically delete the old images, but I can work that out later.
Dave G

- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Jachym:
This script worked the first time I ran it and successfully created image.jpg and copied the latest jpg to image.jpg. It didn't work after that. It looks like it won't create and overwrite an existing file already named image.jpg. If I manually delete it and run the script again the latest image again is copied correctly to image.jpg. Any idea how I can modify the script to work when the file image.jpg already exists in the directory?
This script worked the first time I ran it and successfully created image.jpg and copied the latest jpg to image.jpg. It didn't work after that. It looks like it won't create and overwrite an existing file already named image.jpg. If I manually delete it and run the script again the latest image again is copied correctly to image.jpg. Any idea how I can modify the script to work when the file image.jpg already exists in the directory?
Dave G

- Jachym
- Site Admin

- Posts: 1686
- Joined: Fri Aug 18, 2017 10:12 pm
- Location: Brno, Czech Republic
- Station model: WH1080
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Try using file_get_contents instead of the copy syntax, that should work
- Jachym
- Site Admin

- Posts: 1686
- Joined: Fri Aug 18, 2017 10:12 pm
- Location: Brno, Czech Republic
- Station model: WH1080
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Alternatively you could try deleting the image before copying it by using
unlink("image.jpg");
unlink("image.jpg");
- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
unlink didn't work. I have the script set to run from Meteobridge at 10 minutes and the camera files set to upload every 10 minutes. When the script runs before a file newer than image.jpg uploads from the camera, image.jpg deletes and doesn't write again until the scripts runs the next time. In the meantime it is a broken image link. I placed it before rsort.
I don't know php well enough to understand how to use file_get_contents. Could you show me how to put it in this script to try it? Thanks.
<?php
if ($images = glob("*.jpg") ) {
rsort($images);
$img = $images[0];
$newfile = 'image.jpg';
copy($img, $newfile);
}
?>
I don't know php well enough to understand how to use file_get_contents. Could you show me how to put it in this script to try it? Thanks.
<?php
if ($images = glob("*.jpg") ) {
rsort($images);
$img = $images[0];
$newfile = 'image.jpg';
copy($img, $newfile);
}
?>
Dave G

- Jachym
- Site Admin

- Posts: 1686
- Joined: Fri Aug 18, 2017 10:12 pm
- Location: Brno, Czech Republic
- Station model: WH1080
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Try this:
<?php
if ($images = glob("*.jpg") ) {
rsort($images);
file_put_contents(file_get_contents($images[0]), "image.jpg");
}
?>
<?php
if ($images = glob("*.jpg") ) {
rsort($images);
file_put_contents(file_get_contents($images[0]), "image.jpg");
}
?>
- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
That doesn't seem to do anything. When I run it from my browser it doesn't return an error or anything, and no file is created or changed.
Dave G

- Jachym
- Site Admin

- Posts: 1686
- Joined: Fri Aug 18, 2017 10:12 pm
- Location: Brno, Czech Republic
- Station model: WH1080
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Strange.... I will look at it tomorrow
- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Jachym:
This seems to be working. I moved the unlink command outside the routine to the top. Now I'm fighting the Meteobridge executing the script. It works when I test it manually, but it fails on the schedule. If I have to I can set up a cron job.
<?php
unlink("image.jpg");
if ($images = glob("*.jpg") ) {
rsort($images);
$img = $images[0];
$newfile = 'image.jpg';
copy($img, $newfile);
}
?>
Thanks again for all your help.
This seems to be working. I moved the unlink command outside the routine to the top. Now I'm fighting the Meteobridge executing the script. It works when I test it manually, but it fails on the schedule. If I have to I can set up a cron job.
<?php
unlink("image.jpg");
if ($images = glob("*.jpg") ) {
rsort($images);
$img = $images[0];
$newfile = 'image.jpg';
copy($img, $newfile);
}
?>
Thanks again for all your help.
Dave G

- Jachym
- Site Admin

- Posts: 1686
- Joined: Fri Aug 18, 2017 10:12 pm
- Location: Brno, Czech Republic
- Station model: WH1080
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
OK,
I think the problem is synchronization. Rather than renaming the latest file I could customize the updateWebcam.php script to read the latest file regardless of its name (sorting it chronologically and then using the latest). However what I then need from you is the exact name of the folders where the images are on your server, what their names are. Ideally a screenshot and I will set a relative path to the crons folder.
Email it to me and I will see what can be done.
I think the problem is synchronization. Rather than renaming the latest file I could customize the updateWebcam.php script to read the latest file regardless of its name (sorting it chronologically and then using the latest). However what I then need from you is the exact name of the folders where the images are on your server, what their names are. Ideally a screenshot and I will set a relative path to the crons folder.
Email it to me and I will see what can be done.
- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
This is working fine now. I set my Meteobridge to execute the sort/filename script for each of the cameras every 5 minutes and each camera to ftp an image every 10 minutes. It appeared the MB event wasn't working, but actually my host wasn't allowing the second camera ftp access to send new pictures. As soon as I closed FileZilla the new images started loading, even though all ftps have their own credentials setup. Interesting.
Now what would really help is to add a command to the end of the script to delete all the image files in the directory except 'image.jpg' after the new 'image.jpg' file has been written. They all start with 'Schedule' for example 'Schedule_20171111-121249.jpg' and have that same format with different numbers on them. Could probably be done with wildcard characters if I knew how. Then I wouldn't have to go in and manually delete the old files periodically. What I'm reading suggests not using unlink to do that as that command doesn't actually delete the files, just unlinks the name and technically leaves the file on the server. It works to change the name but not good for deleting files. Again I know very little about php at this point so I only know what I read about it.
Now what would really help is to add a command to the end of the script to delete all the image files in the directory except 'image.jpg' after the new 'image.jpg' file has been written. They all start with 'Schedule' for example 'Schedule_20171111-121249.jpg' and have that same format with different numbers on them. Could probably be done with wildcard characters if I knew how. Then I wouldn't have to go in and manually delete the old files periodically. What I'm reading suggests not using unlink to do that as that command doesn't actually delete the files, just unlinks the name and technically leaves the file on the server. It works to change the name but not good for deleting files. Again I know very little about php at this point so I only know what I read about it.
Dave G

- Jachym
- Site Admin

- Posts: 1686
- Joined: Fri Aug 18, 2017 10:12 pm
- Location: Brno, Czech Republic
- Station model: WH1080
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
I always used unlink and it does delete the file, Im not even aware of any other command that would delete stuff. I think it is like on a PC. When you delete something, even from the Trash, it still is on the HDD, but it looks as empty space and would be overwritten if necessary
- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Good to know. I certainly trust you before all the noise on the internet.
Dave G

- Jachym
- Site Admin

- Posts: 1686
- Joined: Fri Aug 18, 2017 10:12 pm
- Location: Brno, Czech Republic
- Station model: WH1080
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
so just show me a few examples of the names of the files you want to delete
- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Here is a snip from FileZilla. They all start 'Schedule' followed by the date and time numbers added.
I'm thrilled I finally have these cameras off of Wunderground. I would have done it a long time ago if I had realized there was a way to deal with the screwy file naming on these Foscam cameras. A support tech emailed someone on Wxform they were announcing the end of the webcams this week and all cameras will be dropped from WU on December 15. I know you are not surprised at all and neither am I at this point.
I'm thrilled I finally have these cameras off of Wunderground. I would have done it a long time ago if I had realized there was a way to deal with the screwy file naming on these Foscam cameras. A support tech emailed someone on Wxform they were announcing the end of the webcams this week and all cameras will be dropped from WU on December 15. I know you are not surprised at all and neither am I at this point.
- Attachments
-
- filenames.JPG (67.16 KiB) Viewed 19057 times
Dave G

- Jachym
- Site Admin

- Posts: 1686
- Joined: Fri Aug 18, 2017 10:12 pm
- Location: Brno, Czech Republic
- Station model: WH1080
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
the you could try:
if ($images = glob("Schedule_*.jpg") ) {
foreach($images as $img){
unlink($img);
}
}
placing this at the end of the script
if ($images = glob("Schedule_*.jpg") ) {
foreach($images as $img){
unlink($img);
}
}
placing this at the end of the script
- dmgould
- Forecaster

- Posts: 173
- Joined: Sat Aug 26, 2017 2:43 am
- Location: Divide, Colorado, USA
- Station model: Davis Pro 2 Plus Wireless
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
Jachym:
Thanks. That works fine. I also figured out I don't need to 'unlink' the image.jpg if I apply the same 'if' condition you listed. If I'm starting to understand this code better -- I probably don't need that second 'if' condition since it's the same as the first one. Here is what I'm using. The only files left in the directory are the current image.jpg and this script file I'm triggering from the Meteobridge, exactly what I wanted. Now I can start configuring the webcam plugin referencing the current image from both cameras.
<?php
if ($images = glob("Schedule_*.jpg") ) {
rsort($images);
$img = $images[0];
$newfile = 'image.jpg';
copy($img, $newfile);
}
if ($images = glob("Schedule_*.jpg") ) {
foreach($images as $img){
unlink($img);
}
}
?>
Thanks. That works fine. I also figured out I don't need to 'unlink' the image.jpg if I apply the same 'if' condition you listed. If I'm starting to understand this code better -- I probably don't need that second 'if' condition since it's the same as the first one. Here is what I'm using. The only files left in the directory are the current image.jpg and this script file I'm triggering from the Meteobridge, exactly what I wanted. Now I can start configuring the webcam plugin referencing the current image from both cameras.
<?php
if ($images = glob("Schedule_*.jpg") ) {
rsort($images);
$img = $images[0];
$newfile = 'image.jpg';
copy($img, $newfile);
}
if ($images = glob("Schedule_*.jpg") ) {
foreach($images as $img){
unlink($img);
}
}
?>
Dave G

- Jachym
- Site Admin

- Posts: 1686
- Joined: Fri Aug 18, 2017 10:12 pm
- Location: Brno, Czech Republic
- Station model: WH1080
- Software: Meteobridge
- Contact:
Re: Webcam Block - WU dropping them
looks good to me