I have an example running and connecting to the IoT cloud using an ESP32 AdaFruit feather. I wonder if the dual Soft Access Point and Station WiFi feature can be supported? In addition to the IoT cloud connection which is working, I want to create a side-by-side soft access point at the default private address 192.168.4.1 and have my Arduino device listen for UDP messages coming through that address. I use PacketSender to send UDP packets.
I used to use WiFi Manager along with dual access point to have the ESP32 connected to the internet AND set up a server listening on 192.168.4.1. The local address has its own SSID and Password:
The WiFi dialog on my host (intel Mac running Sonoma) to enter the SSID and password never appears when I am using the cloud connection methods.
Other code snippets to show my approach are included below.
void connectLocalAP() {
WiFi.mode(WIFI_AP_STA); // explicitly set mode, esp defaults to STA+AP
Serial.println("\n[*] Creating ESP32 AP");
WiFi.softAP(ssidAP, passwordAP); // ESP-32 as access point
Serial.print("[+] AP Created with IP Gateway ");
Serial.println(WiFi.softAPIP()); /*Printing the AP IP address*/
Serial.print("ESP Board MAC Address: ");
Serial.println(WiFi.macAddress());
Serial.print("Soft-AP IP address = ");
Serial.println(WiFi.softAPIP());
Udp.begin(localPort);
}
and in setup() I call the AP connection function and try to complete the cloud connection
connectLocalAP();
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
Maybe want I want to do is not supported?. There are no errors in Serial Monitor.
The IoT connection DOES succeed but there is no WiFi presence at 192.168.4.1 using the SSID and password I have chosen.
What I expect to happen is that my computer (a Mac running Sonoma) would pop up a dialog to connect to the Soft-AP access point with the AP SSID and password as declared. No connection dialog appears and the list of SSIDs that my computer sees does not have one named EEK-F008 in it.
I made some progress on this and raised an issue on the github issues page: https://github.com/arduino-libraries/ArduinoIoTCloud/issues/454. The inclusion of the cloud update statement in the main loop causes WiFi status codes of 6 or 255 depending on how I set the WiFi mode. If I comment out the update statement:
// ArduinoCloud.update();
in the main loop the access point is created and works but then no cloud connection is fully established. Leaving the line as originally generated causes the Status Code errors.
But maybe this use case is not supported with current cloud operations?
Maybe I need to wait for the IoT Cloud connection to complete BEFORE I try to set up a Soft-AP. Is there an event I can watch for, have a handler for that event, and in the handler call my Soft-AP creation logic? I have written WiFi Event handler logic where ordinary WiFI events are checked and reacted to. Will the IoT cloud connection handler publish events I can handle in a similar way? Some sample code might help me to see how to approach this.
Well, I should have seen this pathway earlier, but yes, I can wait until the IoT connection handler uses the named SSID and password to connect to my local WiFi access point which generates a connected event and then I can spawn the Soft-AP at whatever local address I choose which does not disappear and can be used to receive and process messages through the local address. It was enough to write the handler, connect the handler in setup() and call the AP creation logic in the connected event:
//wifi event handler
void WiFiEvent(WiFiEvent_t event) {
switch (event) {
case SYSTEM_EVENT_STA_GOT_IP:
Serial.println("WiFi connected!");
//When connected set UDP AP
connectLocalAP();
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
Serial.println("WiFi not connected");
break;
default:
// Serial.println("Unexpected WiFi event");
break;
}
}
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
WiFi.mode(WIFI_AP_STA); // explicitly set mode, esp defaults to STA+AP
WiFi.onEvent(WiFiEvent);
Nice and clear. Hope this talking to myself sequence of replies can help someone else down the line.