Node MCU Wifi Reconnect
Posted: Sun May 21, 2017 10:51 am
Hi,
I use a Node to control my 433mhz sockets, which are placed in my garden, with a small webpage.
I use a PowerLine-adaptor to bring Wifi to my garden.
Now I put my Node in the summerhouse next to the adaptor.
If I plug the Node in, I can access for about 60sec to the webpage, then I canĀ“t.
I think that the problem is that the Powerline-adaptor loses every ~60sec for about 1sec the connection to the other adaptor at my router.
How can I reconnect the Node to the Wifi-Network?
Philipp
Here is my code:
I use a Node to control my 433mhz sockets, which are placed in my garden, with a small webpage.
I use a PowerLine-adaptor to bring Wifi to my garden.
Now I put my Node in the summerhouse next to the adaptor.
If I plug the Node in, I can access for about 60sec to the webpage, then I canĀ“t.
I think that the problem is that the Powerline-adaptor loses every ~60sec for about 1sec the connection to the other adaptor at my router.
How can I reconnect the Node to the Wifi-Network?
Philipp
Here is my code:
Code: Select all
#include <ESP8266WiFi.h>
const char* ssid = "WLAN7618";
const char* password = "xxxxxxxxxx";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(115200);
delay(1);
mySwitch.enableTransmit(2);
mySwitch.setPulseLength(180);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
y\">Reiherschreck Off</a></li></ul><p></body>";
s += "</html>\n";
// Send the response to the client
client.print(s);
delay(1);
Serial.println("Client disconnected");
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}