Interrupt from the CC3000

Hi,

First of all, sorry for my english :wink:

I was wondering if it is possible to “stop” the execution of a function (on the Sparkcore) as soon as I send to it a http request ?

Actually, i start my functions using http request and :
Spark.function(“param1”, foo1);
Spark.function(“param2”, foo2);

For example, the first function may take several seconds to be performed (for loops, etc.). So i would like to stop it, as soon as i send a new http request, let say to activate the second function.

Thanks !!

Tom

Hi @TomPen,

Sure! You could simply set a flag indicating that the core should wait until something is done… something like…

int STOP_WORKING = 0;
int counter = 0;

void setup() {
    Spark.function("foo1", foo1);
    Spark.function("foo2", foo2);

}

void loop() {
    if (!STOP_WORKING) {
        counter++;
    }
}

int foo1(String command) {
    STOP_WORKING = 1;
    Delay(1000);
    return 1;
}

int foo2(String command) {
    STOP_WORKING = 0;
    return 0;
}

Thanks,
David

Ok thanks Dave.
But it not going to work because when the sparkcore is in the while loop, it doesnt react to http request (no reaction to foo1 or foo2).

To make it work, I used a IF( !STOP_WORKING ) instead of the while, and the while loop is done by the loop() function.
It works, but it is not very nice… If I want to use a for loop, i need to have the loop counter outside the loop() function, and to increase the index each time, until it reaches a max. value. etc…

That would be nice to just code a for loop in a function, as usual, and the sparkcore receives an interrupt that can stop the execution each time there is a HTTP request…

Maybe it is not possible as the CC3000 is continuously “talking” with the core ?! So the HTTP request would not be distingued for “normal chat” ?

Hi @TomPen,

Oops, good catch! That was a total typo on my part, meant to type ‘if’ and typed ‘while’ instead. Right now the loop behavior must not block for longer than a few seconds, but we’re working on a fix for that. The Spark_WLAN_Loop function is called between every loop execution, and will call your exposed function when called from the Api. So it’s a bit like an interrupt, but not exactly quite yet.

Thanks,
David