MDNS stop responding for some time after I send data
Posted: Thu Mar 22, 2018 1:12 pm
Hi,
My code is very simple, I use my esp8266 as a server which should wait for a client connection to read data from it and transmit it to the Arduino via the serial.
I use also the mDNS to detect the IP addresses of the ESP8266 inside the network and here's the code :
I use my phone app as a client and the code work perfectly, I scan for the “_SmartDimmerx2._tcp.local.” and the phone detect the esp with its IP addresses.
I was able to send data to the ESP and it receive it correctly and then send it back to arduino through serial,
The problem was after I send continuously some data to the ESP and then i try again to scan for the mDNS the ESP didn't respond. The ESP still not responding to the mDNS scan for like 30 seconds/1 minutes and after that it become discoverable again.
In the meantime when the mDNS is not responding the ESP still able to receive data from the phone and send it through the serial without any problem and display the correct data. So the esp is not bugged.
I feel like something is blocking the mDNS service when I send a lot of data from the phone. Did I made something wrong in my code ?
When the mDns is not responding I tried to scan with Zeroconf android app and it didn't respond too until after like one minute.
My code is very simple, I use my esp8266 as a server which should wait for a client connection to read data from it and transmit it to the Arduino via the serial.
I use also the mDNS to detect the IP addresses of the ESP8266 inside the network and here's the code :
Code: Select all
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <EEPROM.h>
.....
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
if (!MDNS.begin("Device 1")) { //
while (1) { delay(1000); }
}
MDNS.addService("SmartDimmerx2", "tcp", 80);
WiFi.mode(WIFI_STA);
delay(4000);
// Check if WiFi is already connected and if not,
if (WiFi.status() != WL_CONNECTED){
Serial.println("Disconnected");
ConnecStat_Toarduino = false;
}
else {
Serial.println("Connected");
ConnecStat_Toarduino = true;
}
// Start the server
server.begin();
}
void loop() {
MDNS.update();
if (WiFi.status() != WL_CONNECTED) {
Serial.println("Disconnected");
ConnecStat_Toarduino = false;
delay(100);
}
else if ((WiFi.status() == WL_CONNECTED) && (ConnecStat_Toarduino = false)) {
Serial.println("Connected");
ConnecStat_Toarduino = true;
}
if (Serial.available() > 0) {
String incomingChars = Serial.readStringUntil('\n');
if(incomingChars.indexOf("WPS") != -1) {
WPS_fnct();
}
}
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
time_cnx = millis();
return;
}
// Wait until the client sends some data
while (!client.available()) {
if ((millis() - time_cnx)>2000)
{return;}
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
client.flush();
client.stop();
// Match the request
int val;
if (req.indexOf("V=") != -1)
{
Serial.print(req.substring(2,5));
Serial.println(req.substring(7,11));
//Serial.println(char(req.substring(8,10).toInt()));
}
else {
client.stop();
return;
}
}
I use my phone app as a client and the code work perfectly, I scan for the “_SmartDimmerx2._tcp.local.” and the phone detect the esp with its IP addresses.
I was able to send data to the ESP and it receive it correctly and then send it back to arduino through serial,
The problem was after I send continuously some data to the ESP and then i try again to scan for the mDNS the ESP didn't respond. The ESP still not responding to the mDNS scan for like 30 seconds/1 minutes and after that it become discoverable again.
In the meantime when the mDNS is not responding the ESP still able to receive data from the phone and send it through the serial without any problem and display the correct data. So the esp is not bugged.
I feel like something is blocking the mDNS service when I send a lot of data from the phone. Did I made something wrong in my code ?
When the mDns is not responding I tried to scan with Zeroconf android app and it didn't respond too until after like one minute.