Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By LEDAero
#20769
thewiep wrote:
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 :)


Being a dunce, I have no idea what 'url encoded' means - why would we want this?
User avatar
By cal
#20774
alextu wrote:
cal wrote:Moin,

what is the eeprom? Where is it located? What is it normally being used for on the esp?

Cal


hi, thee eeprom is a nonvolatile memory where you can save and read stuff between restarts. in the case of the esp it s written on the flash chip, same as everything else

Thanks for that answer!
But that means if people take it for a real eeprom they may be suprised if their flash wears out.

Cal
User avatar
By tytower
#20776 EEPROM is Electrically eraseable programable read only memory as far as I know and EEPROM is the FLASH isn't it.

https://en.wikipedia.org/wiki/EEPROM

EEPROM (also written E2PROM and pronounced "e-e-prom", "double-e prom", "e-squared", or simply "e-prom") stands for Electrically Erasable Programmable Read-Only Memory and is a type of non-volatile memory used in computers and other electronic devices to store small amounts of data that must be saved when power is removed, e.g., calibration tables or device configuration.

Unlike bytes in most other kinds of non-volatile memory, individual bytes in a traditional EEPROM can be independently read, erased, and re-written.

When larger amounts of static data are to be stored (such as in USB flash drives) a specific type of EEPROM such as flash memory is more economical than traditional EEPROM devices. EEPROMs are organized as arrays of floating-gate transistors.