Button with code

Hi

in my alarm home I would like to use blynk app, but on /off alarm not a classic button, but
a button protect with code …
example, numeric input widget i enter my code alarm on /off , or text input, or terminal …

its possible?

1 Like

Yes - it is possible, search for terminal input using search.

It has been covered previously.

1 Like

yes you can create your own kb too.

3 Likes

because I can’t find the project link :rage::rage::rage:

If you’re expecting a ready-made project that does exactly what you have in mind then you’re going to be out of luck.

If you want ideas and code snippets that can be adapted to something which meets your basic criteria then do some research:
https://community.blynk.cc/search?q=Button%20security

Pete.

1 Like

i have a problem on/off with terminal, but the widget button is ok …
this is my code

Blockquote
int x;
BLYNK_WRITE(V30){
if (String(“1111”) == param.asStr()) {
terminal.println(“Password OK”) ;
Blynk.notify(“Password impianto accettata”);
} else {
terminal.print(“Password ERRATA!!!”);
Blynk.notify("Attenzione, forzatura impianto ");
Blynk.email(“YOUR EMAIL HERE”, “Impianto Allarme!!!”, “Attenzione tentativo di accesso non autorizzato!!!”);
terminal.write(param.getBuffer(), param.getLength());
terminal.println();
}
terminal.flush();
}
void antifurto() {
if (x == 1) {
if (stato_imp = true) { // flag impianto inserito
number1inserito();
number2inserito();
digitalWrite(led_1, HIGH); // accende led impianto inserito
delay(1200); //
digitalWrite(led_1, LOW); // spegne il LED (LOW l’uscita viene disalimentata)
delay(400); //
if (stato_reed == HIGH) { // contatto porta aperto
number1allarme();
number2allarme();
digitalWrite(led_2, HIGH); // accende led segnalazione allarme
}
if (stato_tamper == HIGH) { // linea tamper aperta
number1allarme();
number2allarme();
digitalWrite(led_2, HIGH); // accende led segnalazione allarme
}
}
else if (stato_imp = false) { // flag impianto disinserito
number1disinserito();
number2disinserito();
digitalWrite(led_1, LOW); // spengne led a impianto disinserito
digitalWrite(led_2, LOW); // spegne led segnalazione allarme
}
}
}

i have a Int x, this in, void aintifurto, commands on/off , but terminal widget the line
if (x == 1)
for enable alarm I don’t know how to handle it

Help!!!

So where in your code is ‘x’ being set to 1?

Pete.

1 Like

in my code virtual write v 30 where I put x = 1

You don’t set x=1 ?

1 Like

I’m glad it wasn’t just me that couldn’t see it!

I thought (another) trip to Specsavers was needed!

Pete.

1 Like
terminal.write(param.getBuffer(), param.getLength());

If this is where you are trying to type x=1, this will not work.

All that does is copy back to the terminal what you type in, it doesn’t store the input in a variable. Thus it doesn’t set x to 1.

sorry but I do not understand in this way with a button widget my code is perfect “on/off perfect”

int x;
BLYNK_CONNECTED() {
      Blynk.syncVirtual(V30);
  }

BLYNK_WRITE(V30){
 x = param.asInt();
 }
void antifurto() {
  if (x == 1) {
  if (stato_imp = true) { // flag impianto inserito
    number1inserito();
    number2inserito();
    digitalWrite(led_1, HIGH);  // accende led impianto inserito
    delay(1200); // 
    digitalWrite(led_1, LOW); // spegne il LED (LOW l'uscita viene disalimentata)
    delay(400); //
    if (stato_reed == HIGH) { // contatto porta aperto
      number1allarme();
      number2allarme();
      digitalWrite(led_2, HIGH);  // accende led segnalazione allarme
    
    }
    if (stato_tamper == HIGH) { // linea tamper aperta
      number1allarme();
      number2allarme();
      digitalWrite(led_2, HIGH); // accende led segnalazione allarme
    }
  }
  else if (stato_imp = false) { // flag impianto disinserito
    number1disinserito();
    number2disinserito();
    digitalWrite(led_1, LOW);  // spengne led a impianto disinserito
    digitalWrite(led_2, LOW); // spegne led segnalazione allarme
  }
}
}

my problem is if insert terminal widget.

I’m afraid I don’t understand what you’re saying.

Pete.

ok…

if I use the widget button with the last code I posted, everything works from the blynk app I can activate and deactivate the alarm.
if I use the terminal widget instead with the code below it will not work, from app blynk it will not activate and deactivate the alarm

int x;
WidgetTerminal terminal (V30);
BLYNK_CONNECTED() {
      Blynk.syncVirtual(V30);
  }
BLYNK_WRITE(V30){
  if (String("1111") == param.asStr()) {
terminal.println("Password OK") ;
Blynk.notify("Password impianto accettata");
  } else {
terminal.print("Password ERRATA!!!!");
Blynk.notify("Attenzione, forzatura impianto ");
Blynk.email("YOUR EMAIL HERE", "Impianto Allarme!!!", "Attenzione tentativo di accesso non autorizzato!!!!");
terminal.write(param.getBuffer(), param.getLength());
terminal.println();
  }
  terminal.flush();
}
void antifurto() {
   {
  if (stato_imp = true) { // flag impianto inserito
    number1inserito();
    number2inserito();
    digitalWrite(led_1, HIGH);  // accende led impianto inserito
    delay(1200); // 
    digitalWrite(led_1, LOW); // spegne il LED (LOW l'uscita viene disalimentata)
    delay(400); //
    if (stato_reed == HIGH) { // contatto porta aperto
      number1allarme();
      number2allarme();
      digitalWrite(led_2, HIGH);  // accende led segnalazione allarme
      }
    if (stato_tamper == HIGH) { // linea tamper aperta
      number1allarme();
      number2allarme();
      digitalWrite(led_2, HIGH); // accende led segnalazione allarme
    }
  }
  else if (stato_imp = false) { // flag impianto disinserito
    number1disinserito();
    number2disinserito();
    digitalWrite(led_1, LOW);  // spengne led a impianto disinserito
    digitalWrite(led_2, LOW); // spegne led segnalazione allarme
  }
}
}

Would you please stop using blockquotes around your code. Use triple backticks instead.

We’ve now seen three different versions of this code, each one different.
Your first version wasn’t setting x=1 in your V30 callback.
The second version is setting x=param.asInt() which will be 1 when the button widget is on.
The third version has scrapped the use of x altogether.

I’m totally lost about what it is that you’re trying to achieve with this code.

Pete.

my code is the last one I posted but it doesn’t work.
how do i fix it to activate my burglar alarm

So at the moment, when your BLYNK_WRITE(V30) callback function is triggered it checks if the text entered into your terminal is “1111”
If it is then it gives feedback via the terminal and sends a Blynk notification.
If it’s not “1111” then it gives feedback via the terminal, sends a Blynk notification and an email.

If you want something else to happen when “1111” is entered via the terminal then you need to either execute more code, call another function or set a flag that can be used later. You are doing neither of these at the moment.
You were checking if a flag (x) had been set to “1” in your antifurto function, but never setting that flag in the BLYNK_WRITE(V30) callback. You’ve now removed that code, rather than setting that flag to “1” within BLYNK_WRITE(V30) as we suggested before.

Pete.

my flag is int x , this flag enable my antifurto , and yes setting the flag in the BLYNK_WRITE (V30) callback, i think with terminal.wrtie but not function

Show me where, in your latest code, you are doing this.

Pete.

2 Likes

his flag is used in the first sketch but it disappears in the second .

1 Like