Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By thewiep
#15618
chriscook8 wrote:https://github.com/chriscook8/esp-arduino-apboot

This reads from eeprom to get SSID and password information.s


Thanks a lot for this nice example!!
It has a lot of things in it I can use.

Like another user in another thread I also noticed that it stores the url encoded version of the ssid and pass.

Someone was kind enough to post code to complete this task:
https://gist.github.com/jmsaavedra/7964251

I slightly modified it so we also get the size of the url decoded version as this will likely be smaller
Code: Select allint urldecode(char *dst, const char *src)
{
  char a, b;
  int new_size = 0;
  while (*src) {
    if ((*src == '%') &&
      ((a = src[1]) && (b = src[2])) &&
      (isxdigit(a) && isxdigit(b))) {
      if (a >= 'a')
        a -= 'a'-'A';
      if (a >= 'A')
        a -= ('A' - 10);
      else
        a -= '0';
      if (b >= 'a')
        b -= 'a'-'A';
      if (b >= 'A')
        b -= ('A' - 10);
      else
        b -= '0';
      *dst++ = 16*a+b;
      src+=3;
    }
    else {
      *dst++ = *src++;
    }
    new_size += 1;
  }
  *dst++ = '\0';
  return new_size;
}


For the password I then used following code

Code: Select all        int buffer_size = q_pass.length() + 1;
        char pass_encoded[buffer_size];
        char pass_decoded[buffer_size];

        qpass.toCharArray(pass_encoded,buffer_size);
        int decoded_size = urldecode(pass_decoded,pass_encoded);

        Serial.println("writing eeprom pass:");
        for (int i = 0; i < decoded_size; ++i)
        {
          EEPROM.write(32+i, pass_decoded[i]);
          Serial.print("Wrote: ");
          Serial.println(pass_decoded[i]);
        }


this can probably be improved but I needed something quick :)
User avatar
By ian
#18609 This had me scratching my head for a while too :)
My approach was to check if the IP address was non-zero & then execute a 'return'
ie if the IP address is not zero we must have a new one so the job is done.
This will throw you out of setup() and into loop()

if (WiFi.localIP() !=0) return;

I put this in the while loop at the end of launchWeb()

Hope this helps