Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Shell script timelapse camera crash....

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
thusgaard
LXF regular


Joined: Wed Jun 07, 2006 11:21 am
Posts: 102
Location: Skanderborg, Denmark

PostPosted: Thu Jul 11, 2013 7:49 am    Post subject: Shell script timelapse camera crash.... Reply with quote

Hi

I want to turn my old Lenovo R61 into a timelapse camera. I have a series of scripts that used to work on my HP NC6220, may it rest in pices. I use a Microsoft home cinema HD camera.

But I'm experiencing USB issues, it seams to loose USB connection and not reconnect. I have tried a lot of things but none were successful. Maybe I'm doing it wrong. So now I'm asking for help. And I'll be debugging at the same time myself.

For starters I'm using uvccapture, but I'm using a version that should be better with this camera (http://dp.nonoo.hu/modified-uvccapture/). It was better on the HP pc, but both versions seam to be equally bad on the Lenovo PC.

My script does a lot of odd things to handle the problems I have seen over time.

In front of the script below I have a script with a loop calling it. It does nothing else at the moment.

Code:
#!/bin/bash

# Crash script if not finished in 15 seconds
me=$$
(sleep 15; kill $me >/dev/null 2>&1) & nuker=$!

# Prime camera with a 4 sec delay
 uvccapture -v -d/dev/video0 -x1280 -y720 -D4

# Take picture, with a 3 sec delay
uvccapture -v -d/dev/video0 -x1280 -y720 -D3 -o%Y%m%d%H%M%S.jpg

# Reset USB to make sure that the camera is ready for the next run
./ResetUSB.sh

# Script killer. KILL 
kill $nuker >/dev/null 2>&1



This is the script I call to reset USB:

Code:
#!/bin/bash

#http://billauer.co.il/blog/2013/02/usb-reset-ehci-uhci-linux/


#SYSEHCI=/sys/bus/pci/drivers/ehci_hcd
SYSEHCI=/sys/bus/pci/drivers/ehci-pci
SYSUHCI=/sys/bus/pci/drivers/uhci_hcd

if [[ $EUID != 0 ]] ; then
 echo This must be run as root!
 exit 1
fi
 
if ! cd $SYSUHCI ; then
 echo Weird error. Failed to change directory to $SYSUHCI
 exit 1
fi

for i in ????:??:??.? ; do
 echo -n "$i" > unbind
 echo -n "$i" > bind
done

if ! cd $SYSEHCI ; then
 echo Weird error. Failed to change directory to $SYSEHCI
 exit 1
fi

for i in ????:??:??.? ; do
 echo -n "$i" > unbind
 echo -n "$i" > bind
done


I have not been able to find out where exactly this procedure craches. But I believe (from what I have seen in the terminal window) that the “path” to the webcam changes or becomes unavailable at some point (sometimes on the second picture) and this can only be helped by reconnecting the webcam.

Code:
ERROR opening V4L interface
: No such file or directory


Yesterday I shot almost 1000 pictures at a 24 second interval. I'll make it into a movie and post it later.

Next time my script crashes I'll have a look at lsusb to see if the interface changes. Currently it is:

Code:
Bus 002 Device 002: ID 045e:075d Microsoft Corp. LifeCam Cinema



I hope that some one has a bright idea. I would love to see this work.

Kind Regards J;-)

Edit: Wrong info about LSUSB corrected.
Back to top
View user's profile Send private message Visit poster's website
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8369
Location: Warrington, UK

PostPosted: Thu Jul 11, 2013 9:11 am    Post subject: Reply with quote

The timestamp of the last successful picture will tell you when the problem arose. Have you tried looking in the system log for USB-related errors around that time?
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
thusgaard
LXF regular


Joined: Wed Jun 07, 2006 11:21 am
Posts: 102
Location: Skanderborg, Denmark

PostPosted: Thu Jul 11, 2013 9:38 am    Post subject: Reply with quote

nelz wrote:
The timestamp of the last successful picture will tell you when the problem arose. Have you tried looking in the system log for USB-related errors around that time?


No I have not.
How do look/search for these errors and where (system log?) ?
Back to top
View user's profile Send private message Visit poster's website
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8369
Location: Warrington, UK

PostPosted: Thu Jul 11, 2013 11:03 am    Post subject: Reply with quote

It's usually /var/log/messages, /var/log/current or /var/log/syslog.

All entries are timestamped so just load it into your favourite text viewer, or use the log viewer provided by your distro, and look at what happened around that time.
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
thusgaard
LXF regular


