Author Topic: Amcrest camera image rename and move php script? Help please.  (Read 6723 times)

0 Members and 1 Guest are viewing this topic.

Offline tripper22

  • Member
  • *
  • Posts: 25
Amcrest camera image rename and move php script? Help please.
« on: November 12, 2017, 04:32:52 PM »
Since Weather Underground is no longer going to be hosting webcam images I have to do it myself. I currently use GoDaddy to host a Worpress website and I want to use a page of that website to display static images that are uploaded every 10 minutes.

So far:

-Camera is uploading images in nested folders every 10 minutes.
-I need a script that takes the latest *jpg image from the folders to create a current static image with a consistent name.

A user @Ian. with similar issues posted his problem which is similar to mine here. http://www.wxforum.net/index.php?topic=33009.0

I did everything I could following the different instructions from that thread. I have the same error he encountered but I can't resolve it, even though he did.

The errors:

Warning: sort() expects parameter 1 to be array, null given in /home/content/45/3170445/html/krb/wp-content/uploads/webcam//hik.php on line 37

Warning: copy(): The first argument to copy() function cannot be a directory in /home/content/45/3170445/html/krb/wp-content/uploads/webcam/hik.php on line 50

Any help would be greatly appreciated. :)





« Last Edit: November 12, 2017, 04:46:41 PM by tripper22 »

Offline Ian.

  • Forecaster
  • *****
  • Posts: 459
    • Chatteris Weather
Re: Amcrest camera image rename and move php script? Help please.
« Reply #1 on: November 12, 2017, 05:03:55 PM »
I've replied to your PM.
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #2 on: November 12, 2017, 06:04:02 PM »
I am making progress. The reason why it's not working is because the .jpg is not in the root of the upload folder. If I put a .jpg file in the root of upload folder it works fine. It won't work if the .jpg is within folders within the upload folder. The Amcrest camera uploads the images into nested folders and there is no way to change it. I need to find a way to move the newest jpg file from the nested folders and preferably delete everything in there afterwards (files are named 01[R][0@0][0].jpg).

The Wunderground ftp made it work so there must be a way.
« Last Edit: November 12, 2017, 06:10:12 PM by tripper22 »

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Amcrest camera image rename and move php script? Help please.
« Reply #3 on: November 13, 2017, 05:48:25 AM »
Hi,
I guess I have too little info, I need to know exactly what you are trying to achieve, how the folders are structured, the paths etc.

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #4 on: November 13, 2017, 12:55:51 PM »
Okay I will be as detailed as I can be. The camera is an Amcrest IP2M-841. I am using Godaddy's Linux hosting. The camera uploads a jpg image to the server every 10 minutes.

The current file structure:
/webcam/AMC000X5_3R286G/2017-11-11/001/jpg/17/40/01[R][0@0][0].jpg
                                                                               /50/01[R][0@0][0].jpg
                                                                         /18/00/01[R][0@0][0].jpg
                                                                              /10/01[R][0@0][0].jpg
                                                                              /20/01[R][0@0][0].jpg
                                                                              /30/01[R][0@0][0].jpg

I want to rename the newest jpg image to image.jpg and move it to the root of the webcam folder and delete the old files periodically. I attached the php script that I got from Ian's thread. I created the folders in that script to test and see if it works and it does. But it won't work of course with my file structure. Because the script needs a jpg file in the root of the folder. Hopefully that was descriptive enough. :) Thanks!
« Last Edit: November 13, 2017, 01:04:01 PM by tripper22 »

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Amcrest camera image rename and move php script? Help please.
« Reply #5 on: November 13, 2017, 01:17:37 PM »
The problem is that your cam creates new folders for even every minute

Offline droiddk

  • Forecaster
  • *****
  • Posts: 334
Re: Amcrest camera image rename and move php script? Help please.
« Reply #6 on: November 13, 2017, 01:36:51 PM »
Okay I will be as detailed as I can be. The camera is an Amcrest IP2M-841. I am using Godaddy's Linux hosting. The camera uploads a jpg image to the server every 10 minutes.

