-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UDP not receiving data after sometimes #7007
Comments
@komputerboy Please can you retry with latest git master version ? |
I have the same problem. I updated today to 2.6.3 and uploaded the sketch and still having the same issue. I have tried everything but after somewhere between 5 and 20 minutes the connection is lost and ESP8266 no longer receives UDP packets. If I ping the ESP8266 from my router, after about 1 minute it will come back online. During the network dropout, the ESP8266 is unreachable, but it's returning WL_CONNECTED, and using event handling, it will never register an event under OnStationModeDisconnected, despite the fact that it is no longer responding on the network. |
@komputerboy @reynolds087 |
I am willing to try it, but I don't know how to install. Can you send me a link to instructions or just quickly explain? My experience with updating my ESP8266 is just updating the libraries in the Arduino IDE through the board manager. That is how I installed 2.6.3 yesterday. |
Nevermind, I see the link for the board manager on the page. I will try it. |
I'm not sure if I did it correctly. I added a link to the repository in the preferences under "additional board manager URLs". I left the existing link in there as well so it has this string: . I then updated esp8266 by ESP8266 Community in the board manager to version 0.0.1--git-version--2.6.3-86-gc61b0de to 0.0.1 Restarted Arduino IDE ESP8266 Boards (2.6.3-86-gc61b0de) now shows in the Tools => Board context menu. Do I need to delete the old library or take other steps in order to ensure that I am using the correct library? Not sure if you need to know this, but I am including the following libraries in my sketch: #include <stdio.h> |
I am running your example without issue for more than 15 minutes.
|
Do you see anything in my sketch that would be causing this problem? I don't understand why it's dropping out. No other device on my network has connection instability. #include <stdio.h>
#include <Arduino.h>
#include <Ticker.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ESP8266WiFiMulti.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
const char* routerIP = "";
const char* ssid = "";
const char* password = "";
WiFiUDP UDPTestServer;
ESP8266WiFiMulti WiFiMulti;
unsigned int UDPPort = 6666;
const int packetSize = 255;
char packetBuffer[packetSize];
char keepAlivePacket[] = "Test_Keep_Alive";
Ticker keepAliveTicker;
WiFiEventHandler connectedEventHandler, disconnectedEventHandler, gotIpEventHandler;
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
String strButtonPress = ""; //Console input to initiate IR signal send
IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message.
void setup()
{
Serial.begin(115200);
delay(20);
connectedEventHandler = WiFi.onStationModeConnected([](const WiFiEventStationModeConnected& event)
{
Serial.println("");
Serial.println("Station Connected");
});
gotIpEventHandler = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP& event)
{
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
});
disconnectedEventHandler = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected& event)
{
Serial.println("Station disconnected");
});
WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
keepAliveTicker.attach(60, KeepAlive);
while (WiFiMulti.run() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
irsend.begin();
UDPTestServer.begin(UDPPort);
}
int value = 0;
void loop()
{
if (WiFi.status() != WL_CONNECTED)
{
delay(1);
WiFiMulti.run();
return;
}
handleUDPServer();
strButtonPress = "";
delay(1);
}
void handleUDPServer() {
int cb = UDPTestServer.parsePacket();
if (cb) {
int len = UDPTestServer.read(packetBuffer, packetSize);
if (len > 0)
{
packetBuffer[len] = 0;
}
for(int i = 0; i < strlen(packetBuffer); i++) {
strButtonPress += packetBuffer[i];
}
strButtonPress.trim();
Serial.println(strButtonPress);
if(strButtonPress.indexOf("NEC_Power") >= 0)
{
Serial.println("Sending NEC_Power...");
irsend.sendNEC(0x20DF10EF);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Input") >= 0)
{
Serial.println("Sending NEC_Input...");
irsend.sendNEC(0x20DFF40B);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Volume_Up") >= 0)
{
Serial.println("Sending NEC_Volume_Up...");
irsend.sendNEC(0x20DF40BF);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Volume_Down") >= 0)
{
Serial.println("Sending NEC_Volume_Down...");
irsend.sendNEC(0x20DFC03F);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Channel_Up") >= 0)
{
Serial.println("Sending NEC_Channel_Up...");
irsend.sendNEC(0x20DF00FF);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Channel_Down") >= 0)
{
Serial.println("Sending NEC_Channel_Down...");
irsend.sendNEC(0x20DF807F);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Mute") >= 0)
{
Serial.println("Sending NEC_Mute...");
irsend.sendNEC(0x20DF906F);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Menu") >= 0)
{
Serial.println("Sending NEC_Menu...");
irsend.sendNEC(0x20DFF20D);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Exit") >= 0)
{
Serial.println("Sending NEC_Exit...");
irsend.sendNEC(0x20DF926D);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Ok") >= 0)
{
Serial.println("Sending NEC_Ok...");
irsend.sendNEC(0x20DF22DD);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Up") >= 0)
{
Serial.println("Sending NEC_Up...");
irsend.sendNEC(0x20DFA25D);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Down") >= 0)
{
Serial.println("Sending NEC_Down...");
irsend.sendNEC(0x20DF629D);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Left") >= 0)
{
Serial.println("Sending NEC_Left...");
irsend.sendNEC(0x20DFE21D);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Right") >= 0)
{
Serial.println("Sending NEC_Right...");
irsend.sendNEC(0x20DF12ED);
UDPTestServer.flush();
}
else if(strButtonPress.indexOf("NEC_Back") >= 0)
{
Serial.println("Sending NEC_Back...");
irsend.sendNEC(0x20DF52AD);
UDPTestServer.flush();
}
else {}
}
}
void KeepAlive()
{
Serial.println("Sending Packet");
UDPTestServer.beginPacket(routerIP, UDPPort);
UDPTestServer.write(keepAlivePacket);
UDPTestServer.endPacket();
Serial.println("Packet Sent");
}
|
Did you try to disable ticker ? |
@d-a-v I can try that, but I only added the ticker to try and correct the timeout issue. It sends a UDP message to another computer on the network. I was hoping it would keep the device connected, but it didn't help. For some reason, the device will become unreachable after a period of time and not receive UDP packets. I can't find any rhyme or reason because it will sporadically reconnect, but it's not reliable. The two things that seem to force it start sending or receiving again are when I reboot it or ping it for a few minutes. When I first start pinging it will time out, but then eventually I get a response, and then I can send the UDP. |
Ok, I tried 'ticker.attach_scheduled()', but it didn't help. |
Did you try |
I added that line in, but it just did the same thing. Not responding to pings or UDP commands after a while. |
Magical solution for that kind of issue may include one or several tests from the following list:
|
@d-a-v |
It's unofficial API, it currently is
You can use it anytime, it will send gratuitous ARP packets only when interface is up at the given interval. |
That seems to have fixed the issue for me. Sometimes I have to send the command 4 or 5 times if I haven't connected to it in a while, but I no longer have to ping the device for 2 minutes before it will respond. |
Thanks for testing ! |
#6889 is merged, closing |
How can i use this function ? The IDE give me this error when i try to compile |
Try (updated) #include <ESP8266WiFiGratuitous.h>
…
experimental::ESP8266WiFiGratuitous::stationKeepAliveSetIntervalMs(5000);` |
Basic Infos
Platform
Settings in IDE
Problem Description
I have problem with WiFi UDP program with UDP Example. In the beginning Wemos is receiving UDP data. But after some minutes ( > 5 minutes ), Wemos is not receiving UDP data.
Any solution?
Thank You.
Code
The text was updated successfully, but these errors were encountered: