Post topics, source code that relate to the Arduino Platform

User avatar
By PerlUser12
#77437 I have been attempting connect my Wemos D1 up to wifi, which it has successfully done before but it is failing to connect now. The code is successfully compiling yet fails when it try's to connect I have a suspicion that the wifi mode is effecting but changing it to AP and even STA does not yield any results.

code:
//insert of module's
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

MDNSResponder mdns;

// input of credentials
const char* ssid = "********";
const char* password = "*******";
ESP8266WebServer server(80);

String webPage = "";
String x = "";

//setting of GPIO pins
int gpio4_pin = 12;//P4
int gpio2_pin = 4;//P3

IPAddress ip(192, 168, 2, 67); //
IPAddress gateway(192, 168, 2, 1);

IPAddress subnet(255, 255, 255, 0);

//creation of webserver
void setup(void) {
webPage += "<h1>WIFI Irrigation system Web Server</h1><p>Socket #1 <a href=\"socket1On\"><button>ON</button></a>&nbsp;<a href=\"socket1Off\"><button>OFF</button></a></p>";

// preparing GPIOs
pinMode(gpio4_pin, OUTPUT);
digitalWrite(gpio4_pin, LOW);
pinMode(gpio2_pin, OUTPUT);
digitalWrite(gpio2_pin, LOW);

//setting static ip
Serial.begin(115200);
Serial.println("Setting static ip to : ");
Serial.println(ip);
Serial.println("Connecting to the Internet...");
WiFi.config(ip, gateway, subnet);


WiFi.mode(WIFI_STA); //STA - AP

int qwe = 0;
delay(1000);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");

}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

//begining of server
if (mdns.begin("esp8266", ip)) {
Serial.println("MDNS responder started");
}
digitalWrite(gpio2_pin, LOW);
digitalWrite(gpio4_pin, LOW);
server.on("/", []() {
server.send(200, "text/html", webPage);
});

//Valve loop here is where I am getting most of my errors
server.on("/socket1On", []() {
server.send(200, "text/html", webPage);
int y = 0;
int op = 25;
//String x = server.arg("plain");
//Serial.println(x);
while (y<250){
server.send(200, "text/html", webPage);
delay(1000);
String x = server.arg("plain");
delay(1000);
Serial.println(x);
digitalWrite(gpio4_pin, HIGH);
digitalWrite(gpio2_pin, LOW);
delay(1000);
digitalWrite(gpio2_pin, HIGH);
digitalWrite(gpio4_pin, LOW);
delay(1000);
digitalWrite(gpio4_pin, LOW);
digitalWrite(gpio2_pin, LOW);
delay(1000);
y++;
delay(1000);
Serial.println(y);
if(x = "q")
y + op;
else;
}
});




//End of valve loop

server.begin();
Serial.println("HTTP server started");

}

void loop(void) {
server.handleClient();
}
User avatar
By PerlUser12
#77553
schufti wrote:this could be e.g. due to following reasons:

a) old/incompatible wifi calibration parameters in flash
b) you experimented with deepsleep and wake_rf_off option

--> use "Erase Flash - All Flash Content" from Tools menu


Seeing as I haven't used any deep-sleep or wake_rf_off options I assume from your suggestion it is probably due to an old incompatible WiFi calibration but I cannot seem to find the Erase flash option you suggested.