PageLines- v65oai7fxn47qv9nectx.pngSoftware, especially the headless/daemon/embedded kind,  often needs a way to notify users about events.  Typically this is done by displaying a message on-screen, writing to a log file, or sending e-mail.   Advanced notification solutions, like Amazon’s Simple Notification Service, can send notifications via SMS message, and allow recipients to subscribe and unsubscribe at any time.   For many Makers and Tinkerers though, SNS is overkill and not free (Makers love free stuff!).

Here is how you can use Twitter to send near real-time SMS notifications to a dynamic subscriber list for free.

  1. Create a Twitter account for your device / software / gizmo
  2. Decide if the account should be public (any one can follow) or private (only approved users can follow).
  3. Get an API key for the new Twitter account
  4. Use a twitter client in the language of your choice to ‘tweet’ when certain events occur
  5. Subscribers now follow the newly-created Twitter account (after approval, if the account is private)
  6. Subscribers enable Mobile Notifications for the new Twitter user to receive SMS messages on new tweets.

The benefits of this approach are:

  • SMS messages are sent for free.
  • Notifications are more immediate than email.
  • Users control their own subscription and notification settings.
  • Notifications can be made public (anyone can follow) or private (must be approved before following).

Personally, I like using the Twitter4j API in Java applications.  See an example of Twitter sending notifications when it’s tea time  by visiting the Tweetpot project.  Here’s a excerpt from Tweetpot.java:

/**
* Send a tweet using the application and auth credentials specified
* in twitter4j.properties. See http://dev.twitter.com to obtain the
* required api keys.
*/
    private void tweet() {
        SimpleDateFormat df = new SimpleDateFormat("h:mm:ss a");
        String message = "The kettle has boiled (" + df.format(new Date()) + ")";
        Twitter twitter = new TwitterFactory().getInstance();
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, message);
        try {
            twitter.updateStatus(message);
        } catch (TwitterException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.ERROR, ex);
        }
    }

 

Tagged with →  
Share →

Leave a Reply

Your email address will not be published.