ESP32 as an Access Point with the ability to store WiFi credentials (and other configurational data)

andrew_p
Posts: 30
Joined: Sun Jan 01, 2017 5:37 pm

ESP32 as an Access Point with the ability to store WiFi credentials (and other configurational data)

Postby andrew_p » Tue Jan 10, 2017 1:17 am

ESP32 provides a great API for managing WiFi connections and I'm looking for code example/snippets, which would allow to accomplish the following:

1. When ESP32 starts if verifies if there is any configurational data stored.
2. If there is NO configurational data, then it runs in a WiFi Access Point mode and serves HTML page, where a user can specify WiFi credentials and other configurational data in key-value pairs format (NVS?)
3. if there IS configurational data stored, then ESP32 runs in a standard WiFi mode (as a station) and performs common tasks using stored configurational data.

Do you guys have / know any code examples which can help? I did try access point example (thanks Neil!), it works fine, just need a bit more (how to serve HTML page and store data?).

Essentially I want to have something what ESP32-Duktape provides at the very first setup step (again, Neil!), but I want to have my custom HTML page with a custom configurational data, so ESP32 can use that data for common tasks (let's say I want to specify # of LEDs to blink or URL to perform HTTP request etc.)

- Andrew

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP32 as an Access Point with the ability to store WiFi credentials (and other configurational data)

Postby kolban » Tue Jan 10, 2017 1:36 am

Howdy Andrew,
Might this be a partial starting point?

https://github.com/nkolban/esp32-snippe ... g/bootwifi

It feels like the core bit you need might be an HTTP server. In C, my goto on that is the Mongoose project.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

MitchSF
Posts: 11
Joined: Sat Jun 17, 2017 11:30 am

Re: ESP32 as an Access Point with the ability to store WiFi credentials (and other configurational data)

Postby MitchSF » Sat Jun 17, 2017 11:45 am

I would LOVE to have a library that does this! I'm working on two projects that require configuration data to be saved, in addition to ssid and password. A bonus would be the ability to specify field types such as text, numeric, drop down box, radio button, and data validation with error messages. Maybe that's asking too much, but with the ESP32, MKR1000 and many other Internet connected products, I'm surprised that nothing like this exists yet. For sure, I can't do it myself.

Alterane
Posts: 3
Joined: Thu Jun 01, 2017 5:47 pm

Re: ESP32 as an Access Point with the ability to store WiFi credentials (and other configurational data)

Postby Alterane » Tue Jul 04, 2017 2:29 pm

Hi, i have manage to make a http server who do some part of what you want.

Now, the esp start with an AP not hidden with an SSID DEFAULT, and a server http with dhcp on 192.168.1.1.
The http server avec an page with a form, asking for ssid name for the next AP, ssid name for the STA to connect and password.
I receive an process the POST request store value on nvs, BUT..
The AP start well with the same code.
I cannot manage to start STA with (char *) i don't know why...
I use:

Code: Select all

strcpy ((char *)wifi.sta.ssid, "SSID");
work but when a use :

Code: Select all

//myvar is a string fresh malloc and extract from nvs
strcpy ((char *)wifi.sta.ssid, myvar);
That didn't work :'(...
I have check the string is perfect, right length and right data.
Can we start a wifi sta with mallocated ssid extract from nvs ?

preetam
Posts: 49
Joined: Thu Jan 26, 2017 2:31 pm
Location: Germany

Re: ESP32 as an Access Point with the ability to store WiFi credentials (and other configurational data)

Postby preetam » Wed Jul 05, 2017 10:37 am

Hi Andrew,

I assume you are storing in nvs using nvs_set_str (as a string) , in that please check whether the string is zero terminated.

Thank you
Paul

Alterane
Posts: 3
Joined: Thu Jun 01, 2017 5:47 pm

Re: ESP32 as an Access Point with the ability to store WiFi credentials (and other configurational data)

Postby Alterane » Wed Jul 05, 2017 5:59 pm

Thank you, but it worst than that...

I forgot the esp_wifi_connect().

Shame on me :/

But for sure if the string is store on a (const char *) in the code you don't need to use esp_wifi_connect(), after esp_wifi_start() the program connects itself ...

Weird..?!

Who is online

Users browsing this forum: Bing [Bot] and 89 guests