cannot declare variable 'Udp' to be of abstract type 'WiFiUDP'

cannot declare variable 'Udp' to be of abstract type 'WiFiUDP'

Yeah… here is my code

//#include <string.h>
#include <stdio.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#define USE_SERIAL Serial

const char* ssid = "JMR";
const char* password = "cr965";

WiFiUDP Udp;

long delayMS;
unsigned int localUdpPort = 8888;  // local port to listen on
char incomingPacket[255];  // buffer for incoming packets

void setup() {
  Serial.begin(115200);
  Serial.println();

  Serial.printf("Connecting to %s ", ssid);

  IPAddress ip(192, 168, 1, 139);
  IPAddress gw(192, 168, 1, 254);
  IPAddress dns(192, 168, 1, 254);
  IPAddress sn(255, 255, 255, 0);
  WiFi.config(ip, gw, sn, dns);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" connected");

  Udp.begin(localUdpPort);
  Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
}
void loop()
{
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    // receive incoming UDP packets
    //Serial.println("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
    int len = Udp.read(incomingPacket, 255);
    Serial.println(incomingPacket);
    if (len > 0)
    {
      incomingPacket[len] = 0;
      if (strlen(incomingPacket) < 4) {
       //Truncated packet? Ask to re-transmit.
        Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
        Udp.write("9999");
        Udp.endPacket();
      return;
      }
    }   
  }
  if (millis() - delayMS > 1000) {
    Serial.println(9102);
  }
  delayMS = millis();
}

Luckily this is a small sketch. The problem is “WiFiUDP Udp;”, the error language is above my head, and this sure as heck compiled fine before 1.8.8.

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages" (or the icon that looks like two pieces of paper in the Arduino Web Editor). Click that button. Paste the error in a message here using code tags. If the text exceeds the forum's 9000 character limit, save it to a text file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.

I'm not familiar with the library, but the compiler's message is fairly straight forward (assuming there are no other errors in your code). It's saying that WiFiUDP is an Abstract Class, meaning that it has at least one purely virtual method. You can't create a variable with the type of an abstract class. There must be some class that derives from WiFiUDP that you should be using.

Hmmmm… this compiles for me for board Adafruit Huzzah ESP8266

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

WiFiUDP Udp;

void setup() {
	Udp.begin(80);
}

void loop() {
}

do not include WiFiUdp.h.

I'm getting this compile error now. I'm getting nowhere with this damned ESP module. Only compile failures! Is there a way to revert 1.8.6?

it compiled fine there. I have enough trouble debuggin my own code, much more someone elses.

C:\Users\matt\Documents\Arduino\libraries\ESP8266WiFi\src/WiFiServerSecureAxTLS.h:36:20: error: invalid abstract return type for member function 'axTLS::WiFiClientSecure axTLS::WiFiServerSecure::available(uint8_t*)'

WiFiClientSecure available(uint8_t* status = NULL);

I need UDP suport though. I get lots of compile errors like this, only in 1.8.8. How would I fix it?

There must be an error in every library! I got them from github. Something else is wrong…

See the attachment.

errors.txt (15.8 KB)

mattlogue:
There must be an error in every library! I got them from github. Something else is wrong...

See the attachment.

don't install in libraries folder, libraries which are part of core package.

You should always read the comments in a library after installing it to see how to use it. All the Arduino
stuff is open-source specifically so you can get it and figure things out and adapt to your requirements
if needed.

As I previously requested on your other thread:

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages" (or the icon that looks like two pieces of paper in the Arduino Web Editor). Click that button. Paste the error in a message here using code tags. If the text exceeds the forum's 9000 character limit, save it to a text file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.

mattlogue has created a new thread for the "invalid abstract return type for member function" errors shown in the errors.txt output they posted here.

