There is a pointer to a void passed to the function. You know, that it really is a pointer to a AsyncClient type. To access the functions from the AsyncClient class, you need to cast the void pointer to a pointer to AsyncClient.
LightuC:
There is a pointer to a void passed to the function. You know, that it really is a pointer to a AsyncClient type. To access the functions from the AsyncClient class, you need to cast the void pointer to a pointer to AsyncClient.
Both lines does the same, they are casting an ambiguous void pointer to something else. The difference is that the first line has no error checking, you could cast anything to anything like this. The second line has some compile time error checking which will dissalow most bogus castings from happening.
Both lines does the same, they are casting an ambiguous void pointer to something else. The difference is that the first line has no error checking, you could cast anything to anything like this. The second line has some compile time error checking which will dissalow most bogus castings from happening.
[More info](https://en.cppreference.com/w/cpp/language/reinterpret_cast).
I would avoid the casting and just declare the correct method argument like this:
Which sets a timer to call the function "replyToServer" with the argument "client". In order to use "client" as an instance of "AsyncClient" the cast in "replyToServer" is required.
EDIT: Btw, the timer is never armed, so it does nothing AFAICT. The code in post #5 fails because "client" is not a valid pointer.
Which sets a timer to call the function "replyToServer" with the argument "client". In order to use "client" as an instance of "AsyncClient" the cast in "replyToServer" is required.
EDIT: Btw, the timer is never armed, so it does nothing AFAICT. The code in post #5 fails because "client" is not a valid pointer.
I'm sorry im trying to follow along i tried this,
void loop() {
testFunction();
}
void testFunction(){
if (millis() - now >= 1000) {
AsyncClient* client;
replyToServer(client);
now = millis();
}
}
but the esp crashes as soon as it connects?
I dont want to break the ASync functionality of the code but for the client i think it would be nice to just be able to send whatever data i need to when i need to.
void testFunction(){
if (millis() - now >= 1000) {
AsyncClient* client; //client is NULL, using it will fail
replyToServer(client);
now = millis();
}
}
If you want global access to the "AsyncClient" instance, then you need to declare it as a global variable instead of a local variable in "setup()". The "client" variable in the original code is only valid in "setup()", "handleData(..)" and "onConnect(..)".
Danois90:
You are using and unintialized pointer / object:
void testFunction(){
if (millis() - now >= 1000) {
AsyncClient* client; //client is NULL, using it will fail
replyToServer(client);
now = millis();
}
}
If you want global access to the "AsyncClient" instance, then you need to declare it as a global variable instead of a local variable in "setup()". The "client" variable in the original code is only valid in "setup()", "handleData(..)" and "onConnect(..)".
Thanks, declaring it globally did the trick for now. Thanks again
I wish there was more documentation on the ESPASyncTCP. the only problem i really have with it is it seems kinda sluggish. 1 message a second tops without lag and freezes. it never crashed but just slow. i dont know if there is a receive buffer to empty or not.