Setting up wifi from firmware?

Hello. I am currently working on my finals, which is due next week. For this i am making a project with the core.

What i need is the ability to setup wifi through my firmware, or through serial without putting the device into listening mode.

The reason for this is that i am going to make a casing for the spark, so the MODE and RST buttons will be hidden. With these buttons hidden, i still need to be able to change the wifi settings.

Is that possible?

Have a look at the docs for WiFi.setCredentials() and WiFi.listen().

Ah great! Thanks alot! :smile:

EDIT: I am trying to access the spark through processing, but i can't seem to establish a serial connection. Is there anything i need to do in order for processing to send commands through serial, while the spark is in listening mode?

Also, if i restart the core, and shut off my router, the core just blinks green. Why doesn't it go to listening mode?

THis is my code:

void loop()
{
    if(!Spark.connected()){
    WiFi.listen();
    } else {
        measureToCloud();
    }
}

I’d think in listening mode, your code and so “processing” is not running, so you can’t use it for that.
My suggestion for that would be to go for a bare metal serial terminal (e.g. PuTTY) first, to get the Core doing what you want and once this is done, go back to processing.

For the second question, you might like to have a look at the docs for SYSTEM_MODE(SEMI_AUTOMATIC).
In the default SYSTEM_MODE(AUTOMATIC) your code won’t execute when the connection is lost and once it starts running again you’ll find Spark.connected() to be true ;-).

2 Likes

Thank you so much! I will take a look at it! :slight_smile:

1 Like

Hmm… So i have made it go into listening mode, using system_mode. But when i send the credentials to the spark, it just keeps going into listening mode. Am i supposed to make it connect at some point?

Have a try with this

SYSTEM_MODE(SEMI_AUTOMATIC)

void setup()
{
  pinMode(A0, INPUT_PULLUP);

}

void loop()
{
    if (!digitalRead(A0))
        WiFi.listen();
    else if (!Spark.connected())
    {
        Spark.connect();
        while(!Spark.connected())
            SPARK_WLAN_Loop();
    }
        
    delay(1000);
}

When pulling A0 to LOW, the Core should go into listening mode.
Then let go of A0 and provide your credentials and see what happens.

1 Like

Ah thank you. I made my own version

void loop()

{
if(!Spark.connected()){
        WiFi.listen();
        while(!Spark.connected()){
        delay(5000);                
        }
    } else {
    Serial.println("Spark connected!");
    measureToCloud();
}
} 

Now, how often does the cloud update? when i access the variable through this link:
https://api.spark.io/v1/devices/DEVICEID/VARIABLE/?access_token=ACCESSTOKEN

The variable value updates only like every 30. seconds or so. Is it really that slow?

Also, i cannot express how happy and gratefull i am, that you spend your time helping me. Thank you so much!

EDIT: Indents

EDIT EDIT:
I think i found it. I had two different cloudcvariables, which seemingly slowed the cloud update rate down extensively…

2 Likes

I wouldn’t think it takes that long, unless you don’t service the cloud regularly.

I’ve got a PS/2 mouse project running, where the cumulated mouse travel gets reported every few seconds.

What do you mean by service the cloud? :smile:

In SYSTEM_MODE(AUTOMATIC) & SYSTEM_MODE(SEMI_AUTOMATC) the cloud gets serviced each time you drop out of loop(), or when your cumulated time spent in delay() fullfilles a second, or whenever you call Spark.process()/SPARK_WLAN_Loop().

In SYSTEM_MODE(MANUAL) only when you call Spark.process()/SPARK_WLAN_Loop().

So if you spend a lot of time in loop() and don’t do any of the above, the cloud might get serviced too little.

1 Like

Ah. SPARK_WLAN_Loop() fixed my issue. Thank you very, very much! :slight_smile:

1 Like