So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By ron57108
#68967 Followup to my previous post (which hasn't been approved yet)...

In return for all the help I found on this forum and the Arduino forum, I just wanted to stop back by here to post what I've learned about interacting with the ESP8266 embedded on the PLDuino. Surely there are other ways, but after literally days of testing those other ways, this is the best I could come up with:

The attached .INO is my resulting sketch for changing the SSID and other parameters at runtime. It is a derivative of the "Helper Sketch" published by the folks that make the PLDuino. There seem to be a few "undocumented" items in the sketch, but they also appear to be very necessary. Also, if you try to watch the serial communication real-time, there seems to be a timing problem. Thus, serial monitor may not necessarily represent what is actually happening on the ESP8266 - watch your WiFi signal instead.

Lastly, to use the sketch, simply call "cancelWiFiTestStartup()" from your other sketch file(s).

Enjoy,
R

Code: Select all//Found this in the PLDuino firmware examples files


bool waitUntilStringReceived (String ptn, int timeout)
{
  String response = "";
  long start_time = millis();
  while(millis() - start_time < timeout)
  {
    if (Serial2.available())
    {
      response += (char)Serial2.read();
      if (response.length() >= ptn.length())
      {
        response = response.substring(response.length() - ptn.length());
        if (response == ptn) return true;
      }
    }
  }
  return false;
}
 

void cancelWiFiTestStartup()
{
  LOGLN(F("Waiting for initial startup string from ESP8266"));
  if (waitUntilStringReceived("type \"qw\"", 10000))
  {
    LOGLN(F("ESP8266 startup string received"));
    LOGLN("sending qw...");
    Serial2.println("qwqwqw;\n");
    Serial.flush();
  }
  Serial2.flush();
  delay(5000);
  LOG(F("Sending AP configuration: "));
  LOGLN(F("=wifi.ap.config({ssid=\"newSSID\",pwd=\"newPassword\",auth=3,channel=3,hidden=0,max=4,beacon=100,save=true})"));
  Serial2.println("=wifi.ap.config({ssid=\"newSSID\",pwd=\"newPassword\",auth=3,channel=3,hidden=0,max=4,beacon=100,save=true})");

}