Essentially, I found this code from the Blynk example browser
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!");
// 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!");
}
}
But I don’t really understand it and why/if I would need to set it up in this format, it truly isn’t sinking in.
So, in plain language, this code is saying if the button is pressed (reading a high) then the integer value of isButtonPressed will read 0? Then the next line of code appears to be an if statement, but I don’t see a typical “if this is true then that” type of argument that follows.
I am sorry, I can’t understand logically how this code is playing a role to push an in-app notification?
As I now have separated the BLYNK_WRITE Codes, I am wondering why I couldn’t add the “Blynk.notify” statement as per the following code?
BLYNK_WRITE(V21) // Executes when the value of virtual pin 21 changes (By Smartwatch)
{
if(param.asInt() == 1)
{
// execute this code if the switch widget is now ON
digitalWrite(4,HIGH); // Set NodeMCU D2 to HIGH
timer.setTimeout(1000L, []() { // Wait 1s then...
digitalWrite(4,LOW); // Set NodeMCU D2 to LOW
Blynk.virtualWrite(V21,0); // Turn the widget attached to V21 Off
Serial.println("Spare Relay activated by Smartwatch");
Blynk.notify("Spare Relay activated by Smartwatch");
}); // END of Lambda Function
}
else
{
// execute this code if the switch widget is now OFF
digitalWrite(4,LOW); // Set NodeMCU D2 to LOW
}
}
Yes I do, with the following settings
Notify when hardware goes offline - Set to ON (and I do get those ones)
I’m not sure what’s happening with your notifications.
They work for me when using the Frankfurt cloud server, but I guess you’re using a different server.
Do notifications work if you do them with an API call?
But is what I have below in my code - specifically the line with Blynk.Notify meant to work? Do I have to add anything else perhaps?
Blynk.virtualWrite(V21,0); // Turn the widget attached to V21 Off
Serial.println("Spare Relay activated by Smartwatch");
Blynk.notify("Spare Relay activated by Smartwatch");
I have also setup Blynk to connect to Singapore server (closest to me in Australia) IP address of 188,166,206,43 - not sure if the IP address is right through, pinched that from elsewhere in this forum.
Add details :
• Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
• Smartphone OS (iOS or Android) + version
• Blynk server or local server
• Blynk Library version
• Add your sketch code. Code should be formatted as example below.