How to connect to wireless AP, but not to the Spark Cloud?

Hello,
I have an application where I’m just trying to hit a MQTT broker on the local LAN. I only need the Spark cloud when I want to reprogram, which I can do via a button on the device. So, I want the Photon to connect to the wireless AP, because that’s where the broker is. But I don’t want it to connect to the cloud unless I press the button. Alternatively, it can connect to the Spark cloud if it wants or is able to, but don’t prevent my user application from running just because the Spark cloud can’t be reached. However, do prevent it from running until the wifi connection is established.

I read the system mode explanation, but still have questions.

In semi and full manual mode, the “Spark.connect()” command seems to tell the Core/Photon to do two things:

  1. connect to wireless AP
  2. connect to Spark cloud

Spark.connect() doesn’t seem to differentiate between “connect to wireless AP” and “connect to Spark Cloud”?

If the Spark.connect call never reaches the Spark cloud, the microcontroller hangs at the routine, right? Is there a separate Wireless.connect() and a Spark.connect(), where Wireless.connect() only connects to the wireless AP and not try to reach the Cloud?

Thanks!

Yup! Take a look at the WiFi library.

If the Photon is in MANUAL or SEMI_AUTOMATIC mode, calling Spark.connect() shouldn't block your code. In fact, you have to manually "block" in a loop to make sure you're connected to the cloud before you call any cloud functions:

Particle.connect();
while (!Particle.connected()) {
    Particle.process();
}

The Particle functions in that code are the same as the Spark ones. The Spark functions are deprecated, but still usable.