Can I Call Wifi.begin() before setup() function?
Because when I do I get :
error: 'WiFi' does not name a type
Explore... Chat... Share...
Moderator: igrr
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "........";
const char* password = "........";
WiFi.begin(ssid, password);
ESP8266WebServer server(80);
const int led = 13;
void handleRoot() {
digitalWrite(led, 1);
server.send(200, "text/plain", "hello from esp8266!");
digitalWrite(led, 0);
}
void handleNotFound(){
digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}
void setup(void){
pinMode(led, OUTPUT);
digitalWrite(led, 0);
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());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/inline", [](){
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
Were you able to write binary data to file with SP[…]
Hello . Good afternoon. I would like to ask for he[…]
Hello, My in-laws are Mexican and live in Mexico […]
Hi Buddies, Did you encounter the issue of efuse […]
See if this fits your needs: https://www.instruct[…]
I was hoping this project looks good before I move[…]
I think it would be easier to use a Pi with a buil[…]
It's generally considered more practical and effic[…]
Wouldn't it be easier to setup your ESP in station[…]
+1 from me, thank you for sharing. Just to clarif[…]
I am currently trying to determine how the ESP8266[…]
Follow US on Twitter and get ESP8266 news and updates first.