Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ESP32 WebSerial Wifi connection ?

Status
Not open for further replies.

Wp100

Well-Known Member
Hi,

Have been running this WebSerial code from this tutorial and it works fine.
https://randomnerdtutorials.com/esp32-webserial-library/

However we want to incorporate it into our main controller program, but do not want to leave the Wifi function running all the time, but have it restarted on an event/timed basis.

Having no experience of wifi code we tried this bit of code, but do not know if it actually closes the Wifi down properly, and if repeating the start up code from the Setup , it seems to start the wifi ok and allows the web page to be displayed on the PC, but no data is transmitted.

Have looked and found this type of question on the web, but without any answer, surely there must be a way to stop and start wifi rather than letting it wastefully run all the time when not needed ?

Code:
 // main loop of wifi code- then -

 WiFi.disconnect();

   Serial.print("disconnected for 10 secs");
   delay(10000);
   Serial.print("reconnecting ");

 WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.printf("WiFi Failed!\n");
    return;
  }
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
  // WebSerial is accessible at "<IP Address>/webserial" in browser
  WebSerial.begin(&server);
  WebSerial.msgCallback(recvMsg);
  server.begin();
 
  WebSerial.println("Hello-Again!");
  delay(2000);
}    //end of main loop
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top