EthernetUdp class causing a Not defined error, even though it's included

I have been combing through this forum for a while now, and keep seeing this problem pop up but haven't found a good solution yet. It seems there's a DMX library floating around with old calls to UDP.h in it, and after updating the library to use the new EthernetUdp.h style calls, and after updating the bit of code I was working on to match, I'm still getting EthernetUdp not declared in this scope. If I define it, (EthernetUdp Udp;), then I still get an error stating that it "isn't declared in this scope". I have included all modified files, and some code.

This script (and lib-dmx.cpp, etc) was apparently originally written for Arduino 0023, and I am trying to update it for Arduino 1.8.9.

The code was too long to paste into this post, so I attached it as artnet_node.ino.

Errors:

/Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino: In function 'void setup()':
artnet_node:275:6: error: 'EthernetUdp' was not declared in this scope
      EthernetUdp.begin(ArtNode.localPort);
      ^
/Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino: In function 'void loop()':
artnet_node:284:7: error: 'EthernetUdp' was not declared in this scope
   if( EthernetUdp.available() > ARTNET_HEADER_SIZE ) 
       ^
/Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino: In function 'void handle_packet()':
artnet_node:290:3: error: 'EthernetUdp' was not declared in this scope
   EthernetUdp.readPacket((uint8_t *)&packetBuffer, MAX_BUFFER_UDP, (uint8_t *)&ArtNode.remoteIp, (uint16_t *)&ArtNode.remotePort);  
   ^
/Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino: In function 'void send_reply(uint8_t, uint8_t*, uint16_t)':
artnet_node:393:5: error: 'EthernetUdp' was not declared in this scope
     EthernetUdp.sendPacket(packet, size, ArtNode.broadcastIp, ArtNode.remotePort);
     ^
artnet_node:397:5: error: 'EthernetUdp' was not declared in this scope
     EthernetUdp.sendPacket(packet, size, ArtNode.remoteIp, ArtNode.remotePort);
     ^
Using library SPI at version 1.0 in folder: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI 
Using library Ethernet at version 2.0.0 in folder: /Applications/Arduino.app/Contents/Java/libraries/Ethernet 
Using library Dmx in folder: /Users/Newlin/Documents/Arduino/libraries/Dmx (legacy)
Using library LiquidCrystal at version 1.0.7 in folder: /Applications/Arduino.app/Contents/Java/libraries/LiquidCrystal 
exit status 1
'EthernetUdp' was not declared in this scope

artnet_node.ino (18.7 KB)

lib_dmx.h (8.58 KB)

lib_dmx.cpp (13.9 KB)

lulighttec:
If I define it, (EthernetUdp Udp;), then I still get an error stating that it "isn't declared in this scope".

The class name is EthernetUDP, not EthernetUdp. You can refer to File > Examples > Ethernet > UDPSendReceiveString to see how to use it.

pert:
The class name is EthernetUDP, not EthernetUdp. You can refer to File > Examples > Ethernet > UDPSendReceiveString to see how to use it.

Thanks for that info. I did read the example, and duplicated in this code as seemed appropriate, but the same error occurs.

artnet_node_t             ArtNode;
artnet_reply_t            ArtPollReply;
//artnet_ipprog_reply_t   ArtIpprogReply; //not implemented yet
artnet_packet_type_t      packet_type;
EthernetUDP               Udp;

and then further down:

void loop() 
{
  if( EthernetUdp.available() > ARTNET_HEADER_SIZE ) 
    handle_packet();
}

