BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Notify widget help


#1

Hello community!

I’m using a local blynk server running on a raspi, I have already set up 5 ESP-12’s with DHT22 sensors which are working just fine.

• Hardware model + communication type = Lolin ESP-12 NodeMCU v3
• Smartphone OS (iOS or Android) + version = iOS 12.1 with notifications enabled
• Blynk server or local server = local server
• Blynk Library version = 0.5.4

Now I’m trying to add a PIR sensor to a new device so it would give me a push notification in case of a movement is detected. First of all I wanted to test the notification itself so I uploaded the example from the docs site.
In this example I’ve added a LED widget to test if the code is working.

So the code is pretty much just a basic example to test the notify widget: when I short the PIN on the ESP, following happens:

  • a blue LED lits on the board
  • I get a serial message “Button is pressed”
  • in the app, the LED widget lit (well, for the 2-3rd try that is)

But I don’t receive a push message at all!

Here comes my code, what’s wrong with it? (token, wlan, IP data are changed)

Kind Regards,
Daniel


/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  Simple push notification example

  App project setup:
    Push widget

  Connect a button to pin 2 and GND...
  Pressing this button will also push a message! ;)
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxyy";
char ssid[] = "xxcc";
char pass[] = "vvbb";

WidgetLED led2(V2);
BlynkTimer timer;



void notifyOnButtonPress()
{
  // Invert state, since button is "Active LOW"
  int isButtonPressed = !digitalRead(2);
  if (isButtonPressed) {
    Serial.println("Button is pressed.");

    // Note:
    //   We allow 1 notification per 5 seconds for now.
    Blynk.notify("Yaaay... button is pressed!");
    
    led2.on();
    

    // You can also use {DEVICE_NAME} placeholder for device name,
    // that will be replaced by your device name on the server side.
    //Blynk.notify("Yaaay... {DEVICE_NAME}  button is pressed!");
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass, IPAddress(11,11,11,11), 2121);

  // Setup notification button on pin 2
  pinMode(2, INPUT_PULLUP);

  // Attach pin 2 interrupt to our handler
  attachInterrupt(digitalPinToInterrupt(2), notifyOnButtonPress, CHANGE);
  
}

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


#2

Did you add in the Notification widget?

Also, the way you have it set, it can potentially send multiple notifications in a second, minute, etc… (every interrupt trigger), but only one notification every 5 minutes is allowed.

You need to have some form of logic control with flags and timers. Search this forum for similar notification examples.


#3

Of course I did.

Regarding the multiple notifications - shouldn’t it at least send one push notification and ignore the rest?


#4

We never know what people forget :stuck_out_tongue_winking_eye: Did you set it for high priority and make sure all App permissions are enable in the phone settings?

I don’t know… i have never tried to spam a Blynk server before (Cloud or Local).

If it receives many at once, a distinct possibility with button bounce, then it may simply block them all for an indeterminate period. I am sure they have that limitation, and tell everyone about it in the Docs and test script commentary, for a reason.

You could always try a sketch with a single test notification at device boot.


#5

Thank you for the tip Gunner!

Following your advice, wrote a simple code so every time the device boots, it sends a push message - and it’s working!

It really seems that the server (local or otherwise) simply ignoring the messages if it deems to be a spam.


#6

Makes sense… just like email spam filters, etc… even this forum will block your posts if spammy activity is suspected.

Now you can look at timed routines. For example…

  • Upon triggering action, look if “Trigger Flag” is ON or OFF
  • If ON, then do nothing, return to monitoring for trigger
  • If OFF, set Flag to ON, then send notification, then start timeout timer (that will clear Flag back to OFF after x time).

Here is some examples of timers… there is one for a Latch that does what I just referred too.


#7

will do that, thank you!