简体   繁体   English

无匹配 Function 开始多播 - Arduino/cpp

[英]No Matching Function Begin Multicast - Arduino/cpp

I was given a project to convert from ESP8266 to ESP32, and I'm definitely not a coder, but it needs to get done.我得到了一个从 ESP8266 转换为 ESP32 的项目,我绝对不是编码员,但它需要完成。 So I was hoping I could get some guidance/help on how to solve this issue.所以我希望我能得到一些关于如何解决这个问题的指导/帮助。 I'm basically taking previous code from an old project using an ESP8266 WiFi module and converting it over to a more updated module using ESP32.我基本上是从使用 ESP8266 WiFi 模块的旧项目中获取以前的代码,并使用 ESP32 将其转换为更新的模块。 Been compiling and troubleshooting code as I go the best I can, but this one has stumped me.一直在编译和故障排除代码,因为我尽我所能 go,但是这个让我很难过。

The error message I'm getting is "No matching function for call to 'WiFiUDP::beginMulticast(IPAddress, IPAddress&, const unsigned int&)'我收到的错误消息是“No matching function for call to 'WiFiUDP::beginMulticast(IPAddress, IPAddress&, const unsigned int&)'

There are several pages of code, but this is the.cpp file that is currently throwing up an error, and hoping it's able to be resolved with something on this page.有几页代码,但这是当前抛出错误的 .cpp 文件,并希望能够通过此页面上的某些内容来解决它。 Like I said, I'm not a coder, but I have the basics down.就像我说的,我不是编码员,但我已经掌握了基础知识。 Any help on this would be greatly appreciated.对此的任何帮助将不胜感激。 Thanks!谢谢!

#include "Switch.h"
#include <functional>
 
// Multicast declarations
IPAddress ipMulti(239, 255, 255, 250);
const unsigned int portMulti = 1900;
char packetBuffer[512];   

#define MAX_SWITCHES 14
Switch switches[MAX_SWITCHES] = {};
int numOfSwitchs = 0;

//#define numOfSwitchs (sizeof(switches)/sizeof(Switch)) //array size  
 
//<<constructor>>
UpnpBroadcastResponder::UpnpBroadcastResponder(){
    
}
 
//<<destructor>>
UpnpBroadcastResponder::~UpnpBroadcastResponder(){/*nothing to destruct*/}
 
bool UpnpBroadcastResponder::beginUdpMulticast(){
  boolean state = false;
  
  Serial.println("Begin multicast ..");
  
  if(UDP.beginMulticast(WiFi.localIP(), ipMulti, portMulti)) {
    Serial.print("Udp multicast server started at ");
    Serial.print(ipMulti);
    Serial.print(":");
    Serial.println(portMulti);

    state = true;
  }
  else{
    Serial.println("Connection failed");
  }
  
  return state;
}

//Switch *ptrArray;

void UpnpBroadcastResponder::addDevice(Switch& device) {
  Serial.print("Adding switch : ");
  Serial.print(device.getAlexaInvokeName());
  Serial.print(" index : ");
  Serial.println(numOfSwitchs);
  
  switches[numOfSwitchs] = device;
  numOfSwitchs++;
}

void UpnpBroadcastResponder::serverLoop(){
  int packetSize = UDP.parsePacket();
  if (packetSize <= 0)
    return;
  
  IPAddress senderIP = UDP.remoteIP();
  unsigned int senderPort = UDP.remotePort();
  
  // read the packet into the buffer
  UDP.read(packetBuffer, packetSize);
  
  // check if this is a M-SEARCH for WeMo device
  String request = String((char *)packetBuffer);

  if(request.indexOf('M-SEARCH') > 0) {
      if(request.indexOf("urn:Belkin:device:**") > 0) {
        Serial.println("Got UDP Belkin Request..");
        
        // int arrSize = sizeof(switchs) / sizeof(Switch);
      
        for(int n = 0; n < numOfSwitchs; n++) {
            Switch &sw = switches[n];

            if (&sw != NULL) {
              sw.respondToSearch(senderIP, senderPort);              
            }
        }
      }
  }
}```

The Arduino UDP API as defined by the UDP base class in Arduino core has The Arduino UDP API as defined by the UDP base class in Arduino core has

uint8_t beginMulticast(IPAddress, uint16_t); 

In esp8266 Arduino WiFi the UDP is modified and the first parameter of beginMulticast specifies the network interface to listen to.在 esp8266 Arduino WiFi 中 UDP 被修改,beginMulticast 的第一个参数指定要监听的网络接口。 (Network interfaces are STA, SoftAP, Ethernet etc) (网络接口为 STA、SoftAP、以太网等)

In esp32 Arduino WiFi library beginMulticast has only the standard parameters and listens on all network interfaces.在 esp32 中,Arduino WiFi 库 beginMulticast 只有标准参数并监听所有网络接口。

Your solution is to remove the first parameter in the beginMulticast call.您的解决方案是删除 beginMulticast 调用中的第一个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM