gpt4 book ai didi

c++ - ESP32-AsyncUDP 自带的 udp.onPacket 处理函数

转载 作者:行者123 更新时间:2023-12-02 10:37:54 29 4
gpt4 key购买 nike

您能帮我在下面的示例中如何声明 udp.onPacket 的处理程序吗?

  if(udp.listen(1234)) {
Serial.print("UDP Listening on IP: ");
Serial.println(WiFi.localIP());
udp.onPacket([](AsyncUDPPacket packet) {
Serial.print("UDP Packet Type: ");
Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
Serial.print(", From: ");
Serial.print(packet.remoteIP());
Serial.print(":");
Serial.print(packet.remotePort());
});
}

我想要这样的代码
  if(udp.listen(1234)) {
Serial.print("UDP Listening on IP: ");
Serial.println(WiFi.localIP());
udp.onPacket(processPacketHandler);
}

void processPacketHandler ...

最佳答案

我不确定 Arduino C++ 中的绑定(bind)函数。我会试试这个:

    if(udp.listen(1234)) {
Serial.print("UDP Listening on IP: ");
Serial.println(WiFi.localIP());
udp.onPacket([](AsyncUDPPacket packet) { processPacketHandler(packet); });
}

void processPacketHandler(AsyncUDPPacket packet){ ...

关于c++ - ESP32-AsyncUDP 自带的 udp.onPacket 处理函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59416104/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com