Joined: Wed Jun 07, 2006 11:21 am
Posts: 102
Location: Skanderborg, Denmark

PostPosted: Thu Jul 11, 2013 11:31 pm    Post subject: Reply with quote

I can not see any crashes in the system log:
Very early in todays run

Code:
Jul 11 16:18:50 jesper-ThinkPad-R61 kernel: [24132.008324] hub 2-0:1.0: USB hub found
Jul 11 16:18:50 jesper-ThinkPad-R61 kernel: [24132.008331] hub 2-0:1.0: 6 ports detected
Jul 11 16:18:51 jesper-ThinkPad-R61 kernel: [24132.812087] usb 2-1: new high-speed USB device number 2 using ehci-pci
Jul 11 16:18:51 jesper-ThinkPad-R61 kernel: [24132.961017] usb 2-1: New USB device found, idVendor=045e, idProduct=075d
Jul 11 16:18:51 jesper-ThinkPad-R61 kernel: [24132.961029] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Jul 11 16:18:51 jesper-ThinkPad-R61 kernel: [24132.961037] usb 2-1: Product: Microsoft® LifeCam Cinema(TM)
Jul 11 16:18:51 jesper-ThinkPad-R61 kernel: [24132.961044] usb 2-1: Manufacturer: Microsoft
Jul 11 16:18:51 jesper-ThinkPad-R61 kernel: [24132.962323] uvcvideo: Found UVC 1.00 device Microsoft® LifeCam Cinema(TM) (045e:075d)
Jul 11 16:18:51 jesper-ThinkPad-R61 kernel: [24132.966063] input: Microsoft® LifeCam Cinema(TM) as /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/input/input956
Jul 11 16:18:52 jesper-ThinkPad-R61 kernel: [24134.084282] 2:3:1: cannot get freq at ep 0x82
Jul 11 16:18:52 jesper-ThinkPad-R61 mtp-probe: checking bus 2, device 2: "/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1"
Jul 11 16:18:52 jesper-ThinkPad-R61 mtp-probe: bus: 2, device: 2 was not an MTP device
Jul 11 16:18:53 jesper-ThinkPad-R61 colord: Device added: sysfs-Microsoft-Microsoft®_LifeCam_Cinema_TM_


Just before the last picture

Code:
Jul 11 20:41:01 jesper-ThinkPad-R61 kernel: [39862.432358] hub 2-0:1.0: USB hub found
Jul 11 20:41:01 jesper-ThinkPad-R61 kernel: [39862.432365] hub 2-0:1.0: 6 ports detected
Jul 11 20:41:02 jesper-ThinkPad-R61 kernel: [39863.236117] usb 2-1: new high-speed USB device number 2 using ehci-pci
Jul 11 20:41:02 jesper-ThinkPad-R61 kernel: [39863.385128] usb 2-1: New USB device found, idVendor=045e, idProduct=075d
Jul 11 20:41:02 jesper-ThinkPad-R61 kernel: [39863.385141] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Jul 11 20:41:02 jesper-ThinkPad-R61 kernel: [39863.385149] usb 2-1: Product: Microsoft® LifeCam Cinema(TM)
Jul 11 20:41:02 jesper-ThinkPad-R61 kernel: [39863.385156] usb 2-1: Manufacturer: Microsoft
Jul 11 20:41:02 jesper-ThinkPad-R61 kernel: [39863.386564] uvcvideo: Found UVC 1.00 device Microsoft® LifeCam Cinema(TM) (045e:075d)
Jul 11 20:41:02 jesper-ThinkPad-R61 kernel: [39863.390303] input: Microsoft® LifeCam Cinema(TM) as /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/input/input1611
Jul 11 20:41:03 jesper-ThinkPad-R61 kernel: [39864.508393] 2:3:1: cannot get freq at ep 0x82
Jul 11 20:41:03 jesper-ThinkPad-R61 mtp-probe: checking bus 2, device 2: "/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1"
Jul 11 20:41:03 jesper-ThinkPad-R61 mtp-probe: bus: 2, device: 2 was not an MTP device
Jul 11 20:41:03 jesper-ThinkPad-R61 colord: Device added: sysfs-Microsoft-Microsoft®_LifeCam_Cinema_TM_


Just after the last picture
Code:

