Cleaning up after soft_ap_example

tim8656
Posts: 5
Joined: Fri Jun 17, 2022 1:38 pm

Cleaning up after soft_ap_example

Postby tim8656 » Fri Jun 17, 2022 2:57 pm

Hi

I am using an AZ Delivery ESP32, VS Code, PlatformIO and ESP-Prog debugger.

What I want to do is:

1 Set the ESP32 up as an access point, scan the local Wifi signals and present the list in a web page.

2 The user selects a wifi signal and enters the password.

3 The ESP32 then exits AP mode and connects to the selected wifi signal with the entered password.

4 The ESP32 then calls a time server to synchronise its clock

5 The ESP32 then periodically sends timestamped data to an mqtt broker.

The problem seems to lie with the AP mode. With hardcoded SSID and password, the time server and mqtt code
work fine, but if the AP and webserver are used, the timeserver code never seems to get an ip address.

I can work around the problem by saving the credentials in flash after step 2, setting a bypass_webserver flag and rebooting,
but I would like to find a tidier solution.

As a test vehicle, I've built the sntp example code and inserted the following after ++boot_count;

// WEBSERVER CODE STARTS HERE >>>>>>>>>>>>>>>>>>>>>>>>>

// Set the esp32 up as an access point and implement a webserver
// The webserver scans the available wifi signals and presents them in a web page
// The user selects the desired signal and enters the password

implement_webserver(); // just start with the soft_ap_example for now, then set webserver_complete

// poll the webserver for a 'complete' status

while (!webserver_complete)
{
vTaskDelay(1 / portTICK_RATE_MS);
webserver_complete = get_complete();
}

shutdown_webserver(); // attempt to remove all trace of the access point/webserver

// get the credentials that the user entered
wifi_credentials = get_credentials();
printf("Wifi credentials are: ssid %s; password %s\n", wifi_credentials.ssid, wifi_credentials.password);

// WEBSERVER CODE ENDS HERE >>>>>>>>>>>>>>>>>>>>>>>>>>

obtain_time();// now try to get the time...

Any ideas. anyone?

Who is online

Users browsing this forum: No registered users and 330 guests