# Interrupt from the CC3000

**URL:** <https://community.particle.io/t/interrupt-from-the-cc3000/2877>\
**Category:** General\
**Created:** [February 15, 2014, 12:13pm UTC](https://community.particle.io/t/interrupt-from-the-cc3000/2877 "2014-02-15T12:13:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomPen](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@TomPen](https://community.particle.io/u/TomPen)\
**Post date:** [February 15, 2014, 12:13pm UTC](https://community.particle.io/t/interrupt-from-the-cc3000/2877/1 "2014-02-15T12:13:36Z")

</div>

Hi,

First of all, sorry for my english 😉

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

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [February 15, 2014, 8:14pm UTC](https://community.particle.io/t/interrupt-from-the-cc3000/2877/2 "2014-02-15T20:14:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TomPen](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@TomPen](https://community.particle.io/u/TomPen)\
**Post date:** [February 16, 2014, 2:56pm UTC](https://community.particle.io/t/interrupt-from-the-cc3000/2877/3 "2014-02-16T14:56:43Z")

</div>

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” ?

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [February 16, 2014, 7:43pm UTC](https://community.particle.io/t/interrupt-from-the-cc3000/2877/4 "2014-02-16T19:43:49Z")

</div>

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