Jul 11 20:41:25 jesper-ThinkPad-R61 kernel: [39886.824580] hub 2-0:1.0: USB hub found
Jul 11 20:41:25 jesper-ThinkPad-R61 kernel: [39886.824594] hub 2-0:1.0: 6 ports detected
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.624110] usb 2-1: new high-speed USB device number 2 using ehci-pci
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.772846] usb 2-1: New USB device found, idVendor=045e, idProduct=075d
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.772859] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.772867] usb 2-1: Product: Microsoft® LifeCam Cinema(TM)
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.772874] usb 2-1: Manufacturer: Microsoft
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.774164] uvcvideo: Found UVC 1.00 device Microsoft® LifeCam Cinema(TM) (045e:075d)
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.777914] input: Microsoft® LifeCam Cinema(TM) as /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/input/input1612
Jul 11 20:41:27 jesper-ThinkPad-R61 kernel: [39888.896358] 2:3:1: cannot get freq at ep 0x82
Jul 11 20:41:27 jesper-ThinkPad-R61 mtp-probe: checking bus 2, device 2: "/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1"
Jul 11 20:41:27 jesper-ThinkPad-R61 mtp-probe: bus: 2, device: 2 was not an MTP device
Jul 11 20:41:27 jesper-ThinkPad-R61 colord: Device added: sysfs-Microsoft-Microsoft®_LifeCam_Cinema_TM_
Back to top
View user's profile Send private message Visit poster's website
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8369
Location: Warrington, UK

PostPosted: Fri Jul 12, 2013 12:26 am    Post subject: Reply with quote

thusgaard wrote:
I can not see any crashes in the system log:

Just after the last picture
Code:

Jul 11 20:41:25 jesper-ThinkPad-R61 kernel: [39886.824580] hub 2-0:1.0: USB hub found
Jul 11 20:41:25 jesper-ThinkPad-R61 kernel: [39886.824594] hub 2-0:1.0: 6 ports detected
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.624110] usb 2-1: new high-speed USB device number 2 using ehci-pci
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.772846] usb 2-1: New USB device found, idVendor=045e, idProduct=075d
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.772859] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.772867] usb 2-1: Product: Microsoft® LifeCam Cinema(TM)
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.772874] usb 2-1: Manufacturer: Microsoft
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.774164] uvcvideo: Found UVC 1.00 device Microsoft® LifeCam Cinema(TM) (045e:075d)
Jul 11 20:41:26 jesper-ThinkPad-R61 kernel: [39887.777914] input: Microsoft® LifeCam Cinema(TM) as /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/input/input1612
Jul 11 20:41:27 jesper-ThinkPad-R61 kernel: [39888.896358] 2:3:1: cannot get freq at ep 0x82
Jul 11 20:41:27 jesper-ThinkPad-R61 mtp-probe: checking bus 2, device 2: "/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1"
Jul 11 20:41:27 jesper-ThinkPad-R61 mtp-probe: bus: 2, device: 2 was not an MTP device
Jul 11 20:41:27 jesper-ThinkPad-R61 colord: Device added: sysfs-Microsoft-Microsoft®_LifeCam_Cinema_TM_


This is not right. "New USB hub found" then "New USB device found, idVendor=045e, idProduct=075d" (I take it that's the camera). For some reason your system is losing sight of the USB bus and then rediscovering it, followed by rediscovering the camera. no wonder its device path is changing.

Of course, it may be the program you are running that triggers this behaviour, so you could try something different, like mjpg-streamer.
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
thusgaard
LXF regular


Joined: Wed Jun 07, 2006 11:21 am
Posts: 102
Location: Skanderborg, Denmark

PostPosted: Fri Jul 12, 2013 7:15 am    Post subject: Reply with quote

nelz wrote:

Of course, it may be the program you are running that triggers this behaviour, so you could try something different, like mjpg-streamer.


I'm doing a USB reset in my script, because that made the picture taking a stable process on my HP portable, untill it had a free fall accident.

Without the USB reset I can take 1 or 2 pics before the crash.
Back to top
View user's profile Send private message Visit poster's website
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8369
Location: Warrington, UK

PostPosted: Fri Jul 12, 2013 9:07 am    Post subject: Reply with quote

What does syslog show when you run without the USB reset?
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
thusgaard
LXF regular


Joined: Wed Jun 07, 2006 11:21 am
Posts: 102
Location: Skanderborg, Denmark

PostPosted: Fri Jul 12, 2013 10:30 am    Post subject: Reply with quote

nelz wrote:
What does syslog show when you run without the USB reset?


Testing that right now. have done 100+ pictures and no errors, last week it wouldn't do 2 consecutive pictures.....
Back to top
View user's profile Send private message Visit poster's website
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast