Skip to content

2.5.0: WiFiUDP Broadcast using static IP & AsyncUDP Broadcast problem #5757

Open
@ErinQvnm

Description

@ErinQvnm

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: [ESP-12F | ESP12-S]
  • Core Version: [2.5.0 Stable & Git 6c5269a]
  • Development Env: [Arduino IDE]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Generic ESP8266 Module | Nodemcu]
  • Flash Mode: [dio]
  • Flash Size: [4MB/1MB]
  • lwip Variant: [v2 Lower Memory]
  • Reset Method: [ck]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200]

Problem Description

I'm using 2 ESPs as a server and a client. UDP broadcast didn't work when client using static IP. I tried using WiFiUDP library.
I also tried using me-no-dev AsyncUDP library. udp.broadcastTo() stopped working.
All the sketch below worked for core 2.4.2, after 2.5.0 they just doesn't work.

MCVE Sketch

###Using WiFiUDP library:
Server:

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

IPAddress ip_ap(192, 168, 1, 123);
IPAddress gw_ap(192, 168, 1, 1);
IPAddress sn_ap(255, 255, 255, 0);
WiFiUDP udp;

void setup() {
	Serial1.begin(921600);
	WiFi.softAPConfig(ip_ap, gw_ap, sn_ap);
	WiFi.softAP("testtest", "testtest");
}

void loop() {
	delay(1000);
	udp.beginPacket(IPAddress(192, 168, 1, 255), 2424);
	udp.print("TEST TEST");
	udp.endPacket();
}

Client:

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

IPAddress ip_sta;
WiFiUDP udp;

void setup() {
	Serial1.begin(921600);
	WiFi.begin("testtest", "testtest");
	while (WiFi.status() != WL_CONNECTED) {
		delay(1000);
		Serial1.print(".");
	}

	//Set client to static IP
	ip_sta = WiFi.localIP();
	ip_sta[3] = 115;
	WiFi.config(ip_sta, WiFi.gatewayIP(), WiFi.subnetMask()); //if comment this line code runs perfectly

	udp.begin(2424);
}

void loop() {
	int packetsize = udp.parsePacket();
	if (packetsize) {
		char packetBuffer[32];
		int len = udp.read(packetBuffer, 32);
		packetBuffer[31] = 0;
		Serial1.print("PACKET: "); Serial1.println(packetBuffer);
		Serial1.print("LENGTH: "); Serial1.println(len);
	}
}

###Using AsyncUDP library:

#include <ESP8266WiFi.h>
#include <ESPAsyncUDP.h>

IPAddress ip_ap(192, 168, 1, 123);
IPAddress gw_ap(192, 168, 1, 1);
IPAddress sn_ap(255, 255, 255, 0);
AsyncUDP udp;

void setup() {
	Serial1.begin(921600);
	WiFi.softAPConfig(ip_ap, gw_ap, sn_ap);
	WiFi.softAP("testtest", "testtest");
}

void loop() {
	delay(1000);
	udp.broadcastTo("Anyone here?", 2424);
	Serial1.println("LOOP");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions