Tweet Low Battery

With is recipe you can automatically post to twitter that your phone is low on power to alert family and friends.

All you need to do is change the screen name @PhOnXe (this is my phones twitter accout) and your onxToken which you can get at  tweetonX. You also want to change your tweet that is posted. With this script I am not forsure on the exact percent that battery is low but my guess is 10-15%. I have verified that this does work. Check is out @PhOnXe.

To use this on{X} Recipe, simply copy the code below and modify if needed.

 // Triggers the function when the screen unlocks
        device.battery.on('low', function (signal){

 
 // Initializing variables
        var twitter = { screenName : "PhOnXe",onxToken : "XXXXXX" } ;
        var tweet = encodeURI('My battery is below 10%, I will die soon. -PhOnXe');
    

        // Sends tweet using TweetOn{X}
        device.ajax(
            {
                url: 'http://tweetonx.com/api/tweet/'+twitter.screenName+'/'+twitter.onxToken+'/?t='+tweet,
                type: 'GET',
                headers: { 'Content-Type': 'application/xml' }
            },
             function onSuccess(body, textStatus, response){
                var parsedBody;
                if(!body){
                    var error = {};
                    error.message = 'invalid body format';
                    error.content = body;
                    console.error('error: ',error);
                }
                console.info('Status: ' + body);
            },
            function onError(textStatus, response){
                var error = {};
                error.message = textStatus;
                error.statusCode = response.status;
                console.error('error: ',error);
            }
        );
        
        });

Recipe Wall

946

Views