arduino-libraries / ArduinoIoTCloud

Home Page:https://app.arduino.cc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Dual Station and Access point WiFi mode for Arduino IoT Cloud connection.

jsolderitsch opened this issue · comments

I have use case where I want to connect a ESP32 device to the cloud and to use the device as an access point to send UDP messages to it locally. For example I sent packets using PacketSender from my host.

Attempting to do this results either in WiFi status codes of 6 or 255 when the cloud update statement is left in the main loop, depending on if I set the mode for WiFI as either WIFI_AP_STA or WIFI_AP before I attempt to create the Soft-AP:

  Serial.println("\n[*] Creating ESP32 AP");
  Serial.print("Setting soft-AP configuration ... ");
  Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");
  Serial.print("Setting soft-AP ... ");
  Serial.println(WiFi.softAP(ssidAP, passwordAP, 11) ? "Ready" : "Failed!");
  Serial.print("Soft-AP IP address = ");
  Serial.println(WiFi.softAPIP());

If I comment out the cloud update statement in the main loop:

//   ArduinoCloud.update();

then the Access Point gets created but of course I don't connect successfully to the Arduino IoT cloud.

18:01:36.679 -> [*] Creating ESP32 AP
18:01:36.679 -> Setting soft-AP configuration ... Ready
18:01:36.775 -> Setting soft-AP ... Ready
18:01:36.775 -> Soft-AP IP address = 192.168.10.1
18:01:38.975 -> ***** Arduino IoT Cloud - configuration info *****
18:01:39.039 -> Device ID: 1c18a0ac-0a43-4d2f-88c2-5397a7af6aac
18:01:39.071 -> MQTT Broker: iot.arduino.cc:8884
18:01:52.150 -> Received(IP/Size/Data): 192.168.10.2 / 4 / send

If I leave the update statement live in my example and I set the WIFI mode to dual AP and Station I see:

18:12:43.328 -> [*] Creating ESP32 AP
18:12:43.360 -> Setting soft-AP configuration ... Ready
18:12:43.393 -> Setting soft-AP ... Ready
18:12:43.424 -> Soft-AP IP address = 192.168.10.1
18:12:45.654 -> ***** Arduino IoT Cloud - configuration info *****
18:12:45.718 -> Device ID: 1c18a0ac-0a43-4d2f-88c2-5397a7af6aac
18:12:45.783 -> MQTT Broker: iot.arduino.cc:8884
18:12:45.815 -> WiFi.status(): 6
18:12:49.810 -> Connection to "JamesElektra" failed
18:12:49.842 -> Retrying in  "4000" milliseconds
18:12:53.778 -> Connected to "JamesElektra"
18:12:57.809 -> Connected to Arduino IoT Cloud
18:12:57.840 -> Thing ID: 20c2ecb3-91fa-45a9-9cec-b3d15bea1d63

If I use just the AP mode by itself I see:

17:59:31.684 -> [*] Creating ESP32 AP
17:59:31.716 -> Setting soft-AP configuration ... Ready
17:59:31.781 -> Setting soft-AP ... Ready
17:59:31.812 -> Soft-AP IP address = 192.168.10.1
17:59:34.009 -> ***** Arduino IoT Cloud - configuration info *****
17:59:34.073 -> Device ID: 1c18a0ac-0a43-4d2f-88c2-5397a7af6aac
17:59:34.106 -> MQTT Broker: iot.arduino.cc:8884
17:59:34.138 -> WiFi.status(): 255
17:59:38.159 -> Connection to "JamesElektra" failed
17:59:38.199 -> Retrying in  "4000" milliseconds
17:59:42.150 -> Connected to "JamesElektra"
17:59:44.706 -> Connected to Arduino IoT Cloud
17:59:44.738 -> Thing ID: 20c2ecb3-91fa-45a9-9cec-b3d15bea1d63

So the cloud connection happens in both cases but there is no Access Point available.

Can this approach be supported, or is there another configuration option I can try and be successful.

I am using a vanilla example for a simple cloud variable inside the rest of my code.

I posted to the IoT cloud topic group:
https://forum.arduino.cc/t/can-arduino-iot-cloud-support-dual-ap-and-station-mode/1255555

I think this issue can be closed because I found an approach that works and is marked as a solution in the forum post.