Ok Google Voice commands to push buttons

Thanks PeteKnight

  1. Ok

  2. I have found this snippet of code in the examples

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

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

I can’t wrap head around that, could you elaborate more on int isButtonPressed = !digitalRead(2);?
I see that we are first declaring an integer of ‘isButtonPresses’ with the default reading being 2?
I am completely lost around this and I have even had my morning coffee.

I thought I could add some code after Blynk.virtualWrite such as

Serial.println("Device activated by Smartwatch");
Blynk.notify("Device activated by Smartwatch");

Doing this shows up the text in the serial monitor, but I don’t get a push notification. I have reinstalled the app and ensured the app has full access to android notifications and can override Do Not Disturb etc. Can I do it this way?

  1. All good then, that will happen.
  2. Perfect - great article, done in 5 mins.

Thanks for you guidance.

I have no idea how this relates to your question, but here here goes…

This is basically saying “set the integer variable isButtonPressed to the opposite of the result that you get when you do a digital read on pin GPIO2”

The exclamation mark operator “!” means NOT, which is effectively saying “the opposite of”, so if digitalRead(2) returns HIGH then the result od applying a NOT operator will be LOW (or 0 as it’s an integer).

Do you have the Notification widget in the app?

Have you tested doing an OTA upload?

Pete.

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)
  • Offline ignore period - set to 1 min
  • Priority - High

Yes, worked well.

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?

Pete.

Not sure how to test for that exactly.

I am connected via 45.55.96.146

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");

The New York server.

No, that should be it.

Pete.

I guess from that I just need to enter in my browser http://blynk-cloud.com/withmytokenhere/notify?

this returns a “page cannot be found”.

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.

I just can’t figure this out, have done everything to ensure Blynk has the highest of access and overriding the phone’s do not disturb.

I even uninstalled the app and rebooted the phone.

The only notification I seem to get is when the device went offline.

If anyone can shed light as to why I’m not getting blynk notifications, I would love to know.

Bump

I’m still stuck with this.

Are there any other Blynk experts who can help uncover why I don’t get notifications?

anyone??

@Amsok what version of the Blynk library are you using?
Is it 0.6.1 or one of the beta versions?

Pete.

Hi Pete,

It is version 1.0.0-Beta.3.

That’s your problem!

Read this topic…

Pete.

ok will do

Thank you so much, that was it and notifications work now!!

That’s good.
Next time though, it’s worth including all the information that’s requested when you initially create the topic :wink:

Pete.

Do you mean by default we should be stating the library used irrespective of the topic?

When you create a new topic and choose “need help…” as the category you get this info…

Before creating the topic

  1. Search forum for similar topics
  2. Check http://docs.blynk.cc and http://help.blynk.cc/
  3. 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. :point_up:Code should be formatted as example below.

Pete.