The current file structure:
/webcam/AMC000X5_3R286G/2017-11-11/001/jpg/17/40/01[R][0@0][0].jpg
                                                                               /50/01[R][0@0][0].jpg
                                                                         /18/00/01[R][0@0][0].jpg
                                                                              /10/01[R][0@0][0].jpg
                                                                              /20/01[R][0@0][0].jpg
                                                                              /30/01[R][0@0][0].jpg

I want to rename the newest jpg image to image.jpg and move it to the root of the webcam folder and delete the old files periodically. I attached the php script that I got from Ian's thread. I created the folders in that script to test and see if it works and it does. But it won't work of course with my file structure. Because the script needs a jpg file in the root of the folder. Hopefully that was descriptive enough. :) Thanks!

uff, crazy structure. No chance you can change that? Changing it would be the "easy" thing to do.

Edit: https://amcrest.com/forum/technical-discussion-f3/ftp-snapshot-folders-t2705.html

Regards
« Last Edit: November 13, 2017, 01:39:59 PM by droiddk »

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #7 on: November 13, 2017, 01:43:46 PM »
The problem is that your cam creates new folders for even every minute
I guess it's whatever time the user sets the snapshot time to be. The file structure cannot be changed. The Weather Underground ftp would grab the newest image from the folders and move it so it could be displayed on their website. There must be a way...
« Last Edit: November 13, 2017, 01:47:05 PM by tripper22 »

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #8 on: November 13, 2017, 01:46:07 PM »
Okay I will be as detailed as I can be. The camera is an Amcrest IP2M-841. I am using Godaddy's Linux hosting. The camera uploads a jpg image to the server every 10 minutes.

The current file structure:
/webcam/AMC000X5_3R286G/2017-11-11/001/jpg/17/40/01[R][0@0][0].jpg
                                                                               /50/01[R][0@0][0].jpg
                                                                         /18/00/01[R][0@0][0].jpg
                                                                              /10/01[R][0@0][0].jpg
                                                                              /20/01[R][0@0][0].jpg
                                                                              /30/01[R][0@0][0].jpg

I want to rename the newest jpg image to image.jpg and move it to the root of the webcam folder and delete the old files periodically. I attached the php script that I got from Ian's thread. I created the folders in that script to test and see if it works and it does. But it won't work of course with my file structure. Because the script needs a jpg file in the root of the folder. Hopefully that was descriptive enough. :) Thanks!

uff, crazy structure. No chance you can change that? Changing it would be the "easy" thing to do.

Edit: https://amcrest.com/forum/technical-discussion-f3/ftp-snapshot-folders-t2705.html

Regards

There is no way to change it. But it's exactly the same as the link you provided droid.  Like I said to Jachym above: The Weather Underground ftp would grab the newest image from the folders and move it so it could be displayed on their website. There must be a way...

Offline droiddk

  • Forecaster
  • *****
  • Posts: 334
Re: Amcrest camera image rename and move php script? Help please.
« Reply #9 on: November 13, 2017, 01:47:30 PM »
Can you pull a image directly from the camera:
http://[ip]/cgi-bin/snapshot.cgi?loginuse=[USERNAME]&loginpas=[PASSWORD]

Remove [] and insert info.

?

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Amcrest camera image rename and move php script? Help please.
« Reply #10 on: November 13, 2017, 01:50:42 PM »
I guess some complex iteration could do this, but you would basicaly have to blindly scan all the possible files/folders (0-23) and for each (0-59) and then check the latest and meanwhile save the image names and then delete them and then delete the folders. The script I originally posted that can get the latest image definitely cannot do this, you would have to have a completely different PHP script for this and question is how fast it would be given all the iterations

Offline droiddk

  • Forecaster
  • *****
  • Posts: 334
Re: Amcrest camera image rename and move php script? Help please.
« Reply #11 on: November 13, 2017, 01:52:23 PM »
I guess some complex iteration could do this, but you would basicaly have to blindly scan all the possible files/folders (0-23) and for each (0-59) and then check the latest and meanwhile save the image names and then delete them and then delete the folders. The script I originally posted that can get the latest image definitely cannot do this, you would have to have a completely different PHP script for this and question is how fast it would be given all the iterations

I agree.

Regards

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #12 on: November 13, 2017, 01:53:29 PM »
Can you pull a image directly from the camera:
http://[ip]/cgi-bin/snapshot.cgi?loginuse=[USERNAME]&loginpas=[PASSWORD]

