Shell script timelapse camera crash....

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Shell script timelapse camera crash....

Postby thusgaard » Thu Jul 11, 2013 6:49 am

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: Select all
#!/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: Select all
#!/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: Select all
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: Select all
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.
thusgaard
LXF regular
 
Posts: 102
Joined: Wed Jun 07, 2006 10:21 am
Location: Skanderborg, Denmark

Postby nelz » Thu Jul 11, 2013 8:11 am

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)
User avatar
nelz
Site admin
 
Posts: 8469
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby thusgaard » Thu Jul 11, 2013 8:38 am

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?) ?
thusgaard
LXF regular
 
Posts: 102
Joined: Wed Jun 07, 2006 10:21 am
Location: Skanderborg, Denmark

Postby nelz » Thu Jul 11, 2013 10:03 am

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)
User avatar
nelz
Site admin
 
Posts: 8469
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby thusgaard » Thu Jul 11, 2013 10:31 pm

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

Code: Select all
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: Select all
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: Select all
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_
thusgaard
LXF regular
 
Posts: 102
Joined: Wed Jun 07, 2006 10:21 am
Location: Skanderborg, Denmark

Postby nelz » Thu Jul 11, 2013 11:26 pm

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

Just after the last picture
Code: Select all
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)
User avatar
nelz
Site admin
 
Posts: 8469
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby thusgaard » Fri Jul 12, 2013 6:15 am

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.
thusgaard
LXF regular
 
Posts: 102
Joined: Wed Jun 07, 2006 10:21 am
Location: Skanderborg, Denmark

Postby nelz » Fri Jul 12, 2013 8:07 am

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)
User avatar
nelz
Site admin
 
Posts: 8469
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby thusgaard » Fri Jul 12, 2013 9:30 am

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.....
thusgaard
LXF regular
 
Posts: 102
Joined: Wed Jun 07, 2006 10:21 am
Location: Skanderborg, Denmark


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests