Closed locchi93 closed 8 years ago
you need to reopen the UDP socket after a Wifi disconnect. a simple way is:
if(WiFi.status() == WL_CONNECTED) {
if(!udp) {
udp.begin(1234);
}
}
in the loop.
Ok... but this in not the main problem... The problem is the disconnection itself. What causes the disconnection?
I have seen something like this only with a very old router. there I was able to increase the time between the disconnects by changing the beacon interval, but I wasn't able to fix it.
I have an Asus n55u... I will try to play with the beacon interval
EDIT: Changing the beacon interval don't seem to chance anything. I don't know what to try.
have you a longer time where you not call delay in you code?
This is the loop, it's really basic. With the "yield()" call, the wifi should operate properly:
void loop() {
noBytes = Udp.parsePacket();
if (noBytes) {
Udp.read(packetBuffer,noBytes);
Serial.println("riceived");
handleMessage(packetBuffer[0],noBytes);
}
yield();
}
at the end off the loop "yield" is done automatically ;)
in this part of the code i not see any problems.
have you the same problem when the loop
is empty?
WiFi.RSSI();
I think I've solved the problem some how... I have changed some configuration on my router (asus n55u), now the connection seems stable! I have enabled "Snooping IGMP" and this seems the key to make it work... but why?
if i remember right IGMP is used to build up the multicast routing. may if it not enabled the ESP get the wrong packages or non packages and then disconnect the WiFi.
I just ran across this myself. I have one ESP in softAP mode, and another one in station mode. The first one is sending 20pps UDP traffic to the second one (yes that would be DMX-ish data). After exactly 5 minutes the station goes 'offline'. The code is really simple, so there should be no surprises there.
WiFi connection
void connect() {
udp.stop();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
blink();
}
udp.begin(7654);
}
The loop:
void loop() {
if (WiFi.status() == WL_CONNECTED) {
if (!udp)
udp.begin(7654);
int packetSize = udp.parsePacket();
if (packetSize > 0) {
int len = udp.read(buffer, 128);
buffer[len] = 0;
for (int i = START_ID; i <= END_ID; i++) {
digitalWrite(pins[i - START_ID], (buffer[i] > 0) ? LOW : HIGH);
}
blink();
}
} else {
connect();
}
}
I added the WL_CONNECTED and connect() call to work around the issues. Without this it would just hang.
The AP is working like a champ, I have not seen any issues with that one that I can think of.
This is running the latest 'official' arduino esp8266 code, SDK 1.2.0. I have seen other threads where upgrading the SDK to 1.3 or 1.4 may solve issues, anyone know how to do that? Just copy in the new sdk and change boards.txt to use the new names?
the latest git version uses SDK 1.3.0_15_08_10_p1
I'll try to grab that and see if that changes anything. Thanks!
Would it be sufficient to use the Statging version, or would I need a git clone and build?
a git clone
and then run build/build_board_manager_package.sh shut do it.
you may can use --depth
if you not need the full git history.
Hmmm, same thing with 1.3.0 (pulled and generated board manager this morning). I get just over 5 minutes (6018-6019 packets sent at 20pps, to be exact). If I wanted to try 1.4.0 (I have it downloaded), would it be more than just replacing the libs and ld?
Also, is there some status that I could check that might indicate why it got disconnected? I doubt there is log, but some status flags I could print out?
yes 1.4.0 has some changes with task and idle handling @igrr has done some first test but there is no really usable version now. the SDK only gives a disconnect event and a reason as uint8_t to meaning is may be linked to this enum: https://github.com/esp8266/Arduino/blob/cabb450fc13eefaf35a78b9a911d59efd548b81a/hardware/esp8266com/esp8266/tools/sdk/include/user_interface.h#L346 but you not find a real description in the SDK docs.
I have some problems with my program. It's a simple UDP server (connected to my router) listening on port 8888 for incoming data. All runs great, I can send data to it and I get the reply back. The problem is that if it keep listening for 5 minutes, without sending data to it, i get this from the serial wifi debug
I don't know if the problem is related to the settings of my router... or something else... After this "reconnect," i'm unable to comunicate with the device through UDP, but I can see it running from the serial monitor. I constantly check the heap and remains constant to "30072".