Spark Core + AccelStepper Library problems

There are several ways (more and less verbose) to connect and there are multiple threads that show how to code it.

One way is shown here
Photon/P1 loop()/user code blocking in SEMI_AUTOMATIC mode

For your purpose to only connect for OTA flashing, you might want to put the connection logic into a function and trigger that fn via a button.