Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Barnabybear
#47626 Hi, I’m using the Arduino IDE 2.0 & WiFiUdp.h to send sCAN packets. With the way I need it to work, it has to send to various multicast addresses that are defined by variables. If I could pre-set these it would be easy, but I can’t and there are 65,535 (0xffff) possible options,
Code: Select all239.255.0.1 through to 239.255.255.255

so a look up is not going to work unless I have to.
Does anyone know how to construct an IP address from variables?
I'm currently using:
Code: Select allIPAddress IP_Multicast_Out(239, 255, 0, 1);
unsigned int Port_Multicast_Out = 5568;

followed by
Code: Select allUdp.beginPacketMulticast(IP_Multicast_Out, Port_Multicast_Out, WiFi.localIP());

which works fine for Udp.writes to a single IP. If I try to introduce variables at any point (that I've tried - to many to list) it doesn't compile or sends to 0.0.0.0 .
I'm guessing the 'IPAddress' format is something I'm missing, any help appreciated.
User avatar
By bbx10node
#47639 IP address is a uint32_t but can be accessed as an array of 4 uint8_t.

Code: Select all#include <ESP8266WiFi.h>

void setup() {
  Serial.begin(115200);
  Serial.println();

  IPAddress ipa;
  ipa[0] = 239;
  ipa[1] = 255;
  ipa[2] =   0;
  for (int i = 0; i < 256; i++) {
    ipa[3] = i;
    Serial.println(ipa);
  }
}

void loop() {
}