Remove [] and insert info.

?

I cannot. The camera is in a remote location using a satellite internet connection behind a double nat.

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #13 on: November 13, 2017, 01:56:05 PM »
I guess some complex iteration could do this, but you would basicaly have to blindly scan all the possible files/folders (0-23) and for each (0-59) and then check the latest and meanwhile save the image names and then delete them and then delete the folders. The script I originally posted that can get the latest image definitely cannot do this, you would have to have a completely different PHP script for this and question is how fast it would be given all the iterations

Maybe that's part of the reason why Weather Underground is going to do away with the webcams. I guess i'm hooped :-(

Offline droiddk

  • Forecaster
  • *****
  • Posts: 334
Re: Amcrest camera image rename and move php script? Help please.
« Reply #14 on: November 13, 2017, 01:59:17 PM »
I cannot. The camera is in a remote location using a satellite internet connection behind a double nat.

Ok.
Cant come up with a easy fix.

Regards

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Amcrest camera image rename and move php script? Help please.
« Reply #15 on: November 13, 2017, 02:50:52 PM »
It is normally not that difficult to do, however the structure you have on your server makes it quite complex and would require several nested loops

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #16 on: November 13, 2017, 03:01:25 PM »
Thanks Jachym. I guess I will have to buy a new camera.

Offline bchwdlks

  • Senior Contributor
  • ****
  • Posts: 196
Re: Amcrest camera image rename and move php script? Help please.
« Reply #17 on: November 13, 2017, 03:05:38 PM »
Can you put another ip device at your remote location ? If so you have an easy fix:

  • put a raspberry pi on the remote network
  • collect the images from the camera on the raspberry
  • watch the image directory on the raspberry with inotifywait
  • when it sees a new image let the raspberry ftp it to your web server with any name that works

Offline droiddk

  • Forecaster
  • *****
  • Posts: 334
Re: Amcrest camera image rename and move php script? Help please.
« Reply #18 on: November 13, 2017, 03:07:29 PM »
01[R][0@0][0].jpg  is that the actual name of the file? (example)

Regards


Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #19 on: November 13, 2017, 03:49:44 PM »
Can you put another ip device at your remote location ? If so you have an easy fix:

  • put a raspberry pi on the remote network
  • collect the images from the camera on the raspberry
  • watch the image directory on the raspberry with inotifywait
  • when it sees a new image let the raspberry ftp it to your web server with any name that works

Thanks bch. I was hoping I wouldn't have to go out there. It's a long way. It's possible. I have an older Raspberry Pi lying around. Is there a tutorial that you know of that I can use?

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #20 on: November 13, 2017, 03:50:57 PM »
01[R][0@0][0].jpg  is that the actual name of the file? (example)

Regards

Yes every time from what I can see.

Offline droiddk

  • Forecaster
  • *****
  • Posts: 334
Re: Amcrest camera image rename and move php script? Help please.
« Reply #21 on: November 13, 2017, 03:51:46 PM »

Yes every time from what I can see.

Ok. I have never seen anything like that before  :shock:

Regards

Offline SteveFitz1

  • Forecaster
  • *****
  • Posts: 519
    • Tyler Texas Weather
Re: Amcrest camera image rename and move php script? Help please.
« Reply #22 on: November 13, 2017, 04:14:59 PM »
Have you considered using a small DOS batch script to save an image, then turn around and FTP it to your website in the same script? You could use Windows Task Scheduler to kick off this batch job at whatever interval you want to update the image.

Steve

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #23 on: November 13, 2017, 04:33:06 PM »
Thanks Steve. The camera is in a remote location that won't allow for a windows box unfortunately.

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Amcrest camera image rename and move php script? Help please.
« Reply #24 on: November 13, 2017, 04:41:21 PM »
Maybe a for loop that would look for every hour (0-23) and nested loop for each hour (0-59) and then get the folder content via the glob function and then save them all in an array, sort it and find the latest. Then delete the files, though this is even trickier because PHP cannot delete a folder unless it is empty, so you would need to delete the individual files, then delete the "minute" folder, once it is empty, delete the "hour" folder