Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Larsen
#67715 Hi,
I have been playing with a Witty Cloud / ESP8266-12 board, and after a certain point where I have added the code:

Code: Select allESP.eraseConfig();

Now I am not able to connect to a network any longer - not even with code which normally works perfect (I have removed the ESP.eraseConfig(); again).

If I use a "fresh" Witty Cloud board, and upload code to it, it works fine and connects to the network, but the board which had undergone the ESP.eraseConfig(); treatment, will not connect with the exact same code.

OK, I thought I could dump all memory from the fresh Witty Cloud board, and upload it to the faulty one. To do this, I have tried the esptool.py, with the read_flash and after that, the write_flash options. I have dumped all 5 areas, as specified here: http://www.electrodragon.com/w/Category:ESP8266_Code_Guide#Firmware_Details. But the faulty board will still not connect.

Can anyone maybe give me a hint to what I could have erased/cleared on the ESP8266 so it refuses to connect to a network?

Regards.
User avatar
By QuickFix
#67722 You can erase your entire flash by issuing:
  • Windows ESPTool.exe: esptool -cp COM6 -ce
    or
  • Python ESPTool.py: python esptool.py -p com6 erase_flash
Of course change "COM6" to reflect your com-port settings.

Of course, since your entire flash memory will be erased, you also lose your program and will have to re-upload a sketch again. ;)
User avatar
By Larsen
#67749
philbowles wrote:I'm confused. Did you attempt to move the code from a "good" board to a "bad" board with the tool? Then where is the erasconfig you are talking about?


OK. I thought a short version of my problem was enough, but here goes the longer more detailed version :)

My idea was to make a wireless link between two ESP8266 modules; one module working in AP mode, and the other in STA mode. I am using the Witty Cloud board for this setup (one board in STA mode and another board in AP mode).

My problem was, that the module in STA mode could not connect to the module in AP mode. I read a lot of forum posts about other people having trouble with the exact same, and some suggested that using the <i>ESP.eraseConfig();</i> in the setup function (I am using the Arduino IDE for development and compilation of the code), could solve the problem.

The code which I then used on the module which should run as AP is:
Code: Select all// *************************************************
//                    Prototypes
// *************************************************
void myDelay(int ms);
void blinkLED(int iopin, int msbetweentoggle, int numberofblink, boolean activeHigh);

// *************************************************
//                 Include headers
// *************************************************
#include <WiFiClient.h>
#include <ESP8266mDNS.h>
#include <ESP8266WiFi.h>

extern "C" {
#include "user_interface.h"
}

// *************************************************
//            Definitions
// *************************************************
#define VERSION "1.0"
#define DEVICEID 2

// *************************************************
//            Constant definitions
// *************************************************
const int ledPin       = 2;   // GPIO 2
const int greenLedPin  = 12;  // GPIO 12
const int blueLedPin   = 13;  // GPIO 13
const int redLedPin    = 15;  // GPIO 13


const char* ssid = "abc";
const char* password = "abcabcabc";

long lastTime=0;
long currentTime;
long interval;

IPAddress myIP(192,168,4,1);
IPAddress gateway(255, 255, 255, 0);

MDNSResponder mdns; //stoney
WiFiServer server(80);

void setup()
{
  ESP.eraseConfig();
  wifi_set_phy_mode(PHY_MODE_11G);
 
  pinMode(greenLedPin, OUTPUT);
  digitalWrite(greenLedPin, LOW);    // Active HIGH
  pinMode(blueLedPin, OUTPUT);
  digitalWrite(blueLedPin, LOW);    // Active HIGH
  pinMode(redLedPin, OUTPUT);
  digitalWrite(redLedPin, LOW);     // Active HIGH
 
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);       // Active LOW
 
  WiFi.disconnect();
  delay(1000);
  Serial.begin(115200);

  Serial.println();
  Serial.print("Configuring access point...");

  WiFi.disconnect(true);
  wifi_station_disconnect();

  WiFi.mode(WIFI_AP);

  WiFi.softAPConfig(myIP, myIP, gateway);
  WiFi.softAP(ssid, password);

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

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

  blinkLED(greenLedPin, 100, 5, true);

  interval = 5000;

  WiFi.printDiag(Serial);
}

