Take a look at this:
Ask follow on questions about that smartapp in that thread and people there will be able to help you.