LUA to C (Newbie question of the day)

Trying to see if I can set the SSID, password, and other parameters on an ESP8266 during run-time. I have a PLDuino with the embedded ESP8266 (communicates via the PLDuino Serial2 connection).

If I use ESPlorer (and the "helper sketch" from PLDuino), I can make the SSID (and other) changes by typing the following into ESPlorer:

cfg={} cfg.ssid="newSSID" cfg.pwd="newPASSWORD" cfg.auth=3 cfg.hidden=0 cfg.max=4 cfg.beacon=100 wifi.ap.config(cfg)

So, I'm thinking that if I just "Serial2.println" my wifi.ap.config(cfg) command to the ESP8266, mission accomplished.

In ESPlorer (i.e. LUA), "cfg" is called a table. How can I code the same thing in a sketch?

I've tried different things, but none seem to work. For instance, I created 8 different "cfg_xxx" variables (ex. cfg_ssid) and passed those to the wifi command like: wifi.ap.config(cfg_ssid,cfg_pwd, ... cfg_save). But wifi.ap.config just throws back an error saying it expected a table and got a string.

If I'm approaching this in the wrong way, let me know. I just really don't want to go through the hassle of reflashing the ESP8266 because I plan on building several of these with different SSIDs, and I'm not sure I could anyway since the ESP8266 is integrated on the main board.

Thanks for your help, R

Well - partially answered my own question: The following command seems to work except that the "save" parameter doesn't survive a power cycle.


Followup to my previous post…

In return for all the help I found on this forum and the ESP8266 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).


//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);
      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...");
  LOG(F("Sending AP configuration: "));