My first Blynk sketch. Patience ready only :)

Hi.
Doing my first Blynk project. I have some questions - simple one for now. So I need so my esp-12f, as shell, for Uno board - light up LEDs on 4, 5 pins by Blynk app, as V0 and V1 pins. Here is sketch, but I getting error.

Sketch:

#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

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

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

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

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

  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  BLYNK_WRITE(V0) {
  if (param.asInt() == 1) {
    digitalWrite(4, HIGH);
  } else {
    digitalWrite(4, LOW);
  }
}
BLYNK_WRITE(V1) {
  if (param.asInt() == 1) {
    digitalWrite(5, HIGH);
  } else {
    digitalWrite(5, LOW);
  }
}
  Blynk.begin(auth, wifi, ssid, pass);
}

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

Error:

Arduino: 1.8.1 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\xxx\AppData\Local\Temp\arduino_modified_sketch_930730\ESP8266_Shield.ino: In function 'void setup()':

ESP8266_Shield:72: error: a function-definition is not allowed here before '{' token

   BLYNK_WRITE(V0) {

                   ^

ESP8266_Shield:93: error: expected '}' at end of input

 }

 ^

exit status 1
a function-definition is not allowed here before '{' token

As I understand problem with { } but can’t see anywhere mistake. Or maybe something else? I done same as in Gunner robot project (with Blynk_write(V0)). Here link to his project:

Take the Blynk functions out of setup(), they are standalone functions.

You mean to place them in loop? They placed same as in gunner sketch. Can’t see anybody complain about it.

No.

I’m sure they are not.

Totally free standing like:

BLYNK_WRITE(V1) {
  if (param.asInt() == 1) {
    digitalWrite(5, HIGH);
  } else {
    digitalWrite(5, LOW);
  }
}

Bkynk.run() in loop() does all the magic to use the functions.

Nothing else in loop - I got this.
But maybe I’m learning or can’t understand you enought. Have your checked gunners sketch? There link in first post. They placed same in sketch, I think. Maybe your can explain me in example? Thanks for patience :slight_smile:

Of course, and they are not in setup() and not in loop().

Think about any function:

void someFunction(){
  // some code here
}

That’s exactly what BLYNK_WRITE() is but Blynk.run() checks all the functions without you having to call them in your sketch.

1 Like

I fixed some errors it’s working… Got next in terminal:

[19] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.8 on Arduino Uno

[603] Connecting to Pxxxxxa3
[13636] AT version:0.40.0.0(Aug  8 2015 14:45;58)
SDK vession:1.3.0
Ai-g4
[19727] +CIFSR:STAIP,"192.168.0.116"
+CIFSR:STAMAC,"a0:xxxxxx80:ef"

[19738] Connected to WiFi
[29922] Ready (ping: 11ms).
[39945] Login timeout
[65243] Ready (ping: 15ms).
[75265] Login timeout
[141170] Ready (ping: 11ms).
[151192] Login timeout

Thats meant as WiFi shell esp8266 working?

1 Like

Ready means it’s working but timeout means it’s running badly.

What can be wrong? Power is enought… WiFi is near…

Paste your formatted sketch.
Maybe you are pushing the baud rate too high. You have to crawl at 9600 with shields rather than 115200 for real ESP8266 connections.

1 Like

Then will try to flash it with lower baudrate. Thank you for assistance. Will try tomorrow.

Anybody knows most stable AT firmware? In one bin file?

This is the one mentioned in the docs - http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-with-at-firmware

http://www.electrodragon.com/w/File:At_firmware_bin1.54.zip

1 Like

There 2 files, one of them AiThinker_ESP8266_DIO_8M_8M_V1.5.4.bin
Its about 1mb, but what means 8m?

Flashed that firmware. Now I getting from Arduino serial - “failed to disable echo”. Esp8266 in serial giving me: “ai thinker. Ready”. Guess problem is in Blynk? I found some topic with same problem, but it a bit old though… [SOLVED] “Failed to disable echo” PROBLEM

Guess again :slight_smile:

Maybe that firmware in documentation is not correct version for Blynk?

Maybe you are not setting the baud with the correct AT commands as per the docs.

Maybe you re not setting the correct baud rates in your sketch.

As per the docs (my translation), you have to be mad to try ESP shield connection method when plug and play method is so much easier.

Speaking of OLD… sounds like your library is also OLD… Your screenshot shows v0.4.8 but that version got rid of the “Cannot disable echo” for a more understandable “ESP is not responding”.

So it sounds like you may have some corruption in your Blynk libraries?? Perhaps remove all of them and reinstall from the source.

1 Like

Working now all fine. Was some problem with flasher software. I change it, now it’s all fine. At 9600 working without timeout. Just at the moment don’t have much time. Will continue threat later.