Here's what I came up with:
First off, to make use of all of this, you'll need an Android phone or tablet or an iPhone and a copy of the Pushover client app installed. As well as having an account you'll also need to create an application on their site so that you have an application key (it's free if you're going to be sending yourself fewer than 7,500 notifications in a month).
Once done all that's left is to make use of llHTTPRequest to POST a message. Here's the test script I wrote, with a dressed-up function for sending a message that could be useful in any number of scripts:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////// | |
// Set your app and user token here. Note that you can, on the | |
// PushOver site, create delivery groups so you can deliver a single | |
// notice to multiple users. The delivery group key is then used as | |
// the user key. | |
string APP_TOKEN = "<paste your app token here>"; | |
string APP_USER = "<paste your user token here>"; | |
////////////////////////////////////////////////////////////////////// | |
// Constants for the PushOver parameters. | |
string PUSHOVER_DEVICE = "device"; | |
string PUSHOVER_TITLE = "title"; | |
string PUSHOVER_URL = "url"; | |
string PUSHOVER_URL_TITLE = "url_title"; | |
string PUSHOVER_PRIORITY = "priority"; | |
string PUSHOVER_TIMESTAMP = "timestamp"; | |
string PUSHOVER_SOUND = "sound"; | |
////////////////////////////////////////////////////////////////////// | |
// Send a push message via PushOver. | |
key SendPushMessage( string sToken, string sUser, string sMessage, list lExtra ) | |
{ | |
// Main part of the data. | |
string sData = "token=" + APP_TOKEN + | |
"&user=" + APP_USER + | |
"&message=" + llEscapeURL( sMessage ); | |
// Add any optional parameters. | |
integer iExtra = llGetListLength( lExtra ); | |
integer i; | |
for ( i = 0; i < iExtra; i += 2 ) | |
{ | |
sData += "&" + llList2String( lExtra, i ) + "=" + | |
llEscapeURL( llList2String( lExtra, i + 1 ) ); | |
} | |
// Send the push message. | |
return llHTTPRequest( "https://api.pushover.net/1/messages.json", [ | |
HTTP_METHOD, "POST", | |
HTTP_MIMETYPE, "application/x-www-form-urlencoded" | |
], sData ); | |
} | |
////////////////////////////////////////////////////////////////////// | |
// Default state. | |
default | |
{ | |
///////////////////////////////////////////////////////////////// | |
// Respond to touch. | |
touch_start( integer _ ) | |
{ | |
SendPushMessage( APP_TOKEN, APP_USER, | |
"I was just touched by " + llDetectedName( 0 ) + ".\n\n" + | |
"They were " + (string) llVecDist( llDetectedPos( 0 ), llGetPos() ) + "m away.", [ | |
PUSHOVER_TITLE, "Touch alert!", | |
PUSHOVER_SOUND, "bugle", | |
PUSHOVER_URL, "http://antonyfairport.blogspot.com/", | |
PUSHOVER_URL_TITLE, "Antony Fairport" | |
] ); | |
} | |
} |
(when you create an application on the Pushover site you get to assign an icon, hence the nifty Z&A logo) and when I select the notification it takes me to the Pushover app with the full details:
This is, of course, a really trivial example. But it could be handy for some less-trivial uses such as pinging you when your region has come back from a restart, or letting you know when its status has changed, or letting you know when someone's been booted out of your workshop, etc.
No comments:
Post a Comment