# Manual system mode not functioning?

**URL:** https://community.particle.io/t/manual-system-mode-not-functioning/10823
**Category:** Troubleshooting
**Created:** [March 22, 2015, 12:03am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823 "2015-03-22T00:03:21Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![jnm2](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jnm2/32/4839_2.png) [@jnm2](https://community.particle.io/u/jnm2)
#### Post date: [March 22, 2015, 12:03am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/1 "2015-03-22T00:03:21Z")

</div>

Am I misunderstanding manual mode or is it not functioning as advertised? When I call `Spark.connect` when wifi is connected, it stays breathing green and never even flashes cyan. It’s as though it never even tries to connect to the server.

According to [the docs](http://docs.spark.io/firmware/#system-modes-manual-mode), the following code should work:

```
#include "application.h"
SYSTEM_MODE(MANUAL);

void setup()
{
    Serial.begin(115200);    
    
    WiFi.connect();
    Serial.print("Connecting to WiFi...");
    while (!WiFi.ready());
    Serial.println(" connected.");

    Spark.connect();
    Serial.print("Connecting to server...");
    while (!Spark.connected());
    Serial.println(" connected.");
}

void loop()
{
    Serial.println("loop");
}

```

`Spark.connected()` is never true.

The only reason that I’m not using automatic is that I want to control exactly when `Spark.process` is called during the loop. The server connection is purely for OTA updates and doesn’t need to run more than once every ten seconds.

---

<div class="post-metadata">

### Author: ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)
#### Post date: [March 22, 2015, 1:58am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/2 "2015-03-22T01:58:20Z")

</div>

@jnm2, in manual mode, you have to call [Spark.process()](http://docs.spark.io/firmware/#spark-process) regularly otherwise the “background” process will not run to create and maintain the cloud connection 😃

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [March 22, 2015, 8:55am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/3 "2015-03-22T08:55:12Z")

</div>

As @peekay123 pointed out in MANUAL mode you've to do it all manually, as the docs (you linked) state here  
[http://docs.spark.io/firmware/#system-modes-manual-mode](http://docs.spark.io/firmware/#system-modes-manual-mode)

As a side note `Spark.connect()` does take care of `WiFi.connect()` too, if it's not already there.  
The easiest way to try this mode is by using the provided sample in the docs above, and adapt it for your needs.  
I guess your sample is only for demonstration of the "misbehaviour", since doing all that in `setup()` somehow defeats the purpose of manual mode 😉

As for this

> [@jnm2](#):
>
> The server connection is purely for OTA updates and doesn't need to run more than once every ten seconds.

In this case you might have troubles getting the timing right to trigger your OTA update near enough to your one call of `Spark.process()` per 10sec. At least this is what I experience when doing things via Web IDE and having a `loop()` pushing close to the 10sec limit, even in automatic mode.

If you've got physical access to your Core, I'd go for a button to trigger a tight loop which calls `Spark.process()` - possibly with a timeout.

* * *

But if you want to get your code above running anyhow, apart from calling `Spark.process()` regularly, you might also want to try this little alteration

```auto
  ...
  while (!WiFi.ready())
    SPARK_WLAN_Loop();
  ...
  while (!Spark.connected())
    SPARK_WLAN_Loop();
  ...

```

And what does your serial monitor tell you, where your code got stuck before?

---

<div class="post-metadata">

### Author: ![jnm2](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jnm2/32/4839_2.png) [@jnm2](https://community.particle.io/u/jnm2)
#### Post date: [March 22, 2015, 1:15pm UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/4 "2015-03-22T13:15:23Z")

</div>

I had also tried putting `Spark.process` inside the loop that waits for `Spark.connected()`, but `Spark.connected()` never happens. The serial monitor shows that. Also, the WiFi does not connect without me putting the top code in. Try it; can you get it to work the way you expect?

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [March 22, 2015, 1:47pm UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/5 "2015-03-22T13:47:53Z")

</div>

Yep, at least last time I tried with my IoT-PS/2-Mouse project, but I can try to flash your code an tweak it till it works.

Meanwhile, could you try `SPARK_WLAN_Loop()`?

* * *

Tried it as suggested and it works.  
I don’t understand why it’s always easier to argue that our suggestions won’t work instead of just trying them out 😒

---

<div class="post-metadata">

### Author: ![jnm2](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jnm2/32/4839_2.png) [@jnm2](https://community.particle.io/u/jnm2)
#### Post date: [March 28, 2015, 11:02pm UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/6 "2015-03-28T23:02:20Z")

</div>

Hey! I just got back and saw this. This is the first time I’m physically back with the Spark! This isn’t supposed to be an argument. ☹

I asked you to try the sample that I posted that is _documented_ to work which doesn’t work. Maybe `SPARK_WLAN_Loop` should be included in the documentation?

I solved the problem for now by staying in automatic mode and running an inner `while` loop inside the `loop` method, and exiting the `while` loop every ten seconds. Works like a charm. I feel safer with documented functions.

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [March 28, 2015, 11:29pm UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/7 "2015-03-28T23:29:06Z")

</div>

> [@jnm2](#):
>
> I asked you to try the sample that I posted that is documented to work which doesn't work.

Can you provide a link to that very documentation where you got that code from.  
If we know where, we might be able to correct the docs.

I can't find it. I can only find this at the link you provided

```auto
SYSTEM_MODE(MANUAL);

void setup() {
  // This will run automatically
}

void loop() {
  if (buttonIsPressed()) {
    Spark.connect();
  }
  if (Spark.connected()) {
    Spark.process();
    doOtherStuff();
  }
}

```

And this works like documented.  
As for `SPARK_WLAN_Loop()`, it is frequently used in connection with tight `while()` loops used in samples in the docs (OK, in connection with `Serial.available()`, but even so ;-)).

Have you tried the other suggestion to let `Spark.connect()` do the `WiFi.connect()` implicitly?

---

<div class="post-metadata">

### Author: ![jnm2](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jnm2/32/4839_2.png) [@jnm2](https://community.particle.io/u/jnm2)
#### Post date: [March 29, 2015, 12:12am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/8 "2015-03-29T00:12:04Z")

</div>

That is the documentation I was referring to. The only difference between the exact doc code and the code I posted seems to be that I was trying to `connect` inside `setup` instead of `loop`. That suggests that there is something going on behind the scenes with `loop` after all, even though it’s in manual mode, contrary to the documentation. Maybe it’s `SPARK_WLAN_Loop`, the missing link?

Yes, I did try that. Like I said, if you take the wifi lines out of my example, `Spark.connect()` doesn’t connect the wifi. I feel like it shouldn’t matter whether you are connecting from `loop` or from `setup` if you are in manual mode.

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [March 29, 2015, 12:29am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/9 "2015-03-29T00:29:27Z")

</div>

Ok, actually doing it in `setup()` instead of `loop()` is not the only difference.

One of which and the biggest troublemaker in this is your tight `while()` loop.  
There is nothing spooky going on behind the scenes, it’s the timing that makes the difference.

And `Spark.connect()` **_does_** even call `WiFi.on()` and `WiFi.connect()` if required - apart from having it seen in the source and in the docs you can even try it with this stripped down version of your code that **_does_** work on my Core.

```auto
SYSTEM_MODE(MANUAL);

void setup()
{
    WiFi.off(); // now it's definetly off
    delay(1000);
    Serial.begin(115200);    

/*
    // this can be done, but there is no need
    // since it's done implicitly with Spark.connect()
    
    WiFi.connect();
    Serial.print("Connecting to WiFi...");
    while (!WiFi.ready())
      delay(100);
    Serial.println(" connected.");
*/
    Spark.connect();
    Serial.print("Connecting to server...");
    while (!Spark.connected())
        delay(100); // give it some time
    Serial.println(" connected.");
}

void loop()
{
    Spark.process();
    delay(500);
}

```

* * *

So I’d guess it’s less the _wrong_ documentation but rather misunderstanding and misinterpretation of symptoms.

---

<div class="post-metadata">

### Author: ![jnm2](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jnm2/32/4839_2.png) [@jnm2](https://community.particle.io/u/jnm2)
#### Post date: [April 3, 2015, 10:38pm UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/10 "2015-04-03T22:38:13Z")

</div>

You are right, of course, about the misinterpretation of symptoms. Thank you. So the only thing I was missing was the `delay` call. I would not have guessed that without documentation.

Now, in my mind, it doesn’t make sense that a delay is mandatory- does that mean `delay` is actually doing work besides just blocking?

---

<div class="post-metadata">

### Author: ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)
#### Post date: [April 4, 2015, 5:36am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/11 "2015-04-04T05:36:34Z")

</div>

> [@jnm2](#):
>
> does that mean delay is actually doing work besides just blocking?

No, not really.  
It is true, that - at the moment - delays greater that 1000ms do implicitly call `SPARK_WLAN_Loop();` and some other things to avoid loosing cloud connection, but that's not the case here.

Delay just gives the Core time to breathe, but maybe @mdma can explain a bit better why your tight `while (!Spark.connected());` did prevent the Core to actually connect, while a little delay made it work.

---

<div class="post-metadata">

### Author: ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)
#### Post date: [April 5, 2015, 6:00am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/12 "2015-04-05T06:00:01Z")

</div>

Ah, individual `delay()` calls accumulate the delay, and when this is over 1000ms it will call the background loop. So even a delay of 1ms will eventually run the background loop.

Without the delay, the background loop is never run which is why the device couldn’t connect.

Using delays to run the background loop is a bit of a hack since the background loop execution is a side-affect and not the primary purpose of the function. It’s better instead to call the background loop directly:

```auto
while (!Spark.connected()) {
   SPARK_WLAN_Loop();
}

```

In the 0.4.x line of firmware, the background loop is part of the public API, via

`Spark.process()`

---

<div class="post-metadata">

### Author: ![yianmar](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yianmar/32/2990_2.png) [@yianmar](https://community.particle.io/u/yianmar)
#### Post date: [July 18, 2015, 5:37am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/13 "2015-07-18T05:37:07Z")

</div>

Some ideas…this simple code works fine at my first Pc, but it is not working at the other…seems ignoring SYSTEM\_MODE(MANUAL); trying to connect at router…

#include “application.h”

SYSTEM\_MODE(MANUAL);  
byte mac[6];  
/\* executes once at startup \*/  
void setup() {  
Serial.begin(9600);  
}

/\* executes continuously after setup() runs \*/  
void loop() {  
LED\_Off(LED\_RGB);LED\_On(LED\_RGB);  
LED\_SetRGBColor(RGB\_COLOR\_RED);  
LED\_Off(LED\_RGB);LED\_On(LED\_RGB);  
LED\_SetRGBColor(RGB\_COLOR\_BLUE);  
LED\_Off(LED\_RGB);LED\_On(LED\_RGB);  
LED\_SetRGBColor(RGB\_COLOR\_RED);  
}

---

<div class="post-metadata">

### Author: ![yianmar](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yianmar/32/2990_2.png) [@yianmar](https://community.particle.io/u/yianmar)
#### Post date: [July 18, 2015, 5:39am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/14 "2015-07-18T05:39:51Z")

</div>

or…seems ignoring make of application contaning the code.  
Code has been build and uploaded…"${OUTPUT\_PATH}"dfu-util -d 2b04:d006 -a 0 -s 0x80a0000:leave -D C:\photon043\_1\firmware-photon\_043\build\target\user-part\platform-6-m\Blank.bin

---

<div class="post-metadata">

### Author: ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)
#### Post date: [July 18, 2015, 5:59am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/15 "2015-07-18T05:59:08Z")

</div>

Hi @yianmar, The unit that isn’t running the code, have you already connected it to the cloud? If not, please install the [latest system firmware](https://github.com/spark/firmware/releases), since that’s required to run applications.

With that installed, you should be up and running 😄

---

<div class="post-metadata">

### Author: ![yianmar](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yianmar/32/2990_2.png) [@yianmar](https://community.particle.io/u/yianmar)
#### Post date: [July 18, 2015, 6:00am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/16 "2015-07-18T06:00:42Z")

</div>

Already done, but not working.

---

<div class="post-metadata">

### Author: ![yianmar](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yianmar/32/2990_2.png) [@yianmar](https://community.particle.io/u/yianmar)
#### Post date: [July 18, 2015, 6:05am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/17 "2015-07-18T06:05:12Z")

</div>

I am Not sure about the uploading procedure  
is it?  
dfu-util -d 2b04:d006 -a 0 -s 0x8020000 -D system-part1-0.4.3-photon.bin  
dfu-util -d 2b04:d006 -a 0 -s 0x8060000:leave -D system-part2-0.4.3-photon.bin  
dfu-util -d 2b04:d006 -a 0 -s 0x80a0000:leave -D Blank.bin

even if it is working at my first PC, I wonder what could interacts beyond this.

---

<div class="post-metadata">

### Author: ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)
#### Post date: [July 18, 2015, 6:08am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/18 "2015-07-18T06:08:59Z")

</div>

Try adding some delay() calls between changing the LED to make the changes visible. (And please consider using the [RGB led library](http://docs.particle.io/photon/firmware/#libraries-rgb).)

Those DFU commands are correct. (You don’t need :leave in the second command, but it will do no harm other than you have to put the photon back in DFU mode to flash the application file.)

---

<div class="post-metadata">

### Author: ![yianmar](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/yianmar/32/2990_2.png) [@yianmar](https://community.particle.io/u/yianmar)
#### Post date: [July 18, 2015, 6:12am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/19 "2015-07-18T06:12:51Z")

</div>

thanks for your time spend to help me.  
At my first Pc I do not have this library, but works fine.  
And something more, I am working locally using Netbeans, how I can use the library?

---

<div class="post-metadata">

### Author: ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)
#### Post date: [July 18, 2015, 6:23am UTC](https://community.particle.io/t/manual-system-mode-not-functioning/10823/20 "2015-07-18T06:23:57Z")

</div>

It’s built into the system firmware. All you need is to add:

```auto
void loop()
{
    RGB.control(true);
    RGB.color(RGB_COLOR_RED);
    delay(500);
    RGB.color(RGB_COLOR_BLUE);
    delay(500);
}

```

Since it’s working on your first device I know this isn’t a fix for your problem, but it’s better to code using the RGB support rather than the low-level LED functions.

[Next page](https://community.particle.io/t/manual-system-mode-not-functioning/10823.md?page=2)
