On the last image in post #18, look above the line I quoted, just above the "This class enables..." line. It's there. Whether it was cut-and-pasted, or misbegottenly verbatim-typed by someone who didn't know, I have no way of knowing.
You mean this?
But that's the OP's image - that's the one with the problem!
That image doesn't actually appear on the Particle site - so it appears that @fester225* has made a copy-paste error in that.
EDIT
* Or whoever Fester got it from
Hi @fester225,
please read my post no 16 and - if you use the particle IDE - the following link
https://community.particle.io/t/how-to-include-library-files-using-particle-build-ide/26141
It is quite likely that you did not include the required library for the UDP class and copied parts of the reference page that do not belong to the code.
Good luck!
from Bard.Google.com: You have to create a new instance of a class inside your program because each instance of a class needs to have its own unique state. For example, each instance of the WiFiUDP class needs to have its own unique local port number.
(from fester225: This brings up the problem of what a 'class' is)
Class 06NOV2023 Bard.Google
What is a definition of 'class' as it pertains to C++
In C++, a class is a user-defined data type that encapsulates data and functions into a single unit. Classes are the building blocks of object-oriented programming, and they allow you to create objects that represent real-world entities, such as cars, people, and bank accounts.
A class definition consists of two parts: the declaration and the definition. The declaration specifies the name of the class and its members, while the definition provides the implementation of the class's members.
Here is an example of a simple class definition in C++:
C++
class Car {
public:
string name;
int speed;
void start();
void accelerate();
void brake();
};
Use code with caution. Learn more
This class definition declares a class called Car
with three members:
name
: A string variable that stores the name of the car.speed
: An int variable that stores the speed of the car.start()
,accelerate()
, andbrake()
: Member functions that allow you to start, accelerate, and brake the car, respectively.
Once you have defined a class, you can create objects of that class using the new
operator. For example, the following code creates a new Car
object:
C++
Car myCar = new Car();
Use code with caution. Learn more
You can then access the members of the myCar
object using the dot operator. For example, the following code sets the name and speed of the car:
C++
myCar.name = "Honda Civic";
myCar.speed = 60;
Use code with caution. Learn more
You can also call the member functions of the myCar
object to start, accelerate, and brake the car:
C++
myCar.start();
myCar.accelerate();
myCar.brake();
Use code with caution. Learn more
Classes can also be used to create inheritance hierarchies. Inheritance allows you to create new classes that inherit the properties of existing classes. For example, you could create a SportsCar
class that inherits from the Car
class:
C++
class SportsCar : public Car {
public:
int maxSpeed;
void boost();
};
Use code with caution. Learn more
The SportsCar
class inherits all of the members of the Car
class, plus it has an additional member function, boost()
, which allows you to boost the car's speed.
Classes are a fundamental concept in object-oriented programming. They provide a way to organize your code and make it more reusable and maintainable.
I hope this helps!

View other drafts
You have to create a new instance of a class inside your program because each instance of a class needs to have its own unique state. For example, each instance of the WiFiUDP class needs to have its own unique local port number.
If you were to not create a new instance of WiFiUDP, you would be using the same object for all of your UDP communication. This would cause problems if you were trying to send and receive UDP packets on multiple ports at the same time.
By creating a new instance of WiFiUDP for each port that you need to use, you can ensure that each port has its own unique state and that your UDP communication works as expected.
Here is an example of how to use multiple instances of WiFiUDP:
C++
#include <WiFi.h>
#include <WiFiUDP.h>
WiFiUDP WiFiUdp1;
WiFiUDP WiFiUdp2;
void setup() {
Serial.begin(115200);
// Bind WiFiUdp1 to port 1234
WiFiUdp1.begin(1234);
// Bind WiFiUdp2 to port 5678
WiFiUdp2.begin(5678);
Serial.println("UDP servers started!");
}
void loop() {
// Check if there is any data available on port 1234
if (WiFiUdp1.available()) {
// Receive the data
char buffer[128];
int bytesRead = WiFiUdp1.read(buffer, sizeof(buffer));
// Print the received data to the serial monitor
Serial.println(buffer);
}
// Check if there is any data available on port 5678
if (WiFiUdp2.available()) {
// Receive the data
char buffer[128];
int bytesRead = WiFiUdp2.read(buffer, sizeof(buffer));
// Print the received data to the serial monitor
Serial.println(buffer);
}
}
Use code with caution. Learn more
This code will create two instances of the WiFiUDP class, one for each port that we need to use. We then bind WiFiUdp1 to port 1234 and WiFiUdp2 to port 5678.
In the loop() function, we check if there is any data available on either port. If there is, we receive the data and print it to the serial monitor.
This code demonstrates why it is necessary to create a new instance of WiFiUDP for each port that you need to use. If we were to not create a new instance of WiFiUDP, we would not be able to receive data on both ports at the same time.
I hope this helps!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.