[GH-ISSUE #1211] How to set SSID and Password programmatically ? #1030

Closed
opened 2026-02-28 01:28:12 +03:00 by kerem · 5 comments
Owner

Originally created by @sn00zerman on GitHub (Feb 10, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1211

Hardware

WiFimanager Branch/Release: Development
Esp32:
Hardware: Lilygo TTGO T8
Core Version: 2.4.0, staging

Description:

I'm looking for a way to "pre-fill" the SSID and Password field,
when the captive portal shows up.
(Like one would do when presenting extra parameters, you also have a way to fill it in from the software-side ...)

Additional libraries:

#include "WiFi.h"
#include "HTTPClient.h"
#include "WiFiManager.h"
#include "WiFiClient.h"
#include "WebServer.h"
#include "ESPmDNS.h"
#include "Update.h"

Originally created by @sn00zerman on GitHub (Feb 10, 2021). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1211 #### Hardware WiFimanager Branch/Release: Development Esp32: Hardware: Lilygo TTGO T8 Core Version: 2.4.0, staging ### Description: I'm looking for a way to "pre-fill" the SSID and Password field, when the captive portal shows up. (Like one would do when presenting extra parameters, you also have a way to fill it in from the software-side ...) ### Additional libraries: #include "WiFi.h" #include "HTTPClient.h" #include "WiFiManager.h" #include "WiFiClient.h" #include "WebServer.h" #include "ESPmDNS.h" #include "Update.h"
kerem 2026-02-28 01:28:12 +03:00
  • closed this issue
  • added the
    Question
    label
Author
Owner

@sn00zerman commented on GitHub (Feb 12, 2021):

I managed to solve my own problem :-) (after a good night-sleep, I could think more clear again)

  • I added 2 parameters, of type "hidden": hidden_s and hidden_p (hidden_s contains programmatically SSID, and hidden_p the password)

  • I added a function in the HTTP_SCRIPT[] in strings_en.h, just before the tag:
    "function myHidden()\n"
    "{\n"
    " var txt_s = document.getElementById('s');\n"
    " var txt_hidden_s = document.getElementById('hidden_s');\n"
    " var txt_p = document.getElementById('p');\n"
    " var txt_hidden_p = document.getElementById('hidden_p');\n"
    " txt_s.value = txt_hidden_s.value;\n"
    " txt_p.value = txt_hidden_p.value;\n"
    "}\n"

    • in the HTTP_HEAD_END[], I added onload='myHidden()' , right after the <body

    Everytime, the page loads, it passes the data from the hidden field, into the s and p field :-)

<!-- gh-comment-id:778058939 --> @sn00zerman commented on GitHub (Feb 12, 2021): I managed to solve my own problem :-) (after a good night-sleep, I could think more clear again) - I added 2 parameters, of type "hidden": hidden_s and hidden_p (hidden_s contains programmatically SSID, and hidden_p the password) - I added a function in the HTTP_SCRIPT[] in strings_en.h, just before the </script> tag: "function myHidden()\n" "{\n" " var txt_s = document.getElementById('s');\n" " var txt_hidden_s = document.getElementById('hidden_s');\n" " var txt_p = document.getElementById('p');\n" " var txt_hidden_p = document.getElementById('hidden_p');\n" " txt_s.value = txt_hidden_s.value;\n" " txt_p.value = txt_hidden_p.value;\n" "}\n" - in the HTTP_HEAD_END[], I added onload='myHidden()' , right after the <body Everytime, the page loads, it passes the data from the hidden field, into the s and p field :-)
Author
Owner

@tablatronix commented on GitHub (Feb 12, 2021):

It will use the creds from the ESP and show them, so just save them to the esp. Are you obtaining them from somewhere else?

<!-- gh-comment-id:778296885 --> @tablatronix commented on GitHub (Feb 12, 2021): It will use the creds from the ESP and show them, so just save them to the esp. Are you obtaining them from somewhere else?
Author
Owner

@sn00zerman commented on GitHub (Feb 12, 2021):

I needed a way to programmatically set them in the captive portal, giving the user the possibility to "adjust" these settings and save them. I obtain them trough an algorithm, AP's are taken offline, "re-calculated" and taken back online, in a 24hour cycle ...

But my problem is solved now, with the hidden_s and hidden_p :-)

<!-- gh-comment-id:778426366 --> @sn00zerman commented on GitHub (Feb 12, 2021): I needed a way to programmatically set them in the captive portal, giving the user the possibility to "adjust" these settings and save them. I obtain them trough an algorithm, AP's are taken offline, "re-calculated" and taken back online, in a 24hour cycle ... But my problem is solved now, with the hidden_s and hidden_p :-)
Author
Owner

@tablatronix commented on GitHub (Feb 12, 2021):

I mean why not just do WiFi.begin(SSID,PSK);

<!-- gh-comment-id:778482928 --> @tablatronix commented on GitHub (Feb 12, 2021): I mean why not just do WiFi.begin(SSID,PSK);
Author
Owner

@tablatronix commented on GitHub (Feb 12, 2021):

fyi I added this a few days ago

// to preload autoconnect for test fixtures or other uses that skip esp sta config
bool          preloadWiFi(String ssid, String pass);
<!-- gh-comment-id:778484766 --> @tablatronix commented on GitHub (Feb 12, 2021): fyi I added this a few days ago // to preload autoconnect for test fixtures or other uses that skip esp sta config bool preloadWiFi(String ssid, String pass);
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1030
No description provided.