0

When I flash my code:

/* Create a WiFi access point and provide a web server on it. 

 Author: Lucio A. Rocha
 Last Update: 21 Aug 2016

*/

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

/* Set these to your desired credentials. */
const char *ssid = "MaisonBlanche";
const char *password = "7932gLBw";

ESP8266WebServer server(80);

const int led = 2;  //GPIO2

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\    
    <title>MicroCloud</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>You are connected on MicroCloud #2!</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\    
    <p>Status: Light ON</h1></p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/off\"><h1>Turn OFF</h1></a></p>\           
  </body>\
</html>",

    hr, min % 60, sec % 60
  );
  server.send ( 200, "text/html", temp );  

}

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");

  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);

  pinMode(led, OUTPUT);
  digitalWrite ( led, HIGH );

  //URLs available to query
  server.on("/", handleRoot);
  server.on ( "/on", turnON );    
  server.on ( "/off", turnOFF );
  server.begin();
  Serial.println("HTTP server started");

}

void turnON(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\    
    <title>MicroCloud</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: Light ON</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p></p>\
    <p>Status: Light ON</h1></p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/off\"><h1>Turn OFF</h1></a></p>\       
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);

}

void turnOFF(){

  digitalWrite ( led, LOW );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\    
    <title>MicroCloud</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: Light OFF</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p>Status: Light OFF</p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/off\"><h1>Turn OFF</h1></a></p>\       
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);

}

void loop() {
  server.handleClient();
}

onto the ESP8266 with this setup:

enter image description here

For my serial output I get:

en 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld

I got it to work semi successfully before now. I was basically following along with https://create.arduino.cc/projecthub/luciorocha/esp8266-control-led-with-smartphone-8a59f3. I got to the point where the code was being run successfully - but then something unexpected happened, when I thought the LED would go on, when I selected the turn on button, nothing happened. When I selected turn off, the blue LED on the board turned on and stayed steady. Then, when I selected turn on again, the LED on board went off. I thought the sketch was supposed to manipulate pin 2, but it seemed to be manipulating the onboard LED instead, and in the reverse way that it should.

Now, I can upload it, but the only thing it does after that is spit out the above serial output. I have tried running it with:

GND -> GND
VCC -> 3.3v
CH_PD -> 3.3v

Other sketches seem to work, so maybe something I did triggered an ESP8266 setting which now conflicts with something in the code?

UPDATE

I double checked that other sketches are running - also running is a sketch that connects the ESP8266 to my network - it connects and gets assigned an IP. I made this simplified sketch of the one above, involving the connection process:

/* Create a WiFi access point and provide a web server on it. 

 Author: Lucio A. Rocha
 Last Update: 21 Aug 2016

*/

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");

  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP("MaisonBlanche", "7932gLBw");

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
}

void loop() {

}

The only thing it outputs (no connection) to serial is:

0, len 1384, room 16 
tail 8
chksum 0x2d
csumcL⸮
~ld

So it seems as if the problem is with my code, or it is able to connect to a network as a client but not as a softAP?

UPDATE

I ran this code:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);

void setup()
{
  Serial.begin(115200);
  Serial.println();

  Serial.print("Setting soft-AP ... ");
  boolean result = WiFi.softAP("MaisonBlanche", "7932gLBw");
  if(result == true)
  {
    Serial.println("Ready");
  }
  else
  {
    Serial.println("Failed!");
  }
}

void loop()
{
  Serial.printf("Stations connected = %d\n", WiFi.softAPgetStationNum());
  delay(3000);
}

The same garbled serial output appears, and then it started outputting:

Stations connected = 0

Then the output changed to:

Stations connected = 1

Does this just mean it is successfully connecting using softAP?

UPDATE

I think I have narrowed it down what is not working to the ESP8266WebServer. I used this code:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);

void setup()
{
  Serial.begin(115200);
  Serial.println();

  Serial.print("Setting soft-AP ... ");
  boolean result = WiFi.softAP("MaisonBlanche", "7932gLBw");
  if(result == true)
  {
    Serial.println("Ready");
  }
  else
  {
    Serial.println("Failed!");
  }

  server.on("/", handleRoot);
  server.begin();
}

void handleRoot() {

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

    "<html>\
      <head>\    
        <title>BEASTMODE</title>\
        <style>\
          body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
        </style>\
      </head>\
      <body>\
        <h3>You are connected on BEASTMODE!</h3>\    
      </body>\
    </html>",

    hr, min % 60, sec % 60
  );
  server.send ( 200, "text/html", temp );  
}

void loop()
{
  Serial.printf("Stations connected = %d\n", WiFi.softAPgetStationNum());
  //delay(3000);
  Serial.print("Soft-AP IP address = ");
  Serial.println(WiFi.softAPIP());
  server.handleClient();
}

When the loop starts it begins to output:

Soft-AP IP address = 192.168.4.1
Stations connected = 0 

It seems to go between 0 stations connected and 1 station connected. I go to 192.168.1.4 in my browser, and it never loads the page, it just times out. So if it has a softAP IP address - but it is not accessible, then maybe the server isn't working for some reason. Also I read how you can put the chip into different modes (STA/AP/etc

0

This works fine, doesn't use ESP8266WebServer which seems to be the culprit. It is the web server from ESP8266WiFi. At the bottom there is a link to a blinking LED example which works for me. You just type in <ip>/gpio/0 in browser for off, and change it to /gpio/1 for on.

  • Accept your own answer to close this question. – user31481 Nov 22 '17 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.