Hello.
I tried to use wemos d1 r2 and uploaded WiFiWebBrowser example. But the ssid does not appear on my laptop and when i run serial monitor on my arduino IDE, it just give me infinity point. So what should i do?
#include <ESP8266WiFi.h>
const char* ssid = "your-ssid";
const char* password = "your-password";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
// prepare GPIO2
pinMode(2, OUTPUT);
digitalWrite(2, 0);
// 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();
// Match the request
int val;
if (req.indexOf("/gpio/0") != -1)
val = 0;
else if (req.indexOf("/gpio/1") != -1)
val = 1;
else {
Serial.println("invalid request");
client.stop();
return;
}
// Set GPIO2 according to the request
digitalWrite(2, val);
client.flush();
// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val)?"high":"low";
s += "</html>\n";
// Send the response to the client
client.print(s);
delay(1);
Serial.println("Client disonnected");
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}
in this case i used WeMos D1 R2 esp2866.
Wifi ssid didn't appear, once it appear but can't be connected and serial monitor can't show the ip address or it can't be connected.
This seems very similar to your other thread:
http://forum.arduino.cc/index.php?topic=481493
ZaqyW:
WiF iSe rve r server(80 ); //Initialize the server on Port 80
void setup() {
WiFi.mode(WI FI _ AP); //Our ESP8266-12E is an AccessPoint
WiFi.softAP("Hell o_ IoT ", "12345678 "); // Provide the (SSID, password); .
server.be gi n (); // Start the HTTP Server
Why do you have all these extra spaces in the code?
Use code tags (</> button on the toolbar) when you post code or error messages, not quote tags.
i'm sorry for my bad.
#include <ESP8266WiFi.h>
WiFiServer server(80 ); //Initialize the server on Port 80
void setup() {
WiFi.mode(WIFI_AP); //Our ESP8266-12E is an AccessPoint
WiFi.softAP("Hello_IoT ", "aaaaaaaa"); // Provide the (SSID, password); .
server.begin (); // Start the HTTP Server
Serial.begin(115200);
IPAddress HTTPS_ServerIP = WiFi.softAPIP();
Serial.print("Server IP is: ");
Serial.println(HTTPS_ServerIP);
}
void loop(){}
Threads merged.
thank you