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

Difficulty in triggering virtual pin using ifttt and webhook

#1

Hi guys,
I am trying to trigger the virtual pin 3 on my nodemcu using an ifttt applet that involves using webhooks but am not able to figure out what to fill in the webhooks part of the applet. ifttt requires two different applets for turning on and off the virtual pin. The virtual pin goes on when it receives a value of 1 from the button on the dashboard. Below is a snapshot of the applet and the code used on the nodemcu.
Would really appreciate if anyone could help me out on this one!! @Gunner

#define BLYNK_PRINT Serial


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

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*************";
char pass[] = "*************";

Servo servo;

void cradle() {
//you begin your own personal code for servo here
  int pos;

  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    servo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    servo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 15ms for the servo to reach the position
  }
//your personal code for servo should end here
}


BLYNK_WRITE(V3) 
{
  int pinValue = param.asInt();
  if (pinValue == 1) {    // if Button sends 1
    cradle();             // start the function cradle
    Blynk.run(); // Run rest of show in-between waiting for this loop to repeat or quit.
    int pinValue = 0;  // Set V3 status to 0 to quit, unless button is still pushed (as per below)
    Blynk.syncVirtual(V3); // ...Then force BLYNK_WRITE(V3) function check of button status to determine if repeating or done.
  }
}

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

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  servo.attach(4); //attaches servo to pin 4 (D2 on node mcu)
}

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

#2

Is better to use GET rather than PUT.

You’re located in India, but using the IP address of Blynk New York cloud server, so I guess that’s wrong.

What IP do you get when you ping Blynk-cloud.com ?

Pete.

0 Likes

#3

this is what i get when i ping blynk-cloud.com
12

0 Likes

#4

Interesting,
Oops like your IPS is doing some strange things with DNS, but at least the IP address used in your IFTTT recipe is correct.

Do a search and find some of the other examples I’ve posted using GET with IFTTT and try that approach.

Pete.

0 Likes

#5

sure will do. But do you think its an issue related to the code used?

0 Likes

#6

Well, your BLYNK_WRITE(V3) callback function is slightly odd.

Your comments seem to indicate that you think its’s a loop, which it isn’t. It’s a function that’s triggered automatically when the Blynk server sees a change in the value of V3.

And the Blynk.syncVirtual(V3) command within that function serves no purpose. It could actually create an infinite loop, but I think the Blynk library is too clever to stop that happening.

Pete.

0 Likes

#7

where do you suggest the Blynk.syncVirtual(V3) command should be placed?

0 Likes

#8

so I figured Blynk.syncVirtual(V3) is best placed under void loop() as I need the cradle function to loop.
As for the ifttt applet, I did a little digging and found that this configuration was the one that works for me!


The problem I had encountered earlier was a silly one which had to do with v3 being in all caps.
Anyways thanks for your help @PeteKnight !

0 Likes

#9

First of all, you really should’t be using Blynk that way, and secondly, as I said before, I think (hope) the library is clever enough to stop that happening.

Maybe you should go back to basics and explain what it is you’re trying to achieve and we might be able to suggest a better way.

Pete.

0 Likes