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 ?
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