“Agent” iOS Push

In many of my projects I am doing (they are all just tinkering, not anything I plan to sell), I want push notifications of events to my personal iOS application I am writing. For the time being I am doing this by having an app on my computer which the imp talks to and having that app send out push.

It would be TOTALLY awesome! If there was a way I could upload my cert+private key to the imp servers, and allow the server side agent to send the push notifications. Since I am talking about 1 or 2 clients (which the agent could keep track of and decide at send time which to send to), I don’t see how it is a big scaling issue.

I know I have asked about pushing the past, but now that I have actually done it, there really isn’t that much to sending the push itself (to Apple’s servers)…

Hi man, can you post a example of push notification ios with imp? It will help-me to start! Tanks a lot!

You can’t push directly from imp. Right now, I have a “server” that sits on my home computer and when it decides to push, it does the push.

I am re-writing everything to do agent/imp and trying to get rid of my server. Basically I am going to have a “push-relay” server which sits on my server. Basically, anything will be able to do an HTTP(s) post which will push to an iOS device. I am trying to make it generic so it is usable for more then just imp.

So the imp agent will just do an http.post to this push relay server, and that will do the actual iOS push.

The push-relay server is only complex because I am making it generic (and have some security to prevent someone from spamming with my push relay). The actual iOS push isn’t that hard (once you figure out how to load the cert/private key). You can probably find examples online.

It would be AWESOME, if there was a built in IMP way to do this.

The IMP servers would need:

  • Cert/Private Key
  • A way for clients to register for wanting push

then the agents would just say server.iOSPush({});

Of course that is really up to the IMP people to provide (would be nice, as I am not supporting 1000s of users, just 1 or 2, with my home automation, so the overhead for me is quite high).

Another simple way to do push notifications is through a service like Prowl. I have prowl setup on my iOS device, and I can push messages to it the following function in my agent:

`function Push(_apiKey, _application, _event) {
local url = "https://api.prowlapp.com/publicapi/add?"
local query = { apikey = _apiKey, application = _application, event = _event };
url += http.urlencode(query);

server.log("Posting: " + url);
local result = http.post(url, {}, "").sendsync();
server.log(result.statuscode + ": " + result.body);


Yeah, downside is that it pushes to Prowl and not to your custom app:-(

I see… you want to push directly to an app (I actually did not know that was possible). I’m going to get someone to play around with this, and see if it’s possible using agents. We’re wondering if we can find a way to “export” the certificates binary data and store it as a blog in the agent…

We’ll let you know what we find :slight_smile:

Also take a look at some services like Urban Airship

There are apparently a lot of services to push to apps :slight_smile:

A number of push directly from Agents & via intermediate servers using https://pushover.net/

Well, I want to push on behalf of my app (in my case, it is a house “status” app, which has all of what is going on in my house, which is reported by several imps). I want the notifications to be relevant and to take me to my actual app.

I am looking into Parse and Urban Airsphip, still trying to figure out if it is possible to use one of these from an agent.

Ok, so I am looking more into Parse and it may do what I want.

It basically becomes a push gateway for your app.
It is free (for the amount I am going to send).
It lets you push with http (so it will work with agents).

Additionally, their tutorials have start to finish tutorial on push (that can sometimes be tricky, making sure you get the right certs, setting up your bundle identifiers correctly, etc).

Ok, I take it back. IMP doesn’t need this service. parse.com works great (as detailed above). Here is a simple function to post a push to all devices (registered) listening on channel “CHANNEL” (note, Channel, and the api keys are placeholders).

function sendPush(body, sound, info)
local where = {};
local data = {};

where.channels <- "CHANNEL";

if (body) data.alert <- body;
if (sound) data.sound <- sound;
if (info) data.userInfo <- info;

local bodyStr = http.jsonencode({"where": where, "data": data});
local post = http.post("https://api.parse.com/1/push",

server.log("Sending push payload " + bodyStr);

local handler = function(m)
    if (m.statuscode == 200)
        server.log("Push succeeded", kLogVerbose);
        server.log("Failed to send push");



With Parse, Kinvey etc you will need to obtain Push keys from Apple & Google respectevly as they are generic Baas providers, That isn’t the case with Urban Airship or any of the other Push notification providers.

Yes, true, this all requires a paid apple developer account, but I needed that for my custom iOS app (I guess an Electric Imp iOS app where I can just have my data in there would do what I want).

It would be nice if there was a generic Cloud Service to do this and a generic Apple App that could handle notifications from imp enabled devices. I submitted this idea to Quirky http://www.quirky.com/ideations/537314 regardless as to where it goes I intend to prototype it for my own entertainment. A simple configurable way to send notifications would really simplify development

And for you Pushover users. a simple function to send an alert message with title.

`USER_KEY <- “put your user key here”;
APP_TOKEN <- “put your application api token here”;
POST_URL <- “https://api.pushover.net/1/messages.json”;
function pushOver(title, msg) {

local post = http.urlencode({

local headers = {
    "Content-Type": "application/x-www-form-urlencoded"
local response = http.post(POST_URL, headers, post).sendsync();
server.log(response.statuscode + ": " + response.body);


Can I push notifications to my facebook app using the same method?

You can send Email to post your status on Facebook…

Well, as far as I can see (will be testing this soon) you can use Google’s GCM (Google Cloud Messaging) for free Push notifications to an Android device.

GCM, in addition to Push notification to Android devices, can also be used for Push to iOS devices (although much more complicated).

Using GCM with Android is free, just need an Android developer account. Not sure what the cost would be to use GCM with iOS devices as it still uses (ultimately) Apple Push Notification Service (I think I read somewhere about a one-time Apple fee for developers of $99?).

Here is a link to an article about using GCM to push to iOS devices: https://cloud.google.com/developers/articles/ios-push-notifications