AnalogClock






Showing posts with label iphone. Show all posts
Showing posts with label iphone. Show all posts

Tuesday, September 9, 2008

iPhone Gurgling Water Noises and Dropped Calls

Updated 2008-10-08:
I traced the source of the problem back to smsnotify. The daemon shell script runs through a tight loop repeatedly checking the voicemail and sms sqlite databases using the sqlite3 command. I edited the script and put some bigger time delays between queries to the databases and a growing delay between vibrating alerts. The smsnotify default time delays can be a little disconcerting when you get a voicemail or SMS while on a call. It also creates a problem when you put down your phone and leave it for an hour. A single voicemail or sms will run down your battery and wake you from your sleep with incessant vibration alerts every 10 seconds.

Here is my version of the smsnotify.sh script. The original post follows it.:

#!/bin/bash

#set -Tvx

SMSNOTIFY_PATH=/usr/local/smsnotify
SMSNOTIFY_SECONDS=30
SMSNOTIFY_COUNT=0
VMNOTIFY_SECONDS=30
VMNOTIFY_COUNT=0

while test 1
do
if [ `echo 'select count(*) from message where \
flags=0;' | sqlite3 \
/var/mobile/Library/SMS/sms.db` -gt 0 ]
then
if [ $SMSNOTIFY_COUNT -lt 2 ]
then
SMSNOTIFY_SECONDS=10
elif [ $SMSNOTIFY_COUNT -lt 4 ]
then
SMSNOTIFY_SECONDS=100
elif [ $SMSNOTIFY_COUNT -lt 5 ]
then
SMSNOTIFY_SECONDS=1000
elif [ $SMSNOTIFY_COUNT -lt 6 ]
then
SMSNOTIFY_SECONDS=2000
else
SMSNOTIFY_SECONDS=9000
fi
#Each parameter to vibrate is 1 more
#vibration, so vibrate 3 times
$SMSNOTIFY_PATH/vibrate 1 1
let SMSNOTIFY_COUNT+=1
else
SMSNOTIFY_SECONDS=30
SMSNOTIFY_COUNT=0
fi
/bin/sleep $SMSNOTIFY_SECONDS

if [ `echo 'select count(*) from voicemail \
where flags & 1 == 0;' | sqlite3 \
/var/mobile/Library/Voicemail/voicemail.db` -gt 0 ]
then
if [ $VMNOTIFY_COUNT -lt 2 ]
then
VMNOTIFY_SECONDS=10
elif [ $VMNOTIFY_COUNT -lt 4 ]
then
VMNOTIFY_SECONDS=100
elif [ $VMNOTIFY_COUNT -lt 5 ]
then
VMNOTIFY_SECONDS=1000
elif [ $VMNOTIFY_COUNT -lt 6 ]
then
VMNOTIFY_SECONDS=2000
else
VMNOTIFY_SECONDS=9000
fi
#vibrate 2 times
$SMSNOTIFY_PATH/vibrate 1
let VMNOTIFY_COUNT++
else
VMNOTIFY_SECONDS=30
VMNOTIFY_COUNT=0
fi
/bin/sleep $VMNOTIFY_SECONDS

#This program sleeps for 5 seconds then checks
#how long it's been sleeping. If it's been more
#than 10 seconds the phone has slept and it exits,
#allowing the loop to continue
#$SMSNOTIFY_PATH/waitforsleep
done

# vim:ai:et:sw=4:sts=4:


I've been having all kinds of iPhone trouble acquiring signal, dropping calls, and the signal going in and out. My voice sounded incoherent and was always accompanied by the gurgling sound of electronic water.

The problem was of my own creation. I had jail broken my phone and installed all kinds of apps that had launched many server processes. Most of the server processes failed to stop with a simple:

su -c 'launchctl stop com.sourceforge.netatalk.afpd'

I ended up having to do a:

su -c 'for i in /Library/LaunchDaemons/*;
do launchctl unload $i;done'

I did the same for the ones installed in /System/Library/LaunchDaemons. I just limited the file glob expression to the services I wanted to unload as a plain * would probably force me to have to restore my iPhone. i.e. I used com.apple.mDNS* and other more specific file globbing expressions.

Since all of my calls had garbled audio quality my first phone call verified that I had fixed the problem. Also the fact that I had a crystal clear conversation with only one bar was the proof I needed. As I hadn't been able to get my iPhone to dial most of the time with 3 bars.

