-->
Page 2 of 19

Re: Storing and reading ssid/pass from eeprom, AP to config

PostPosted: Sat Apr 25, 2015 12:16 pm
by thewiep
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 :)

Re: Storing and reading ssid/pass from eeprom, AP to config

PostPosted: Sun Apr 26, 2015 11:09 am
by kanin03
Wow! this idea is awesome thanks, chriscook8 and thewiep :D

I've modified this too to handle a RESTfull url easily by using ESP8266WEBSERVER.h
but now it error I don't know what I'm do wrong

can you please help me fix this?
viewtopic.php?f=29&t=2710
Thanks.

Re: Storing and reading ssid/pass from eeprom, AP to config

PostPosted: Wed May 27, 2015 9:12 am
by Sirionnetworks
Hi supercool, i would like to combine this with mqtt , but the main loop is never executed ? so how can i listen for mqtt pubsubclient messages ?

Re: Storing and reading ssid/pass from eeprom, AP to config

PostPosted: Wed May 27, 2015 10:48 am
by ian
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