Core to Push notification

Hi @Hootie81

That should work OK–username and password need to be base64 encoded for basic auth, but you can do that offline in advance and just put the encoded values in your program.

I'm not sure if this answers your question, but we're working on webhooks support that operates by subscribing to published events on your behalf. You can register an eventName, and a url to receive a POST request with the contents of your event. :slight_smile:

1 Like

So that sounds like you should be able to put a hook in that will POST to Prowl for you from the Cloud? HTTPS??

Would it also make sense to roll your own Push Notifications on the Tinker app? Less layers to deal with, and the phone apps are open source so it would be a great model for someone that needed a custom app for a product that requires push notifications... like me :smile:

1 Like

Oooh, hmm. I think maybe pushing notifications to the mobile apps is a different challenge, since then you need to first push messages to Apple, for them to push out to devices. I agree that that would be an awesome feature, and something we should pursue, if only to make it easier for mobile apps to respond to events from the Core.

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

I have this working, mainly due to the help in this page, so thanks to all…
I had a lot of trouble and eventually used wireshark to sniff the internet connection to see where I was having trouble.
One thing I noticed is that the following, sends an IP packet per line, as opposed to a single packet with a concatenated string containing all the content. Seems that being a good netizen would encourage me to send a single packet…
Is there a way to “hold” the transmission until I am finished printing the string? I did achieve that by building the string first and then using a single “client.print(oneString)”, but wondering if the multiple packets is known and expected…

client.print("GET ");
client.print(url);
client.println(“HTTP/1.0”);
client.print("Host: ");
client.println(hostname);

As opposed to

client.print(oneString);

Hey Guys,
So I’m back to an earlier question, I’m at sea on a ship right now, and I’ve got notifications coming to my phone via pushing box. Works great when we have internet, but for a variety of reasons, we lose the internet periodically, and for various amounts of time. When the spark core and my iPhone are both connected to the internet, no problems, my notifications arrive in short order, maybe up to 5 seconds.

But if there is no internet connection, I’m out of luck, and will miss the notification. Any ideas how I can make a notification system from Sparkcore over the LAN to my iPhone (or android) without using the cloud?
Doing the whole thing locally?

Maybe figuring out how to spoof the prowl notification that pushingbox uses?

Jim

its possible to have the core send a get request to an ip on the same wifi network when the cloud is out of reach. my doorbell does this to the XBMC server running on my HTPC when the net is down. i get the video displayed on the tv when someone presses the button.

it may be possible to host a server locally, something like the newtifry one for android, but then the push notification actually goes thru apple or google servers.

i wonder if you could make an email server on a spark and have your phone check it regularly.

@jimbol, you can have one MQTT Broker (like Open Source Mosquitto Broker) running on your local server. On your iOS or Android devices download any MQTT Client application or create one yourself and point to your local server. This could enable you to do local push. Is something like this you are looking for?

Hey All!

I met someone at JSConf who wanted to build a Core to Push Notification example, and he posted his results / code here: https://github.com/davidfekke/sparkpushexample

The only caveat was he used the (limited beta) webhooks feature that’s still under development, but hopefully that is a helpful example! :smile:

Thanks,
David

Thanks David Fekke for the example and thanks @Dave for posting it here. @Dave I suppose WebHooks are created at the Spark Cloud and from firmware code we make a call to it, am I correct or is it too early to ask such a question?

Hi @krvarma,

Good question! Happy to describe the process I currently have in place.

Currently a webhook operates as a subscriber to events coming from your cores, or public events. When it receives an event it’s listening for, it will POST that event info / data to a url of your choosing. You will be able to create and manage webhooks using the API, and the CLI as a wrapper. This way you can easily trigger any webhook using a simple publish call from your Cores. :smile:

This should easily enable usages like IFTTT, and any kind of notifications / third-party side effects without having to keep opening up connections to the events’ SSE endpoints.

Thanks!
David

1 Like

Thanks @Dave for the info. Eagerly waiting for the WebHook release.

1 Like

Hi Guys,
I’m working on this notification project, and having some issues.

The code is below.

When I run this, and trigger a notification, the serial data stops, and about 14 seconds later the Sparkcore resets. I’m also seeing a trouble code, flashing red LED, SOS and then 8 flashes, telling me it’s out of heap memory. But I don’t know why!

Any Ideas?

Tx

const char server[] = "api.pushingbox.com";
const char url[] = "replace with your devid";  //replace with your devid
TCPClient myTCP;

int spinning = 0;
int sentOnce = 0;
unsigned long TimeSinceChange = 5000;
unsigned long TimeSinceNotification = 20001;
unsigned long TimeOfChange = 0;
unsigned long TimeOfNotification = 0;
void interruptCode();
void checkTimes();


void setup() {
    //pinMode(D0, INPUT_PULLDOWN);
    pinMode(D1, INPUT_PULLDOWN);
    attachInterrupt(D0, interruptCode, CHANGE);
    Serial.begin(9600);
    
}
 



void loop() {
    
    checkTimes();
    
}






void sendGetRequest(const char * server, const char * url)
{
     Serial.println("here we go...");
            
    RGB.control(true);
    RGB.color(250, 0,0); //Change LED to Red to indicate nofication
    RGB.control(false);
    
    if (myTCP.connect(server, 80)) {
        myTCP.print("GET ");
        myTCP.print(url);
        myTCP.println(" HTTP/1.0");
        myTCP.println("Connection: close");
        myTCP.print("Host: ");
        myTCP.println(server);
        myTCP.println("Accept: text/html, text/plain");
        myTCP.println();
        myTCP.flush();
    } 
    TimeOfNotification = millis();
}



void interruptCode()
    {
        TimeOfChange = millis();
        if (sentOnce == 0) {
            sendGetRequest(server, url);
            sentOnce = 1;
        }
        
    }

void checkTimes()
    {
        TimeSinceChange = (millis() - TimeOfChange);
        TimeSinceNotification = (millis() - TimeOfNotification);
         Serial.print("tsn...");
         Serial.println(TimeSinceNotification);
         Serial.print("tsc...");
         Serial.println(TimeSinceChange);
         Serial.print("SentOnce...");
         Serial.println(sentOnce);
         
        if (TimeSinceChange > 20000) {
            sentOnce = 0;
          }
    }

Hi @jimbol,

Make sure you’re closing your socket, and try putting a small delay before you close it, so:

void sendGetRequest(const char * server, const char * url)
{
     Serial.println("here we go...");
            
    RGB.control(true);
    RGB.color(250, 0,0); //Change LED to Red to indicate nofication
    RGB.control(false);
    
    if (myTCP.connect(server, 80)) {
        myTCP.print("GET ");
        myTCP.print(url);
        myTCP.println(" HTTP/1.0");
        myTCP.println("Connection: close");
        myTCP.print("Host: ");
        myTCP.println(server);
        myTCP.println("Accept: text/html, text/plain");
        myTCP.println();
        myTCP.flush();

        delay(250);
        myTCP.stop();
    } 
    TimeOfNotification = millis();
}

Thanks,
David

Thanks David,
I’ll try that. I’ve experimented with myTCP.stop(); but didn’t have any luck. Maybe the delay will help. I just got Prowl to work directly without pushing box, which helped and didn’t have the core resetting after sending.
Jim

1 Like