The only caveat is that inorder to renable these services you have to load the profiles again rather than doing a simple stop and then start. I'll have to look into how those .plist files should be written so that the start and stop work properly and maybe even have launchd do the listening for some of the services rather than having all of those services running unnecessarily.

Hope this helps. It saved me from carrying a separate phone just for conversations.

Friday, August 1, 2008

Automate ssh-agent loading and sharing across logins

When the keychain package is not available on a platform I usually use a simple script in my .profile or .bash_profile or .bashrc that loads or reuses an existing ssh-agent.  This allows me to load an ssh key once and use it in any terminal without any additional effort. Like so:

# ssh-agent sharing
if [ -e ~/.ssh-agent ]; then
. ~/.ssh-agent
else
eval $(ssh-agent|tee ~/.ssh-agent)
fi

I tried sprucing it up for Terminal on my iPhone because it starts 4 simultaneous terminals at the same time. My first attempt was a dismal failure. I misguidedly added the following above the previous script:

# ssh-agent sharing - failed multiple concurrent launch attempt
if { ps awx |grep ssh-agent ; } then
if [ -e ~/.ssh-agent ]; then
. ~/.ssh-agent
else
killall ssh-agent
rm ~/.ssh-agent
fi
fi

I ended up finding a relatively simple file locking script:

function my_lockfile ()
{
TEMPFILE="$1.$$"
LOCKFILE="$1.lock"
{ echo $$ > $TEMPFILE ; } &> /dev/null || {
echo "You don't have permission to access `dirname $TEMPFILE`"
return 1
}
ln $TEMPFILE $LOCKFILE >& /dev/null && {
rm -f $TEMPFILE
return 0
}
kill -0 `cat $LOCKFILE` >& /dev/null && {
rm -f $TEMPFILE
return 1
}
echo "Removing stale lock file"
rm -f $LOCKFILE
ln $TEMPFILE $LOCKFILE >& /dev/null && {
rm -f $TEMPFILE
return 0
}
rm -f $TEMPFILE
return 1
}

Which makes it relatively easy to rewrite the script like so:

until my_lockfile ~/.sshagent; do
sleep 1
done

if [ -z "$SSH_AGENT_PID" ]; then
if [ -e ~/.ssh-agent ]; then
. ~/.ssh-agent >& /dev/null
else
eval $(ssh-agent|tee ~/.ssh-agent) >& /dev/null
fi
fi

if ! ps -p "$SSH_AGENT_PID" >& /dev/null; then
eval $(ssh-agent|tee ~/.ssh-agent) >& /dev/null
fi

rm -f ~/.ssh-agent.lock

The import part is the loop at the beginning of the script and the rm at the end.
I could add in a timeout but the lockfile script is pretty good at cleaning up unused lock files. Worst case scenario you can Ctrl-C to break out of the startup script.
If you need help with the basics of using ssh keys and the ssh-agent follow this link:
Automate a Remote Login Using SSH - Webmonkey
Blogged with the Flock Browser

Monday, February 18, 2008

Fix for iPhone not syncing some video

I use the iPhone. Before upgrading iTunes and the iPhone firmware I was able to load video on the iPhone using iTunes. Now I have problems getting the same video to sync to the iPhone. I also have problems getting some video podcasts to sync to the iPhone that used to sync just fine.

I did some research using ffmpeg -i on some of the files that synced and some of the ones that wouldn't sync. I found that the video that wouldn't sync all had something in common. The aspect ratio was showing up as 0:1 (for DAR and PAR).

I googled some iPhone video conversion parameters and found an ffmpeg parameter that gets any video to sync, -aspect 16:9. Now I just need to come up with a set of ffmpeg video conversion parameters that play for more than a few seconds before the audio drops out and the video stops playing.

Gonna try doing an ffmpeg copy and report back the results.

Update 2008-03-08

I found out a lot. The 0.49 version of ffmpeg that comes with ffmpegX works fine. It was either patched to deal with the QuickTime mpeg4 issues or uses default setting that work with QuickTime. Turns out QuickTime needs square pixels for mpeg4 and the harddup video filter to avoid a frame copy problem when it converts to the mpeg4 format as the duplicate frame flag gets lost in the translation. I haven't figured out how to do this with ffmpeg. But all the info on this issue is dealt with in a section of the mencorder documentation under the heading QuickTime. Mencoder uses ffmpeg under the "-lavc" flag.

I'll update with the details after I perform some tests.