Let's build a simple project to send a notification to the smartphone or tablet for the button press event. You can use the same hardware setup you built in the previous section:
Listing 5.3 shows the complete code to send the notification from your Raspberry Pi:
Listing 5.3: sending notification for the button press event
The Blynk.notify() function allows you to mention your own message as a notification:
Blynk.notify("Yaaay... button is pressed!");
Refer to the following steps:
- Type in the preceding code by opening the main.cpp file. Then, save and exit the nano text editor by pressing Ctrl + O, followed by Enter, followed by Ctrl + X.
- After that, build the project by issuing the following command:
pi@raspberrypi:~/blynk-library/linux $ ./build.sh raspberry
- Now, you can run the project with the auth token associated with the project:
pi@raspberrypi:~/blynk-library/linux $sudo ./blynk --token=ca7bed1c92214503a65de8e20164994f
- To test the application, press and release the push button attached to BCM_GPIO pin 23 of the Raspberry Pi. Immediately, you will get a notification on your smartphone or tablet:
A Blynk notification