Skip to content

Get SSID and PASSWORD for current connect WIFI #103

@expertup

Description

@expertup

I make WIFI mesh network. After connect to WIFI I want to get SSID and passord for connect to painlessMesh network.

After enter data in config page, the functions wifiManager.getConfiguredSTASSID() and wifiManager.getConfiguredSTAPassword() working and return entered data, but after restart module these function return nothing.

How to is possible get SSID and password from current connection?

void setup() {
  Serial.begin(115200);
  
  AsyncWiFiManager wifiManager(&server,&dns);

  wifiManager.autoConnect("AutoConnectAP");

  mesh.setDebugMsgTypes( ERROR | STARTUP | CONNECTION );  // set before init() so that you can see startup messages

  // Channel set to 6. Make sure to use the same channel for your mesh and for you other
  // network (STATION_SSID)
  mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT, WIFI_AP_STA, 6, 1 );
  mesh.onReceive(&receivedCallback);

  Serial.println("My SSID is " + wifiManager.getConfiguredSTASSID());
  
  mesh.stationManual(wifiManager.getConfiguredSTASSID(), wifiManager.getConfiguredSTAPassword());
  //mesh.setHostname(HOSTNAME);

  mesh.setRoot(false);
  mesh.setContainsRoot(true);

  myAPIP = IPAddress(mesh.getAPIP());
  Serial.println("My AP IP is " + myAPIP.toString());

  //Async webserver
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(200, "text/html", "<form>Text to Broadcast<br><input type='text' name='BROADCAST'><br><br><input type='submit' value='Submit'></form>");
    if (request->hasArg("BROADCAST")){
      String msg = request->arg("BROADCAST");
      mesh.sendBroadcast(msg);
    }
  });
  server.begin();

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions