Esp8266 re-connect!
Posted: Tue Jan 24, 2017 5:42 am
Dear all
I have implemented a code that among others connects the ESP8266 to my wifi. The problem is that if the Wifi is unavailable, for some reason, the esp8266 does not reconnect to it. How can I force reconnection upon disconnection?
This is the code used to connect to my wifi and set up a server
sendData("AT+RST\r\n",2000,DEBUG); // reset module
sendData("AT+CWMODE=1\r\n",1000,DEBUG); // configure as access point
sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
sendData("AT+CWJAP=\"Rafina\",\"4112703241\"\r\n",5000,DEBUG);
sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
sendData is a function that simply sends the data to esp8266.
I have tried to re-initiate the connection with the following code every 4 hours, but it is not efficient:
interval2= 1400000000;
if (curEspMillis - prevEspMillis >= interval2) {
sendData("AT+RST\r\n",2000,DEBUG); // reset module
sendData("AT+CWMODE=1\r\n",1000,DEBUG); // configure as access point
sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
sendData("AT+CWJAP=\"Rafina\",\"4112703241\"\r\n",5000,DEBUG);
sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
}
Is there a better way?
Regards
Panseptos
I have implemented a code that among others connects the ESP8266 to my wifi. The problem is that if the Wifi is unavailable, for some reason, the esp8266 does not reconnect to it. How can I force reconnection upon disconnection?
This is the code used to connect to my wifi and set up a server
sendData("AT+RST\r\n",2000,DEBUG); // reset module
sendData("AT+CWMODE=1\r\n",1000,DEBUG); // configure as access point
sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
sendData("AT+CWJAP=\"Rafina\",\"4112703241\"\r\n",5000,DEBUG);
sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
sendData is a function that simply sends the data to esp8266.
I have tried to re-initiate the connection with the following code every 4 hours, but it is not efficient:
interval2= 1400000000;
if (curEspMillis - prevEspMillis >= interval2) {
sendData("AT+RST\r\n",2000,DEBUG); // reset module
sendData("AT+CWMODE=1\r\n",1000,DEBUG); // configure as access point
sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
sendData("AT+CWJAP=\"Rafina\",\"4112703241\"\r\n",5000,DEBUG);
sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
}
Is there a better way?
Regards
Panseptos