Coherent Blah's

Grocery list on Bluetooth phone

| | Comments (1) | TrackBacks (0)
    Okay, confession time. However much I try to, I cannot remember the grocery list after I reach the store. The best I can do is, count the number of items before leaving home, remember that, and try to come up with as many items at the store to meet that number, and then call wifey to fill up the gaps. I blame NPR that I listen to on my way for this temporary amnesia. It's just more interesting than my grocery list.
    So what's the big deal!! Write the list down, and take it with me? Unfortunately, pen and paper is not that handy, especially with a two year old running around trying his best to snatch away each and every pen he can.
    Okay, pen and paper is not the problem, the problem is, I needed an excuse to do something geeky about the grocery list. What I wanted to do is, quickly type up the list on a [shell|vim|editor] window, and quickly send the list to my cell phone over bluetooth.
    Now, there are many apps available for similar thing, but I find almost all of them too heavyweight for just this. Especially, if I have to fire up a GUI for this, it's too many mouse clicks to be simple enough.
Then again, what are shells for (personally, I think, the coolest thing in a *nix environment is its shell and scripting prowess).

Here is what I did:
  • First, I need the necessary stuff installed for my Ubuntu Laptop. Just do:
sudo apt-get install obexftp
  • Now, I need to find my phone. Run the following command:
~$ obexftp -b
and you should see output like:
Scanning ...
Using 00:18:xx:xx:xx:xx W810i
identify the line by name that is your phone.
  • Test out you can really send a file across. Create a file, say, grocery.txt, and send it to the phone by the following command:
~$ obexftp -b 00:18:xx:xx:xx:xx -p grocery.txt

The interesting thing to note here is, different phones store the file in different locations, based on their make and configuration. For example, on my Sony Ericcson W810i, it stores on the memory stick under Webpages/Saved pages category.

Why is this important? Because, when you create a new grocery list, you should be able to replace (remove + add) the older list. For that, knowing the location is necessary.
  • Find the real location on the phone. The phone, on its interface, can show a different UI to access the file than the real directory structure that it exposes over bluetooth. Use the obexftp's -l command to browse the directory structure. For example, see the session below:
:~$ obexftp -b 00:18:xx:xx:xx:xx -l
Browsing 00:18:xx:xx:xx:xx ...
Channel: 7
Connecting...done
Receiving "(null)"... <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE folder-listing SYSTEM "obex-folder-listing.dtd">
<!--
XML Coder, (C) 2001 Sony Ericsson Mobile Communications AB
-->
<folder-listing version="1.0"><folder name="Phone memory"/>
<folder name="Memory Stick"/>
</folder-listing>
done
Disconnecting...done
:~$ obexftp -b 00:18:xx:xx:xx:xx -l "Memory Stick"
Browsing 00:18:xx:xx:xx:xx ...
Channel: 7
Connecting...done
Receiving "Memory Stick"... <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE folder-listing SYSTEM "obex-folder-listing.dtd">
<!--
XML Coder, (C) 2001 Sony Ericsson Mobile Communications AB
-->
<folder-listing version="1.0"><parent-folder/>
<file name="MEMSTICK.IND" size="0"/>
<file name="MSTK_PRO.IND" size="0"/>
<folder name="DCIM"/>
<folder name="MP3"/>
<folder name="MSSEMC"/>
</folder-listing>
done
Disconnecting...done

...

:~$ obexftp -b 00:18:xx:xx:xx:xx -l "Memory Stick/MSSEMC/Media files/webpage/saved_pages"
Browsing 00:18:xx:xx:xx:xx ...
Channel: 7
Connecting...done
Receiving "Memory Stick/MSSEMC/Media files/webpage/saved_pages"... Sending "Memory Stick"... Sending "MSSEMC"... Sending "Media files"... Sending "webpage"... done
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE folder-listing SYSTEM "obex-folder-listing.dtd">
<!--
XML Coder, (C) 2001 Sony Ericsson Mobile Communications AB
-->
<folder-listing version="1.0"><parent-folder/>
<file name="todo.txt" size="0"/>
<file name="grocery.txt" size="11"/>
</folder-listing>
done
Disconnecting...done
So, at this point of time, I know that my grocery.txt has been sent to the directory "Memory Stick/MSSEMC/Media files/webpage/saved_pages"

  • Now, your script should be like the following. Running it would fire up a vi to enter the list. Replace that line with whatever your favorite editor is (Kate??). Also, remember to replace the PHONE_ADDRESS with bluetooth address of your phone, and the PHONE_PATH with the path you discovered (the one below should work for W810i's with a memory stick). Good Luck!!
#!/bin/bash
export GROCERY_FILE="grocery.txt"
export PHONE_ADDRESS="00:18:xx:xx:xx:xx"
export PHONE_PATH="Memory Stick/MSSEMC/Media files/webpage/saved_pages/$GROCERY_FILE"
export EDITOR=vim
# First create the grocery list.
#
if [ -f $GROCERY_FILE ]
then
echo "File $GROCERY_FILE exists... Re-Editing";
fi

$EDITOR $GROCERY_FILE

if [ -f $GROCERY_FILE ]
then
echo "Removing $GROCERY_FILE from phone location $PHONE_PATH";
obexftp -b $PHONE_ADDRESS -k "$PHONE_PATH" 2> /dev/null
echo "Adding $GROCERY_FILE to phone";
obexftp -b $PHONE_ADDRESS -p $GROCERY_FILE 2> /dev/null
if [ $? -eq 0 ]
then
echo "Added file to phone successfully. Go Shop!!"
else
echo "Failed to add list to phone. Search for paper and pen!!"
fi

else
echo "File $GROCERY_FILE Does not exist... Aborting.";
fi

0 TrackBacks

Listed below are links to blogs that reference this entry: Grocery list on Bluetooth phone.

TrackBack URL for this entry: http://samya.indiangeek.com/new/mtypes/MT/mt-tb.cgi/22

1 Comments

tubelight said:

Neat! A harmless, geeky, experiment for you ... but good education.

Leave a comment

About this Entry

This page contains a single entry by Samya DasSarma published on March 24, 2008 7:08 PM.

Namesake was the previous entry in this blog.

Reading Anandabazar on Firefox/Linux is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.