cannot reach esp8266 via udp while he is running with a static ip

#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");
}

0
0
Awgiedawgie 440220 points

                                    #include &lt;ESP8266WiFi.h&gt;
#include &lt;WiFiUdp.h&gt;

IPAddress ip_sta;
WiFiUDP udp;

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

	//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(&quot;PACKET: &quot;); Serial1.println(packetBuffer);
		Serial1.print(&quot;LENGTH: &quot;); Serial1.println(len);
	}
}

0
0
4.5
6
Awgiedawgie 440220 points

                                    #include &lt;ESP8266WiFi.h&gt;
#include &lt;WiFiUdp.h&gt;

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(&quot;testtest&quot;, &quot;testtest&quot;);
}

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

4.5 (6 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source