Code problem

I was uesd "BLYNK_WRITE(V0){ int v1=param.asInt(); } "

But it come out error “afunction-definition is not allowed here before '{' token

How can I fix this error?

Do not know if the Syntax accepts all in one line (or is it the lack of space between “)” and “{”?), But this here works for me:

BLYNK_WRITE(V15) { // Do Stuff when button pressed
    int valor = param.asInt();
    if(valor == 1) {
        terminal.println("\nDOING STUFF");
        terminal.flush();
    }
}

According to this post: http://stackoverflow.com/questions/22185288/is-a-function-definition-not-allowed-here-before-a-token

Maybe you are declaring this function inside another function or using “{}” incorrectly (too many or too few).

The proper way to do it is like this:

#include "blynk/blynk.h"

char auth[] = "BLABLABLA";   

void setup () {
    Blynk.begin(auth);
}

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

BLYNK_WRITE(V15) { // Do Stuff when button pressed
    int valor = param.asInt();
    if(valor == 1) {
        terminal.println("\nDOING STUFF");
        terminal.flush();
    }
}

This compiled without error for me, so I suspect you have a syntax error immediately preceding or following this line.

1 Like

Can’t fix it without your code in full as the error does not relate to the line of code you shared.