From the errors.txt output, it appears that the "cannot declare variable 'Udp' to be of abstract type 'WiFiUDP'" error this thread was originally about has been resolved (though mattlogue hasn't been so kind as to mention this fact).

pert:
mattlogue has created a new thread for the “invalid abstract return type for member function” errors shown in the errors.txt output they posted here.
http://forum.arduino.cc/index.php?topic=599883

From the errors.txt output, it appears that the “cannot declare variable ‘Udp’ to be of abstract type ‘WiFiUDP’” error this thread was originally about has been resolved (though mattlogue hasn’t been so kind as to mention this fact).

all the “virtual function not implemented” errors are cause of “abstract class” error. so it is not resolved. the main cause is that esp8266 package developers added in 2.5.0 a parameter to some virtual functions in Client, Server and UDP class. so no external networking library or older versions of esp8266 libraries compile

Here pert. Sorry for double-posting, at the time they seemed different problems, but I think there is one common denominator…

Please refer to attachment

errors2.txt (43.3 KB)

It wasn't clear to me whether this was a cross post. It does make sense sometimes to start a new thread when you have resolved the question asked in the original thread. However, when you do that it's very important to make sure that there are no parallel discussions happening in both threads, as will now start here.

Now that I have seen your full error output, I see that the original error from the other thread still occurs, so this is definitely a cross post.

As was also recommended in the other thread, it really doesn't make sense for you to install the ESP8266WiFi library. That library is part of the ESP8266 core for Arduino and is installed at the same time. It is very closely integrated into the core and so if you try to use a version of the library that is not written for the ESP8266 core version you have installed, you could get errors like the ones you have.

You need to delete this folder:
C:\Users\matt\Documents\Arduino\libraries\ESP8266WiFi

I can compile your updated sketch from the other thread without any errors. However, the error output you posted here indicates that you are compiling the version of the sketch that you had originally posted in that thread, which does have some legitimate bugs that result in these errors:

C:\Users\matt\Documents\Arduino\node7b1\node7b1.ino: In function 'void setup()':

node7b1:74:2: error: 'WiFiUdp' was not declared in this scope

  WiFiUdp.localPort(8888);

  ^

I haven't seen anything about a function like this. Normally you would set the port via Udb.begin(), as you did in your other sketch.

C:\Users\matt\Documents\Arduino\node7b1\node7b1.ino: In function 'void sendUDP()':

node7b1:83:9: error: 'WiFiUdp' was not declared in this scope

     x = WiFiUdp.beginPacket(ip, 8888);

         ^

You need to change this line:

    x = WiFiUdp.beginPacket(ip, 8888);

To:

    x = Udp.beginPacket(ip, 8888);

From my recollection of the code, I think there might be a couple other errors like this that you will need to fix.

Threads merged.

I confused myself and created the other thread in error. I'll stay here, and it looks as if it was merged, so thank you.

Even though I deleted the documents copy of ESP8266WiFi and commented out the include, the compiler notes that ESP8266WiFi is still being used from C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi . Is that normal or a problem? Likely WifiClient or WiFiUdp are referencing in the ESP8266WiFi.

I get errors like “WIFI_STA” is not declared in this scope. I don’t know a workaround to that.

Here is current version of sketch “node-7b1”. It’s function is the bridge between an UNO and another ESP8266 and thus PC via UDP. But don’t tell me to use the ESP in place of Uno because the project is built for an Uno, and I tried using the ESP directly and it failed so many places I didn’t bother coming here.

int code, i, x;

//#include <SPI.h>         // needed for Arduino versions later than 0018
//#include <Ethernet.h>
//#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008
//#include <WiFi.h>
//#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>

//EthernetUDP Udp;

IPAddress ip(192, 168, 1, 139);
const char* ssid = "JMR";
const char* password = "";

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:


unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[32]; //buffer to hold incoming packet,

// An EthernetUDP instance to let us send and receive packets over UDP
//ESP8266WiFi WiFiUdp;

const byte numChars = 8;
char receivedChars[numChars];   // an array to store the received data
char codeChar[numChars];
boolean newData = false;


void setup() {
  // start the Ethernet and UDP:
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  
  IPAddress ip(192, 168, 1, 137);
  IPAddress gw(192, 168, 1, 254);
  IPAddress dns(192, 168, 1, 254);
  IPAddress sn(255, 255, 255, 0);
  WiFi.config(ip, gw, sn,  dns);
  
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Node7b: Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

x = Udp.localPort(8888);
}

void loop() {
     recvWithEndMarker();
    showNewData();
delay(100);
}
void sendUDP() {
    x = Udp.beginPacket(ip, 8888);
  if (x == 1) {
    Serial.print("beginPacket status: Success ");
  }
  else {
    Serial.print("beginPacket status: FAILURE ");
  }
  x = Udp.write(receivedChars);
  Serial.print("Writing: ");
  x = Udp.endPacket();
  if (x == 1) {
    Serial.print("Packet Send status: Success ");
  }
  else {
    Serial.print("Packet Send status: FAILURE ");
  }
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;

Serial.print("recvWithEndMarker");
    
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
 sendUDP();
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}

Here are the errors:

C:\Users\matt\Documents\Arduino\node7b1\node7b1.ino: In function 'void setup()':

node7b1:51:3: error: 'WiFi' was not declared in this scope

   WiFi.mode(WIFI_STA);

   ^

node7b1:51:13: error: 'WIFI_STA' was not declared in this scope

   WiFi.mode(WIFI_STA);

             ^

node7b1:63:27: error: 'WL_CONNECTED' was not declared in this scope

   while (WiFi.status() != WL_CONNECTED) {

                           ^

node7b1:73:5: error: The Udp class has been renamed EthernetUdp.
As of Arduino 1.0, the Udp class in the Ethernet library has been renamed to EthernetUdp.


 x = Udp.localPort(8888);

     ^

C:\Users\matt\Documents\Arduino\node7b1\node7b1.ino: In function 'void sendUDP()':

node7b1:82:9: error: The Udp class has been renamed EthernetUdp.
As of Arduino 1.0, the Udp class in the Ethernet library has been renamed to EthernetUdp.


     x = Udp.beginPacket(ip, 8888);

         ^

Multiple libraries were found for "WiFiClient.h"
 Used: C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi
 Not used: C:\Users\matt\Documents\Arduino\libraries\WiFi
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi 
exit status 1
'WiFi' was not declared in this scope

Juraj:
don't install in libraries folder, libraries which are part of core package.

Where should I put these libraries? There are 3 locations on one drive. One in appData, one in my documents, the other in program files.

gfvalvo:
Hmmmm… this compiles for me for board Adafruit Huzzah ESP8266

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

WiFiUDP Udp;

void setup() {
Udp.begin(80);
}

void loop() {
}

Thanks, I overlooked your post earlier and just tried it and it compiles fine!