Is there a way to configure the network connection (internet connection) from the spark from within code?
There is a low-level way to add new SSID, password, and security type triples to the TI CC3000 WiFi module. That module can hold up to 7 sets of network info. I don’t know of a way to control exactly which network the CC3000 connects to, but there might be a way. You can also just add networks using the iOS/Android app, Spark CLI, or over USB with a serial terminal emulator.
If you look for
wifi_add_profile_callback in the spark_wlan.cpp source, you can see how it is used.
Was that the kind of configuration that you had in mind? Maybe if you said what you are trying to do, we can make better suggestions.
Actually the system will be placed on different locations. So we want to be able to depending on the location (connected to an ID chip over SPI) that it configures it’s location. We need to like make measurements for 1 week / year. But the device will be located at different customers to check their installation. And we do not want to each time configure the SSID. We want to make a configuration based on the location id found that the system configures itself for the network connection.
This is very possible, but you will have to work a bit. In order to read the ID chip over SPI before the internet and cloud connections start, you will either need to disable those from starting and manage them yourself or put all your ID chip code into the constructor of a global object so it can run before the internet/cloud.
By the time the flow reaches the user setup() function, the internet and cloud connections are already up and running.
Do you have any example on how to disable these internet and cloud connections at startup and enable them at a letter point in time?
This is another area where the Spark team is actively working, so there is a temporary solution for today and a better one coming in the future.
To turn off the internet and cloud, you use include files:
#include "spark_disable_wlan.h" #include "spark_disable_cloud.h"
To use programmatic control over the connection there are methods:
//WiFi WiFi.on(); WiFi.off(); WiFi.status(); //Cloud Spark.connect(); Spark.disconnect(); Spark.connected();
There are some timing issues, you can’t just turn things off without waiting a bit after right now. @peekay123 has been doing a lot work in this area recently and may have some good advice.
[edit: fixed some typos in the code]
If I use the following includes;
I get the following errors:
In file included from …/inc/spark_wiring.h:30:0,
…/…/core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning “Defaulting to Release Build” [-Wcpp]
In file included from /isns-dev-tmp.cpp:1:0:
…/inc/spark_disable_wlan.h: In constructor ‘SparkDisableWlan::SparkDisableWlan()’:
…/inc/spark_disable_wlan.h:34:3: error: ‘SPARK_WLAN_SETUP’ was not declared in this scope
make: *** [/isns-dev-tmp.o] Error 1
So there seem to be problems in the 2 includes, how did you do it not to get these compilation errors?
Are you putting these includes in your main sketch or in an included library? The main sketch is run through the Arduino-like preprocessor but the includes libraries are not. I would certainly recommend that you include the wlan and cloud controls in your main sketch.
If you need to put them in a library (and I don’t know why you would) then you need to also include application.h which brings access to the Spark environment.