My Spark Core and a sensor circuit is going to be boxed up and have only the light sensor and the temperature sensor exposed. I realized that if my Wifi Router password changes, then my Spark is going to hang and therefore I will need an exposed Mode Button as well. But the only way I can think of to have access to the mode button is to connect a wire to one of the mode button’s semi-exposed pads (the result is an ugly wire crawling on the spark)
So are there any alternatives to the mode button-press (Smart Config or clear Wifi Data) or at least a more elegant way to have access to the mode button; I’ll try summing up the possible alternatives
Since the Mode Button is an interrupt pin, can I bind one of the analog or digital pins to the same interrupt service routine?
Is there an already exposed pad for the mode button that I don’t know of?
Lets assume the case where the router password has not changed yet and the Spark is working fine
Any function call that is at my disposal to directly put the core into smart config (via serial, tcp or udp)? I’m assuming we can directly call the ISR here?
Don’t think it’s exposed except for the soldered button
I believe there is but not a function already created to do so.
Trying to hunt down the code that triggers the Smart Config mode but if @Dave can point me the way i can write up a test code, verify and share with you
@kennethlimcp The code works great and it answers point 3! @BDub 's code works the same except that it is ‘production ready’
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.
The code we wrote only works IF the wifi credential got changed AFTER the was initialized and already running
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.
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!
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
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.
@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:
Add this line ‘SparkClass SparkConnect(false);’ in ‘application.cpp’
Then just add in the normal code in setup() like the attachInterrupt;
At the end of setup(), we would want to connect back so ‘SparkConnect(true);’
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
EDIT:
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? 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 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 enters the Smart Config mode even though it hasn’t connected to the router yet!
I enter the SSID & Password via Serial.
The restarts and the D7 Led blinks
But it does not connect to my router and goes into GFOD
TRY 2:
Used SparkClass SparkConnect(false);
Added SparkConnect(true); at the end of Setup()
Failed to compile
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()
If I don’t touch the 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
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 seems to surprise me all the time. And I am grateful to you @satishgn