void handle_packet()
{
  EthernetUdp.readPacket((uint8_t *)&packetBuffer, MAX_BUFFER_UDP, (uint8_t *)&ArtNode.remoteIp, (uint16_t *)&ArtNode.remotePort);  
  
  packet_type = (artnet_packet_type_t) get_packet_type((uint8_t *)&packetBuffer);

and so on, and then the errors:

/Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino: In function 'void setup()':
artnet_node:275:6: error: 'EthernetUdp' was not declared in this scope
      EthernetUdp.begin(ArtNode.localPort);
      ^
/Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino: In function 'void loop()':
artnet_node:284:7: error: 'EthernetUdp' was not declared in this scope
   if( EthernetUdp.available() > ARTNET_HEADER_SIZE ) 
       ^
/Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino: In function 'void handle_packet()':
artnet_node:290:3: error: 'EthernetUdp' was not declared in this scope
   EthernetUdp.readPacket((uint8_t *)&packetBuffer, MAX_BUFFER_UDP, (uint8_t *)&ArtNode.remoteIp, (uint16_t *)&ArtNode.remotePort);  
   ^
/Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino: In function 'void send_reply(uint8_t, uint8_t*, uint16_t)':
artnet_node:393:5: error: 'EthernetUdp' was not declared in this scope
     EthernetUdp.sendPacket(packet, size, ArtNode.broadcastIp, ArtNode.remotePort);
     ^
artnet_node:397:5: error: 'EthernetUdp' was not declared in this scope
     EthernetUdp.sendPacket(packet, size, ArtNode.remoteIp, ArtNode.remotePort);
     ^
Using library SPI at version 1.0 in folder: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI 
Using library Ethernet at version 2.0.0 in folder: /Applications/Arduino.app/Contents/Java/libraries/Ethernet 
Using library Dmx in folder: /Users/Newlin/Documents/Arduino/libraries/Dmx (legacy)
Using library LiquidCrystal at version 1.0.7 in folder: /Applications/Arduino.app/Contents/Java/libraries/LiquidCrystal 
exit status 1
'EthernetUdp' was not declared in this scope

artnet_node.zip (10.2 KB)

Everywhere you have something like EthernetUdp.available(), you need to change it to use the name of the EthernetUDP object you created: Udp.available().

I have done some reading and reworking (and it led me to the same thing you just said, the name should be 'Udp'), and I think I'm closer to my goal. I have new errors! :slight_smile:
It seems that the proper way to call this is:

void send_reply(uint8_t mode_broadcast, uint8_t *packet, uint16_t size)
{
  if(mode_broadcast == 1) // send broadcast packet
  {
    //Udp.beginPacket(ArtNode.remoteIp, ArtNode.remotePort); //I commented these out while I was observing error messages
    Udp.write(packet, size, ArtNode.broadcastIp, ArtNode.remotePort);
    //Udp.endPacket(); //but as I understand it they should sandwich the 'write' 
  }
  else // send unicast packet to controller
  {
    //Udp.beginPacket(ArtNode.remoteIp, ArtNode.remotePort);
    Udp.write(packet, size, ArtNode.remoteIp, ArtNode.remotePort);
    //Udp.endPacket();
  }
}

So now it seems that the original arguments aren't quite correct; here are the new errors.

/Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino: In function 'void send_reply(uint8_t, uint8_t*, uint16_t)':
artnet_node:396:68: error: no matching function for call to 'EthernetUDP::write(uint8_t*&, uint16_t&, uint8_t [4], uint16_t&)'
     Udp.write(packet, size, ArtNode.broadcastIp, ArtNode.remotePort);
                                                                    ^
In file included from /Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino:34:0:
/Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:181:17: note: candidate: virtual size_t EthernetUDP::write(uint8_t)
  virtual size_t write(uint8_t);
                 ^
/Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:181:17: note:   candidate expects 1 argument, 4 provided
/Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:183:17: note: candidate: virtual size_t EthernetUDP::write(const uint8_t*, size_t)
  virtual size_t write(const uint8_t *buffer, size_t size);
                 ^
/Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:183:17: note:   candidate expects 2 arguments, 4 provided
In file included from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
                 from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
                 from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:232,
                 from /var/folders/pn/7t4ckm_9505c1pv7sx_2llx40000gn/T/arduino_build_799392/sketch/artnet_node.ino.cpp:1:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:57:12: note: candidate: size_t Print::write(const char*, size_t)
     size_t write(const char *buffer, size_t size) {
            ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:57:12: note:   candidate expects 2 arguments, 4 provided
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:52:12: note: candidate: size_t Print::write(const char*)
     size_t write(const char *str) {
            ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:52:12: note:   candidate expects 1 argument, 4 provided
artnet_node:402:65: error: no matching function for call to 'EthernetUDP::write(uint8_t*&, uint16_t&, uint8_t [4], uint16_t&)'
     Udp.write(packet, size, ArtNode.remoteIp, ArtNode.remotePort);
                                                                 ^
In file included from /Users/Newlin/Downloads/artnet/artnet_node/artnet_node.ino:34:0:
/Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:181:17: note: candidate: virtual size_t EthernetUDP::write(uint8_t)
  virtual size_t write(uint8_t);
                 ^
/Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:181:17: note:   candidate expects 1 argument, 4 provided
/Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:183:17: note: candidate: virtual size_t EthernetUDP::write(const uint8_t*, size_t)
  virtual size_t write(const uint8_t *buffer, size_t size);
                 ^
/Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:183:17: note:   candidate expects 2 arguments, 4 provided
In file included from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
                 from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
                 from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:232,
                 from /var/folders/pn/7t4ckm_9505c1pv7sx_2llx40000gn/T/arduino_build_799392/sketch/artnet_node.ino.cpp:1:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:57:12: note: candidate: size_t Print::write(const char*, size_t)
     size_t write(const char *buffer, size_t size) {
            ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:57:12: note:   candidate expects 2 arguments, 4 provided
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:52:12: note: candidate: size_t Print::write(const char*)
     size_t write(const char *str) {
            ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:52:12: note:   candidate expects 1 argument, 4 provided
Using library SPI at version 1.0 in folder: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI 
Using library Ethernet at version 2.0.0 in folder: /Applications/Arduino.app/Contents/Java/libraries/Ethernet 
Using library Dmx in folder: /Users/Newlin/Documents/Arduino/libraries/Dmx (legacy)
Using library LiquidCrystal at version 1.0.7 in folder: /Applications/Arduino.app/Contents/Java/libraries/LiquidCrystal 
exit status 1
no matching function for call to 'EthernetUDP::write(uint8_t*&, uint16_t&, uint8_t [4], uint16_t&)'

Follow the example sketch's syntax. You set the remote IP and port using Udp.beginPacket(), then only send the packet using Udp.write(). There is more information about this in the UDP.write() reference page:

pert:
Follow the example sketch's syntax. You set the remote IP and port using Udp.beginPacket(), then only send the packet using Udp.write(). There is more information about this in the UDP.write() reference page:
Ethernet - Arduino Reference

I have already read that documentation, and I am trying, but I'm not a coder. I'm a hobbyist, and I'm also working with someone else's code who was more experienced than me. You may need to spell it out. :slight_smile: Thanks.

Well, it's all fixed. After giving my brain a break I saw the problem. I was trying to figure out what to pass to the Udp.write(), because I wasn't sure what variables were used for the packet information and size, until I realized they were staring me in the face.

void send_reply(uint8_t mode_broadcast, uint8_t *packet, uint16_t size)
{
  if(mode_broadcast == 1) // send broadcast packet
  {
    Udp.beginPacket(ArtNode.remoteIp, ArtNode.remotePort);
    Udp.write(packet, size);
    Udp.endPacket();
  }
  else // send unicast packet to controller
  {
    Udp.beginPacket(ArtNode.remoteIp, ArtNode.remotePort);
    Udp.write(packet, size);
    Udp.endPacket();
  }
}

It all compiles quite nicely now. :slight_smile:

Great work getting it working lulighttec!

pert:
Great work getting it working lulighttec!

Thank you for pointing me in the right direction! :smiley: