Blynk App Push Notifications

So I have been playing around with the Blynk app and i must say it is wonderful. The only trouble I am having is to get the Push notifications to work correctly or at all. I have the the simple sample program downloaded to my core and can toggle things on and off using the app but would like to configure a push button on the core side to send me a push notification. Has anybody written a simple program like this or have some insight for me.

Thanks

Here is the simple program I am using and would like to add in the push button feature to mess around with.

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"

char auth[] = "authentication code goes here";

void setup() 
{
Serial.begin(9600);
delay(5000);
Blynk.begin(auth);
}

void loop() {
Blynk.run();
}

I have poked around on the Blynk forums but they do not list anything too specific for programming Particle devices.

you need to use Blynk.notify() for that.

Documentation:
http://docs.blynk.cc/#widgets-notifications-push-notifications

Here is an example of usage
https://github.com/blynkkk/blynk-library/blob/master/examples/Widgets/PushNotification/PushNotification.ino

So i got things to work, sort of. I was able to reference the code Escko posted and get my code to work and recieve a push notification when the button is pressed on pin D0. But running this code now makes my Core act up, it losses its wifi signal and eventually starts to blink Red. I am thinking it has something to do with the interrupt portion of my code since i have read that interrupts can do this sort of thing. Thanks for you help, i am close now but just need to figure this out. Here is the code i am running.

#include "blynk/blynk.h"

char auth[] = "";

void setup() {
    Serial.begin(9600);
    delay(5000);
    Blynk.begin(auth);
    pinMode(D0, INPUT_PULLUP);
    attachInterrupt(D0, notifyOnButtonPress, CHANGE);
}

void notifyOnButtonPress() {
    int isButtonPressed = !digitalRead(D0);
    if (isButtonPressed) {
        BLYNK_LOG("Button is pressed");
        Blynk.notify("D0 is pressed");
    }
    }
void loop() {
Blynk.run();
}

@CadDesigner, doing Blynk stuff in the ISR is not good practice as it blocks the ISR until completed. It is better practice to set a flag which you sample in loop() and call the Blynk functions once set. :wink:

So I was able to move the Blynk function to the loop portion of my code and this seemed to help only a little bit with causing my Core to crash but it still does crash. Is there something I am overlooking in my code that I should also add in? My current code is below:

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"

char auth[] = "";

volatile int state = HIGH;

void setup() {
    Serial.begin(9600);
    delay(5000);
    Blynk.begin(auth);
    pinMode(D0, INPUT_PULLUP);
    attachInterrupt(D0, notifyOnButtonPress, CHANGE);
}

void notifyOnButtonPress() {
    state = !state;
    }

void loop() {
Blynk.run();
    if(state == LOW) {
        Blynk.notify("D0 is pressed");
        delay(1000);
    }
}

Thank You.

@CadDesigner, with a CHANGE interrupt, you will need an external pull-up or pull-down as attachInterrupt() overrides the pinMode() you did. Also, you don’t do any debounce of the button so the interrupt will fire multiple times. You may want to do a search on “interrupt button debounce” in the forum for help on that. :wink:

1 Like

@CadDesigner, after some corrective messages from @ScruffR, I now realize that the pinMode() call prior to attachInterrupt() IS the correct thing to do. I seem to have forgotten the attachInterrupt() documentation I had originally contributed!!! :smirk:

Nonetheless, the bounce issue still exists. There is no need to have a CHANGE interrupt since I assume that by pulling high, the button is connected to GND. As such, you should use a FALLING interrupt which will reduced the bounce “chatter” on the ISR. You can also NOT use an interrupt and use a polled approach like the clickButton library available on the IDE. :grinning:

1 Like

I will give this a try tonight and see if I can get things working properly. Thanks for all the advice, it is much appreciated.

1 Like

please share the code if its working