Is there an alternative to "pressing the Mode Button" for Smart Config & Clear Wifi Data?

@Dave i managed to find the code to trigger the smart_config. Not too tough to do it! Let me cook up some code 1st :smile:

1 Like

I did find the other thread, but now I feel like I should wait…

Okay, sorry to not wait longer!

1 Like

@nitnut I have put together something really something raw and simple at the moment.


Basically, it uses an Interrupt on a User pin and sets WLAN_SMART_CONFIG_START = 1;

I would like to add in some debounce for this and using to trigger a reset after a timeout period :smiley:

1 Like

Here’s another way to force Smart Config from your own button:

And some work being done to make using the mode button in your code even easier:

1 Like

Here’s another way to force Smart Config from your own button:

And some work being done to make using the mode button in your code even easier:


@kennethlimcp The code works great and it answers point 3! @BDub 's code works the same except that it is ‘production ready’ :smiley:

But the code only works if the Spark is successfully connected to a Wifi router. My requirement was for when the password on the Wifi router has changed and application.cpp code no longer works since the Spark gets busy trying to endlessly connect to the router with the old SSID & password.

@Dave I am quite happy with the flow and process of smart config. Its just that if I intend to make a product around the Spark (without any modification) and design a PCB board, I don’t want to have a wire that crawls from the Mode button to an external button. Instead I would like a Digital or an Analog pin to completely replace the Mode Button (and I get to use pcb traces instead of wires)

  • So is there a place in the Core-Firmware where all I have to do is change the pin number of the Mode Button to say D0, and from there on out D0 completely replaces the Mode Button (including interrupts and functionality) even when the Spark application code hangs.

@nitnut To my understanding, it’s possible only if you actually build local with the code used to check the external button and trigger the Smart Config.

  1. The code we wrote only works IF the wifi credential got changed AFTER the :spark: was initialized and already running

  2. IF the core is powered up AFTER a wifi credential change, essentially it will remain in the ‘blinking green’ mode and the only way to check the external button in this scenario is to have the code in ‘application.cpp’, the same file where the MODE button is currently checked

@satishgn is there a way for us to have code in our .ino to be executed before the core starts connecting to cloud? Saw your commit for the other issue and seems related.

@kennethlimcp Yep that’s precisely the problem.

This would be absolutely brilliant if it can work.

However I feel like permanently having the mode button be mapped to a digital or analog pin might be an easier solution. [But I’m sure this will be a ‘custom’ solution and not a ‘general’ one]

@kennethlimcp, with the latest commit, it should now be possible to execute your hardware related code in your constructor before main() starts. Definitely welcome any feedback/idea for improvement!

@satishgn but i have to build locally to get the latest commit going right? Since it’s not going to be pushed to the compile-server2 anything soon

I’m not really advance programmer at the moment and still learning along the way but would definitely love to get this running!

We did push new firmware to the build servers last night, but that probably won’t include this patch until the next push. Right now I think we’re averaging about 1-2 firmware releases every 2 weeks.


@satishgn I can compile locally and test it out; but…

Can you please explain what this exactly means? In which file would I need to place the code? Or if you could point me to a thread or source I would appreciate it.

@kennethlimcp Its not too difficult to do to get things compiled locally if you follow the instructions given on the github page. I’d be glad to help if you run into issues. If I could do it, then anyone can :smile:

@nitnut which approach are you looking at?

If you would prefer the attachInterrupt() way, i can guide you on where to insert the code for compiling locally.

Making an external button work like the MODE button is gonna require some code changes and would be better to wait for the functions to be exposed for users.

@kennethlimcp Sorry about the late reply, I’m in an another timezone.

It would be great to get both ways working because Option 1 (AttachInterrupt) seems dynamic and user friendly but Option 2 (remap mode button) seems fail-safe.

Can you please run me through Option 1 for now so that I can test it out.

  • Where and what code do I need to insert?
  • Also does this mean the Interrupt will be reliably active even during the Green Flashing Stage? If so, then I might not even require Option 2 at all.

Thank you so much already!

@nitnut If you are compiling locally, there is a simple way now to get this going.

With this latest commit:

So what you need to do:

  1. Add this line ‘SparkClass SparkConnect(false);’ in ‘application.cpp’

  2. Then just add in the normal code in setup() like the attachInterrupt;

  3. At the end of setup(), we would want to connect back so ‘SparkConnect(true);’

  4. So with that, we have the core initialized before we proceed with cloud connection.

I never tried it so i cannot tell you if it’s working but the idea is there.

Let me know and i see what i can contribute :smiley:


There’s a simpler way not to work locally and test at the same time but the Spark-CLI is involved. Which do you prefer? :smiley: the CLI is gonna be so much easier!

@kennethlimcp It works! But obviously here’s some problems I ran into…

My code:

  • Blinks the D7 Led with a delay of 500ms inside Loop()
  • When the button connected to D0 is pressed, the :spark: goes into Smart Config Mode
  • The D7 Led is ON continuosly

Try 1:

  • Used only SparkClass SparkConnect(false); and did not include SparkConnect(true);
  • The D7 Led Blinking and the Green Flashing happen almost immediately and simultaneously after the code is flashed
  • On pressing the D0 button, the :spark: enters the Smart Config mode even though it hasn’t connected to the router yet!
  • I enter the SSID & Password via Serial.
  • The :spark: restarts and the D7 Led blinks
  • But it does not connect to my router and goes into GFOD :disappointed:

TRY 2:

  • Used SparkClass SparkConnect(false);
  • Added SparkConnect(true); at the end of Setup()
  • Failed to compile :disappointed:
  • error : no match for call to '(SparkClass) (bool)' SparkConnect(true);

TRY 3:

  • Used SparkClass SparkConnect(false);
  • Added SparkClass SparkConnect2(true); at the end of Setup()
  • D7 Led does not blink considering the code for it is inside the loop() :ok_hand:
  • If I don’t touch the :spark: it successfully connects to the router
  • D0 Button sends Spark to Smart Config before and after connection
  • After entering SSID & Password via Serial; it successfully connects to the router!
  • And I am happy :joy:

I cloned the repos likes two hours ago and I am on the master branch. My actual application code has had issues off late working on the master branch for some reason. I’ll build my code on the master branch along with this test and get back to you on it soon.

Thank you so much! I was pretty confident this was not possible but :spark: seems to surprise me all the time. And I am grateful to you @satishgn

@kennethlimcp I have another favor to ask.

Like you said WLAN_SMART_CONFIG_START = 1; is a flag that needs to be set to enter Smart Config mode. Is there a flag that can be set to Clear All Wifi Data (Equivalent to holding the Mode Button for ~10 seconds) ??

Thanks :smile:

@nitnut i believe it can be done but why would you want to do that? :smiley:

Anyway there was an update earlier like an hour ago which makes things much easier

This can turn off wifi or cloud connection or both

Let me dig up the code later. What’s your time zone like?

EDIT: Seems like this line can do the job


@kennethlimcp If I’m not wrong, entering your router credentials using Smart Config adds the SSID and Password you just entered to an already existing list of SSIDs & Passwords. This process has not been very reliable for me (I keep getting GFOD because of this) and often I have to end up clearing all wifi data before the Spark is up and running. So I’d like to have the Flag in hand for worst case scenarios.

OK so I just have to include the “.h” files and it works without having to call the functions in it? I shall test it out now. I currently don’t have a lot of use for it though.

I’m in India so its IST = GMT +530 out here. But drop a post at your convenience. Thanks so much already :smile: