me-no-dev / ESPAsyncUDP

Async UDP library for ESP8266
173 stars 56 forks source link

Reading packet Data #40

Closed Turtle9er closed 4 years ago

Turtle9er commented 4 years ago

Not really an issue, more a plea for help. I want to send simple values via UDP, but I can't for the life of me figure out how to take the packet.data() and get the information. I am using the examples and Serial.write(packet.data(), packet.length()); works to print it, but for some reason my brain can't seem to comprehend how to just assign a variable to packet.data(). Sorry if not correct place to ask this, but I have search for days and can't seem to figure it out. Thanks in advance.

EdvardPavsic commented 4 years ago

I am no expert and had the same "problem". packet.data() function returns address of the buffer(pointer to the buffer). Like this: uint8_t addr; //pointer addr=packet.data(); byte var1=addr++; byte var2=addr++; byte var3=addr++; I managed to extract the bytes, where my data is received. Those are the first three bytes in the receive buffer. If You need more, just continue. You could also copy them in a loop.

If I wrote something wrong please correct me. BR, Edvard

luxorbis commented 4 years ago

Have a look at this: https://forum.arduino.cc/index.php?topic=639656.0

stale[bot] commented 4 years ago

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.