'Blynk' does not name a type

Hi guys,

I’m making a wireless switch so far it has worked great but I want to add wifi signal strength as I’m using a Wemos D1 Mini Pro with an external antenna, but when ever I try to verify the code I get the following error.

Remote_Switch_Code:29:1: error: 'Blynk' does not name a type

 Blynk.virtualWrite[](V0, map(WiFi.RSSI(), -110, -30, 30, 100));

 ^

Remote_Switch_Code:31:3: error: expected declaration before '}' token

   }

   ^

exit status 1
'Blynk' does not name a type

Here is the code any help would be great.

#define BLYNK_PRINT Serial
#include "ESP8266WiFi.h"
#include "BlynkSimpleEsp8266.h"
#include <Blynk.h>


char auth[] = "07de06a084224282b5dc9c5caaa0f243";


char ssid[] = "Zappia's WIFI (2.4GHz)";
char pass[] = "zaq12wsx";


void setup()
{


  Blynk.begin(auth, ssid, pass);

}

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

Blynk.virtualWrite(V0, map(WiFi.RSSI(), -110, -30, 30, 100));

  }
}

void loop () {}

This is the most messed-up piece of code I’ve seen in a long time :roll_eyes:
You have two void loops and many more closing curly brackets than opening curly brackets.

It looks like you were trying to put this line of code in your void loop

Blynk.virtualWrite(V0, map(WiFi.RSSI(), -110, -30, 30, 100));

but if you did that you’d flood the server because you’re trying to do a Blynk.virtualWrite hundreds of times per second.

You should create a function to push the RSSI reading to the Blynk server and call if every 5 seconds or so with a timer.

Pete.

I’m so sorry as I am very new to this could you please paste in what the actual code should look like :slight_smile:

This is what I’ve done now but I still keep getting ‘Blynk’ does not name a type

#define BLYNK_PRINT Serial
#include "ESP8266WiFi.h"
#include "BlynkSimpleEsp8266.h"
#include <Blynk.h>


char auth[] = "07de06a084224282b5dc9c5caaa0f243";


char ssid[] = "Zappia's WIFI (2.4GHz)";
char pass[] = "zaq12wsx";


void setup()
{


  Blynk.begin(auth, ssid, pass);

}



  Blynk.run();
}

Blynk.virtualWrite(V0, map(WiFi.RSSI(), -110, -30, 30, 100));


}

void loop () {}

Load up the Blynk Blink basic code and take it from there.

Yes I understand that, It’s more so getting the wifi strength part of the code that isn’t playing nicely

okay so now I managed to upload the code and get it working how ever now the signal strength will only update after I reset the D1 mini pro, I have tried setting the refresh rate to push, 1 sec, 2 sec and 5 sec I have confirmed that it won’t updated unless a reset is performed by completely removing the external antenna if anyone can tell me why that would be great thanks

This is the current code that works but doesn’t refresh


#define BLYNK_PRINT Serial


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

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Zappia's WIFI (2.4GHz)";
char pass[] = "zaq12wsx";

void setup()
{

  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

Blynk.virtualWrite(V8, map(WiFi.RSSI(), -110, -30, 30, 100));

}

void loop()
{
  Blynk.run();

}

I’m not going to write your code for you - you won’t learn that way.
As @Gunner suggested, looking at the Sketch Builder examples is a good starting point. This document is also a very good explanation of how to call a function, like the one you want to send RSSI values, using a timer:

Also, you obviously don’t understand the structure of a C++ sketch. I’ll explain a little, but there are better resources out there, especially on YouTube.

This is a function. It happens to be a special function that is run once when the device boots-up, but the principal is the same for other functions.

void setup()
{
  Blynk.begin(auth, ssid, pass);
}

It has an opening (left facing) curly bracket at the beginning and a closing (right facing) curly bracket at the end.

void loop is also a special function and it gets run continuously when the code is running. With Blynk, it needs to look like this:

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

or if you’re using a timer (you have to declare it first, see the document I’ve linked above for info) it will look like this:

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

Anything outside of the opening and closing curly brackets of a function is treated as a “declaration”. This is where you specify which libraries are needed, and where you declare your global variables. You can scatter these declarations all over the place if you wish, but best practice is to put them at the top of your code, as you have here:

#define BLYNK_PRINT Serial
#include "ESP8266WiFi.h"
#include "BlynkSimpleEsp8266.h"
#include <Blynk.h>

char auth[] = "07de06a084224282bxxxxxxxxxxxxx";

char ssid[] = "Zappia's WIFI (2.4GHz)";
char pass[] = "xxxxxxxxx";

Now that you understand this, if you work through both of your sets of code, you’ll see that you have unmatched opening and closing brackets, and pieces of code that aren’t contained within a function at all.
When the Arduino IDE attempts to compile this code it gets very confused and throws up errors that aren’t really very meaningful.

Have a read through this post several times, take a look at the sketch builder examples (the Push Data example is fairly similar in structure to what you need) and take a look at your code again.
If you’re still having issues that you cant resolve then post your updated code and details of the problem and we’ll take a look at it.

Pete.