Help implementing sketch into (C++) code on Raspberry Pi

I need to implement a notification sketch into the following code:

void MotionDetection::soundAlarm() {
    int playing;

    ca_context_playing(snd_context, 0, &playing);
    if (playing == 0)
        ca_context_play(snd_context, 0, CA_PROP_EVENT_ID, "alarm-clock-elapsed", nullptr);

    printf("[ERROR] >>>>>  NO MOVEMENT DETECTED!!!!!!\n\n");

Do I just need to copy and paste the sketch into this task somewhere such as before the printf?
This bit of code is where the project alarms from but I want it to be able to notify to my phone through Blynk too… if any of you could help I would be ecstatic! What sketch would you recommend to use?

I am guessing you are using WiringPi and not NodeJS.

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

Aside from having the notification Widget in your project, all you technically need is one line…

Blynk.notify("My Notification Message");

So just put it somewhere and try it out for yourself :wink: Be aware of the limits though… you might want additional if() and timer code to prevent too much too fast

Limitations :

Maximum allowed body length is 120 symbols.
Only 1 notification per 15 seconds is allowed

Just search this forum for other topics concerning the keyword notification for further examples of limiting action.

Hi @Gunner thanks for getting back to me so quickly! I’ve just put that one line in, tried it in multiple places within that code but it’s not sending any notification to my phone… (yes blynk is turned on, on my phone haha) … any ideas? Thanks, Tom

Did you do this?

@Gunner Yeah, I’ve got it working for DHT22 notifications… :slight_smile: but still wont work in the code above…

Well, we need more info… App version, Cloud or Local Server, Version of library you are using (again assuming WiringPi), FULL code, etc.

Also, try loading this example and see if it works or not.

https://examples.blynk.cc/?board=Raspberry%20Pi&shield=System%20default&example=Widgets%2FPushNotification%2FPushNotification_Button

Oh okay, cheers…
Android app version 2.19.2
Local server (not paying for Cloud server as far as I’m aware)
Wiring Pi 2.44

I’ll try that example now and let you know… thanks @Gunner :slight_smile:

@Gunner Can’t seem to get that working :confused:

What Blynk library version are you using? There was a issue with notifications and an older library version a while ago… EDIT - nope… it was the App version, not the Library :blush:

Strangely the only other RPi based notification issue I could find here was also with WiringPi, and no clarification if App upgrade helped or not… Perhaps notifications don’t work with WiringPi? @vshymanskyy is this a question for you?

Notifications should work as soon as other library functions do. Like virtualWrite, etc.

@Gunner, it’s probably me not doing something simple right… i’ll go through all the examples and keep trying and will message later in the week if I have no joy still :persevere: :slight_smile:

Back to this previous question… i’ve managed to update the script to include the Blynk.notify but when I try to rebuild the project it fails… think it needs an import or include Blynk at the top?
This is wha’;s currently there:

    #include <opencv2/opencv.hpp>
    #include "MotionDetection.hpp"
    #include <time.h>

    import BlynkLib?

and this is the part of the script which the notify has been added to:

void MotionDetection::soundAlarm() {
    int playing;

ca_context_playing(snd_context, 0, &playing);
if (playing == 0)
    ca_context_play(snd_context, 0, CA_PROP_EVENT_ID, "alarm-clock-elapsed", nullptr);
printf("[ERROR] >>>>> NO MOVEMENT DETECTED!!!!!!\n\n");
Blynk.notify("EMERGENCY!!! NO MOVEMENT DETECTED!!!");

Thanks again haha :blush:

Wait???.. are you using Python here?

Kind of important to let us know what is going on at the beginning of the topic :stuck_out_tongue:

Also… is this the same project as your other topic… if so, they should be in the same topic as the issue(s) seem to be the same “how to code Python in Blynk”, not separate as it is just adds to the confusion.

No sorry this is a C++ project on a different Raspberry Pi … thought i’d mentioned that at the beginning when I first opened this question… I’ve got 1 RPI using this C++ code and another i’m using Python on and trying to use Blynk on both… getting confusing I know, apologies!

Ok, than separate topics is OK :slight_smile:

But your code for including Blynk Library in C++ (WiringPi) is different then you listed above.

Look through here for more info…

Ah okay, ill have a read through that and have a play… Like I said, its getting confusing haha! Thanks

Do I need to include all of these at the top of that script?

#ifdef RASPBERRY
 #include <BlynkApiWiringPi.h>
#else
 #include <BlynkApiLinux.h>
#endif
#include <BlynkSocket.h>
#include <BlynkOptionsParser.h>

static BlynkTransportSocket _blynkTransport;
BlynkSocket Blynk(_blynkTransport);
#include <BlynkWidgets.h>

:confounded::confused:

Heh… again, I don’t use WiringPi for my RPi :blush: I find the similarities are close enough (to Arduino/ESP), but not quite, to confuse me… so I use NodeJS instead.

But if I had to guess (and I am :wink: ) then yes… primarily because that is a tutorial topic, thus close enough to a boilerplate as far as I am concerned.