I’m having a strange error with my code when I put it into separate tabs. It compiles and works fine when all on one tab in Arduino IDE (1.8.12) and esp8266 v2.6.3.
Here is the basic code:
//MAIN CODE
//Libraries
#include <BlynkSimpleEsp8266.h> //Blynk support
#include <ESP8266WiFi.h> // connection to WiFi
//
//Login credentials
//Blynk
char auth[] = "";
//WiFi credentials
char ssid[] = "";
char pass[] = "";
//BLYNK TAB
BLYNK_WRITE(V2)
{
if (param.asInt())
{
Blynk.virtualWrite(V1, "clr"); // Clear the terminal on V1
}
}
//LOOP TAB
void loop ()
{
Blynk.run();
}
//SETUP TAB
void setup()
{
Serial.begin(74880);
setup_wifi(); //connect to wifi
Blynk.config(auth);
Blynk.connect();
}
//WIFI TAB
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
I am separating it into the following tabs as per the functions:
MAIN
BLYNK
LOOP
SETUP
WIFI
The Blynk code does not seem to like this and throws the below error.
If I put either LOOP or SETUP code back into the MAIN tab it’s ok again.
Error message - BLYNK_WRITE(V2) line highlighted :
blynk:2:59: error: variable or field 'BlynkWidgetWrite2' declared void
BLYNK_WRITE(V2)
^
blynk:2:24: error: 'BlynkReq' was not declared in this scope
BLYNK_WRITE(V2)
^
blynk:2:71: error: expected primary-expression before 'const'
BLYNK_WRITE(V2)
^
Multiple libraries were found for "ESP8266WiFi.h"
Used: E:\Dropbox\Arduino Wemos\sketches\libraries\ESP8266WiFi
Not used: C:\Users\877\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi
exit status 1
variable or field 'BlynkWidgetWrite2' declared void
I’m not an expert in using tabs in the IDE, but when I have done it I tend to keep the library includes, void setup and void loop in the @main@ tab (although it’s not called Main, it has the filename of the sketch).
If I’m declaring global variables in a different tab, or want to move my library includes into a different tab, then those tabs has to have #include entries in the main tab, like this:
// Include the tabs that contain includes and variable definitions in this order, to prevent compilation errors...
#include "b_libraries_used.h"
#include "c_variables_1.h"
#include "d_variables_2.h"
The “b_” , “c_” and “d_” suffixes are so that I can control the sequence of the tabs, because the IDE wants to display them alphabetically.
Thanks for that it all makes sense. However in this case I’m not sure that is the issue, as I believe Arduino IDE just compiles the tabs in order, and each tab is a separate function. So essentially it should be the same.
I’m sure I have other projects without Blynk where it compiles fine. Unless I’m making a mistake somewhere.
I suspect that the errors you were getting are because you didn’t add .h on to the end of the tab names. I had the same errors when I did the same thing.
Renaming the tabs solved that issue, but then I had the issue that I thought I would, at the end of the compilation it says:
undefined reference to `setup'
Which means that it can’t find the void setup in the main code.
Adding the setup tab as an include solves this, but then when setup calls setup_wifi() it cant find that tab.
I still think that you’re better-off having at least your void loop() in the main tab, and if you put your void setup() in a different tab then you have to do an include for it.
Thanks again for your effort, it’s good to know it’s not just my setup that throws the error.
You may well be correct regarding the .h and #includes, but it doesn’t quite make sense to me why it’s not working.
If you read Robins comments over on the Arduino forum it should just concatenate the .ino files in order when compiling. So I fail to see why having them all in one tab, or seperate tabes in the same order is different.
I have taken other sketches and split them the same way into tabs, and it compiles fine. I don’t think this is a Blynk issue, so I will do some research over on the Arduino forum to save cluttering this one.
I think it’s to do with the fact that the Blynk libraries have includes to other libraries. This makes theses library functions available and visible to other pieces of code at compile time.