Sending pushover messages via Electric Imp

I recently got an Electric Imp april board and developer card.  I’m really digging it and am planning on making a monitoring solution for my garage (including doors and freezer temps).  In addition to reporting the data back via the agent, I wanted to add the ability to send a pushover notification to my phone on events.  I wrote a quick method to do this, and thought it might be useful to others.

//Agent code
function send_pushover(title, message, priority) {
    local url = "https://api.pushover.net/1/messages.json";
    local token = "XXX_TOKENGOESHERE_XXX";
    local user = "XXX_USERGOESHERE_XXX";
    local headers = { "Content-Type": "application/x-www-form-urlencoded" };
    local data = {
        "token": token,
        "user": user,
        "message": message
        "title": title,
        "priority": priority
    }
    local body = http.urlencode(data);
    local response = http.post(url, headers, body).sendsync();
}

//To use, send_pushover("My title", "My message", 0)
//For more on priority see https://pushover.net/api#priority
This entry was posted in Development and tagged , , . Bookmark the permalink.