void loop()
{
  mdns.update(); // Check for any mDNS queries and send responses

  currentTime = millis();
 
  if (currentTime - lastTime > interval)
  {
    myDelay(100);   // make a 100msec delay to make the ESP8266 Watchdog happy
    lastTime = currentTime;
  }
 
  WiFiClient client = server.available(); // Check if a client has connected
  if (!client)
  {
 //   delay(100);
    return;
  }

  blinkLED(blueLedPin, 100, 5, true);
 
  Serial.println("");
  Serial.println("New client");

  // Wait for data from client to become available
  while (client.connected() && !client.available())
  {
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
  client.stop();
}


void myDelay(int ms)
{
  int i;
  for(i=1;i!=ms;i++)
  {
    delay(1);
    if(i%100 == 0)
    {
      ESP.wdtFeed();
      yield();
    }
  }
}


void blinkLED(int iopin, int msbetweentoggle, int numberofblink, boolean activeHigh)
{

  for (int i=0; i<numberofblink; i++)
  {
    digitalWrite(iopin, activeHigh);
    delay(msbetweentoggle);
    digitalWrite(iopin, !activeHigh);

    if (numberofblink > 1)
    {
      delay(msbetweentoggle);
    }
  }
}


The code did not work, and I was not able to get the link working.

After that, I tried to compile and run an old web server program. But now the ESP8266-module will not connect to my router.

The old web server code is:
Code: Select all#include <ESP8266WiFi.h>

const char* ssid = "SSID";
const char* password = "PASSWORD";

const int ledPin = 2;     // GPIO2

WiFiServer server(80);

void setup()
{
  Serial.begin(9600);
  delay(10);

  WiFi.softAPdisconnect(true);       // Be sure that the ESP8266 is in standard mode (NOT AP mode)
  WiFi.mode(WIFI_STA);              // WIFI_AP    WIFI_AP_STA  WIFI_STA
 
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);         // Active LOW
   
  // Connect to WiFi network
  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.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

}

void loop()
{
     
  // Check if a client has connected
  WiFiClient client = server.available();

 
  if (!client)
  {
    return;
  }

  // Toggle LED to show a client has connected
  for (int i=0; i<40; i++)
  {
    digitalWrite(ledPin, LOW);         // Active LOW
    delay(100 - i*2);
    digitalWrite(ledPin, HIGH);
    delay(100 - i*2);
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(client.connected() && !client.available())
  {
    delay(1);
  }
 

  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\n";
  s += "<table width='350px'><tr><td>";
  s += "<center><p style='font-family:verdana'>Hello World</p></center>\n";
  s += "<br><br>\n";
  s += "</td></tr></table>\n";
 
  s += "</html>\n";

  // Send the response to the client
  client.print(s);
 
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

  client.stop();
}


I then found a new ESP8266-module, and uploaded the web server code, as shown above, to it, and it works perfect. So my conclusion is: The module which I ran as AP has been "changed" in a way that I will not work as it did before. And my conclusion was that it was due to the <i>ESP.eraseConfig();</i>. That is, that some usefull configuration data has been erased.

Now to the second part of this.

I thought, I could just make a memory dump of the new ESP8266-module, and upload it to the module which has run as AP. For this purpose I used the <i>esptool.py</i> and used the <i>read_flash</i> option to dump all 5 memory areas as specified here: http://www.electrodragon.com/w/Category:ESP8266_Code_Guide#Firmware_Details. After that, I used the <i>write_flash</i> option to save the dumped data back to the module which has run as AP.

It did not solve my problem.

The module which has run as AP will still not connect to my network with the web server code.

So, my initial question was: Is there something I have forgotten in this process? Will <i>ESP.eraseConfig();</i> erase more info than just the saved SSID and PASSWORD on the ESP8266-module?

I am using Arduino IDE version 1.8.3