Looking for sample code to set the WiFi on web UI (ESP32)

If you are asking a question, please follow this template:

  1. My goal is: Developing the firmware of ESP32
  2. My actions are: I did install mongoose os first.
  3. The result I see is: none
  4. My expectation & question is: [describe your expectation and your question]

    I’m using ESP32-WROOM-32D.
    First, I’m trying to set the WiFi(First Step) on the web ui.
    I found the sample code in the github but could not build.
    So I’m looking for the sample code that can set WiFi on the web ui.
    If turn on the device,

    1. user must able to connect to ESP32 and set the WiFi using web ui.(AP mode)
    2. and also want that user can select ssid.
    3. and then, after saving, automatically connecting to the WiFi.(STA mode)
    4. AND when user want to change WiFi Setting,
      a) user press the button
      b) if then, user must able to set the WiFi again.
      Please let me know the sample code.
      following is the picture to work.

check out the tripflex captive portal library

1 Like

Thank you. I will try

Another option might be https://github.com/d4rkmen/wifi-setup

Don’t be sorry for being a beginner, just read the docs until you become a master.
When you say “connect”… D’you mean you need the Wi-Fi Access Point password ? It is what you set, and if you don’t set, it is the default, docs here
Libraries do have docs too, d’you mean this library ?
‘Mongoose’ with capital ‘M’, as you see in the SSID (the “name” of the network you are connecting to)

Hmm… It was “Mongoose” ^^ thank you~~

When I looked through the log, I found the following message. This is probably the function I need. Is there a sample of how to use it?

[Feb 21 15:24:31.993] mgos_provision_state:54 Provisioning timeout, resetting device
[Feb 21 15:24:31.993] mgos_provision_btn.c:29 Resetting to factory defaults
[Feb 21 15:24:31.993] mgos_sys_config.c:353 Removed conf9.json
[Feb 21 15:24:32.569] mgos_system.c:58 Rebooting in 100 ms

Without timeout, when I press GPIO button, I want to make factory default.

These messages come from the provision library.

now I’m using yellow pin for reset button. so, how do I change the configration sample?
once I set “14” like following, but not working.

- ["provision", "o", {title: "Provision library settings"}]
- ["provision.btn", "o", {title: "Reset button settings"}]
- ["provision.btn.pin", "i", 14, {title: "Reset button GPIO pin"}]
- ["provision.btn.pull_up", "b", false, {title: "True if button is pulled up when inactive"}]
- ["provision.btn.hold_ms", "i", 0, {title: "Hold interval in milliseconds. -1 to disable, 0 to reset if held on boot, > 0 to reset if held at runtime for this long."}]
- ["provision.btn.inhibit_after_s", "i", 0, {title: "Disable reset button once uptime reaches this value in seconds. 0 to keep reset button always enabled."}]
- ["provision.led.pin", "i", -1, {title: "LED GPIO pin. If >= 0, LED blinking will indicate current state."}]
- ["provision.led.active_high", "b", true, {title: "True if LED is on when output is high (1)"}]
- ["provision.stable_state", "i", 3, {title: "A stable state, beyond which reset will not happen. Se to 0 to disable reset."}]
- ["provision.timeout", "i", -1, {title: "Maximum time since boot allowed to reach stable state"}]
- ["provision.max_state", "i", 0, {title: "Maximum state reached so far"}]

How is your button connected to the ESP32? What type of button are you using (normal open, normal close)?

You don’t need to copy all the configuration settings in your mos.yml. You have to specify only the values that are overidding the default ones, e.g.

- ["provision.btn.pin", 14]

PS. I don’t use the provision library, so you might need to read the source code in order to understand how it works.

PPS. The readme of the library explains pretty well how it works.