Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ESP8266WiFi.h and Wifi.h (Read 4176 times)
Paul Martinsen
Junior Member
**
Offline


Posts: 14
Joined: Apr 12th, 2017
ESP8266WiFi.h and Wifi.h
May 1st, 2020 at 5:44am
Print Post  
Hello,

I'd like my source to compile for both ESP8266 and ESP32 targets. It hosts a webserver so I have, at the start of my ino file:
Code (C++)
Select All
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#else
#include "Wifi.h"
#include "WebServer.h"
#endif 



This works fine when building for an ESP32 board. 

However, when I build for an ESP8266 board I get:
Quote:
WiFiUdp.h: 27:7: error: redefinition of 'class WiFiUDP
class WiFiUDP *: public UDP {
:
:


The errors arise in the file arduino-1.8.9\libraries\WiFi\src\WiFiUdp.h. 

What I guess is happening:
  • For ESP32, VisualMicro sees that the ESP32 package includes its own WiFi.h implementation and includes that when it copies files to the staging area for compilation. Just as it should. 
  • ESP8266 includes a wifi library with a different folder name (ESP8266WiFi) so that gets copied to the staging area, but it also copies the default Arduino Wifi library as well. The ESP8266 library, in ESP8266Wifi, also includes a class definition for WiFiUdp so I end up with multiply defined types. 


So it looks like the library discovery is ignoring the pre-processor macros that should prevent that from happening. This wouldn't happen if the ESP8266 folk had stuck to normal naming conventions like the ESP32 people did. 

Any suggestions how I could solve this? Ideally without modifying anything outside the Visual Micro solution. 

Have a great, virus free, weekend,
Paul.


  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2174
Joined: Feb 13th, 2019
Re: ESP8266WiFi.h and Wifi.h
Reply #1 - May 1st, 2020 at 10:22am
Print Post  
Thanks for the report, can you attach the information shown in the yellow box above for both ESP32 and ESP8266 compilations? (just so we have all available information)

The below seems to compile fine for both boards, but I only see the missing WiFiUDP if the .h isnt included on the ESP8266. Hopefully the logs will reveal more, so we can diagnose further.

Code
Select All
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#else
#include <WiFi.h>
#include "WebServer.h"
#endif

WiFiServer server(80);
WiFiUDP udpConn;
....
 

  
Back to top
 
IP Logged
 
Paul Martinsen
Junior Member
**
Offline


Posts: 14
Joined: Apr 12th, 2017
Re: ESP8266WiFi.h and Wifi.h
Reply #2 - May 1st, 2020 at 9:51pm
Print Post  
Hi Simon, 

Thanks for your quick reply. I've created a separate program based on the blink example and packaged it, along with the verbose & properties output, into the attached zip file. The build output is for the "LOIN(WEMOS) D1 R2 & mini" board. 

Incidentally, I had to add FS.h into the #else section for that library to be picked up. 

Have a great day,
Paul
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2174
Joined: Feb 13th, 2019
Re: ESP8266WiFi.h and Wifi.h
Reply #3 - May 2nd, 2020 at 1:30am
Print Post  
No problem, it looks like you have disabled the "vMicro > Compiler > Deep Search for Libraries" option.

If you re-enable this it should correctly build as expected, and not include the non-ESP WiFi Library.
  
Back to top
 
IP Logged
 
Paul Martinsen
Junior Member
**
Offline


Posts: 14
Joined: Apr 12th, 2017
Re: ESP8266WiFi.h and Wifi.h
Reply #4 - May 5th, 2020 at 9:54pm
Print Post  
Thanks. That's resolved the problem. Much appreciated.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint