Add README.md with example

This commit is contained in:
2021-10-14 23:43:59 +02:00
committed by GitHub
parent 1db1655f18
commit 94ce37c6ba

37
README.md Normal file
View File

@ -0,0 +1,37 @@
# espasyncudplistener
ESP32 async udp listener
## Example usage
```C++
#include <esp_log.h>
#include <espwifiutils.h>
#include <asyncudplistener.h>
namespace {
constexpr const char * const TAG = "MYAPP";
} // namespace
AsyncUdpListener udpListener;
void setup()
{
constexpr const uint16_t listeningPort = 1234;
if (!udpListener.listen(listeningPort))
ESP_LOGE(TAG, "could not start listening on udp (port=%i)", listeningPort);
}
void handleUdpPacket(const UdpPacketWrapper &packet)
{
ESP_LOGI(TAG, "udp response from %s : \"%.*s\"",
wifi_stack::toString(packet.remoteAddr()).c_str(),
packet.data().size(), packet.data().data());
// TODO: further processing of packet
}
void handleUdpPackets()
{
while (const auto &packet = udpListener.poll())
handleUdpPacket(*packet);
}
```