[SOLVED]Spark Core Code Execution without the cloud

I’m developing an application that will be launched on a quadcopter platform, and will be out of range of an internet connection.

I’m setup to use the Spark Core to receive an input from the autopilot to trigger an API command to the Sony camera. The only trouble is that I can’t get my code to run. If I’m connected to my wifi with it’s internet connection, then it’ll run my code just fine. Otherwise if I’m connected to the camera’s access point(without internet), it just alternates between flashing green and flashing cyan, seeminly never gettiing to my code. There are flickers of the correct ip output to serial, but most of the time it just says 0.0.0.0.

This page seems to indicate that in automatic mode, the code is run only after a cloud connection is established.
http://support.spark.io/hc/en-us/articles/203013184-Take-control-of-your-connection

Is there a way to run the code after wifi is connected, but without waiting for the nonexistent Spark Cloud connection?

1 Like

Use SYSTEM_MODE(MANUAL); to turn off connection to the :cloud:

This might be useful: http://docs.spark.io/firmware/#advanced-system-modes
As might this: http://docs.spark.io/firmware/#spark-connect
Or this: http://docs.spark.io/firmware/#wifi

Those links are very helpful. I think I’ve implemented the correct calls in my code. But I can no longer seem to get any output on screen from the serial.print commands in my code. Can you take a look and see if I’m blocking it or made a mistake somewhere?

Code is here:

It’s pretty simple, meant to connect to the network and then send an SSDP packet. Although I haven’t gotten it running yet. Thank you!

One thing jumps out at me–you do Udp.begin() before you turn WiFi on. I don’t know what the state of the TI CC3000 is at that time and Udp.begin() tries to create a socket on the TI chip.

Maybe you should try moving that call until after WiFi.connected() it true.

Let’s distill it down to it’s very essence. Take this code:

    SYSTEM_MODE(MANUAL);
    
    void setup() {
      // Print your device IP Address via serial
      Serial.begin(9600);  
      WiFi.on();
    
      // Connects to a network with a specified authentication procedure.
    // Options are WPA2, WPA, or WEP.
      WiFi.clearCredentials();
      WiFi.setCredentials("indiana", "jones", WPA2);
    }
    
    void loop() {
    Spark.process();
    WiFi.connect();
    if (WiFi.hasCredentials() == true)
    {
      Serial.println("Credentials set");
    }
    
    if (WiFi.ready() == true)
      {
      Serial.println("Connected");
      Serial.println(WiFi.localIP());
      }
      else
        {
        Serial.println("Nope");
        }
    }

I can't get it to connect to the WiFi network, and I'm not sure why. It takes the given credentials, but it never seems to get an ip and complete. All I get is the flashing green LED.

EDIT: I found the solution. Each command needs to only be called once. I’ll open a new thread about other issues, but this is the code I got to work
SYSTEM_MODE(MANUAL);

void setup() {
  // Print your device IP Address via serial
  Serial.begin(9600);  
  WiFi.on();

  // Connects to a network with a specified authentication procedure.
// Options are WPA2, WPA, or WEP.
  WiFi.clearCredentials();
//SSID and password
  WiFi.setCredentials("beta", "delta", WPA);
  WiFi.connect();
}

void loop() {
Spark.process();

if (WiFi.hasCredentials() == true)
{
  Serial.println("Credentials set");
}

if (WiFi.ready() == true)
  {
  Serial.println("Connected");
  Serial.println(WiFi.localIP());
  }
  else
    {
    Serial.println("Nope");
    }
}