Customized firmware but want to use Spark Cloud

Hi,

I’ve built a customized firmware and successfully uploaded to Spark board. But I also want to use Spark’s cloud service. So that I add some code to expose a variable like this from the very beginning of my setup function.

void setup() {

    Spark.variable("quaternionW", &quaternionW, DOUBLE);
    // join I2C bus (I2Cdev library doesn't do this automatically)
    Wire.begin();
 ....
}

After flash my firmware, I am sure my Spark’s WIFI is on and successfully connect to the Spark cloud using two ways, one is by Spark Core -> Build -> status light says “core connected”, the other is to use command line, get online result like this: ( I replaced name and id)

$ spark cloud list
Retrieving cores... (this might take a few seconds)
Found 1 cores 
  NNNNNNNNN (XXXXXXXXXXXX) is online

But when I was trying to retrieve my exposed function to the Spark Cloud, I can’t get my exposed variable

$ spark variable list
polling server to see what cores are online, and what variables are available
Retrieving cores... (this might take a few seconds)
NNNNNNNNN (XXXXXXXXXXXX) has 0 variables  (or is offline) 

Any one has experienced this problem? How can I use my customized firmware but also leverage Spark Core’s cloud service?

Thanks,
Mamahow

Shouldn’t be behaving this way.

What code did you change? If you can give a .bin file, I can flash on my core and see how it behaves. :slight_smile:

1 Like

There is a limit on the length of variable names, but I think “quaternionW” should be safe. Please ping me if things still aren’t working, or I’m happy to help review your code if you like to see what might be interfering.

Thanks!
David

Hey Dave

Please check my project code here, you can find one line from the very beginning of setup()

Spark.variable("quaternionW", &quaternionW, DOUBLE);

I tried one more time to use shorter variable name (quat), but still failed to get remote variable.

$ spark variable list
polling server to see what cores are online, and what variables are available
Retrieving cores... (this might take a few seconds)
HarryCore (48ff70065067555049362287) has 0 variables  (or is offline) 

Please help to check!!

Thanks @Dave!
Mamahow

Hmm, the first thing to jump out at me is that you’re doing a bunch of hard blocking stuff in the setup while waiting on Serial input. Normally we kick the wlan loop during long delays, but if you wanted you could kick that yourself before waiting on serial input:

SPARK_WLAN_Loop();

Since the Spark Cloud maintenance happens in that function, the core needs to run the WLAN_Loop function between calls to your main ‘loop()’, so you probably won’t be able to poll for that variable until your core starts running its main loop.

Can you try kicking the wlan_loop manually, or doing some of your Serial initialization in the loop instead of in setup, or waiting to grab the variable until you’ve entered your loop?

Thanks,
David

Hi @mamahow

Have tried one of the simple demos like the measuring the temperature over a Spark.variable() example? You don’t need a temp sensor–you can fake it out with an incrementing variable or millis();. You could do that with your code too by comment out large chunks and just leaving the double Spark.variable().

I would grab the access token out of the out of the Build web page (on the settings panel you get by clicking the little gear) and use that with curl, a command line tool that does http requests similar to the examples in the doc. For a time, it was easy to have multiple Spark accounts and only the account with the core “claimed” can access it.

1 Like

Hey @Dave & @bko,

Thanks for your quick hint, I found there’s a waiting condition in the driver to stop running main loop. This condition makes my driver’s main loop stop until getting a serial input as a trigger signal. This is really a good practice for registering Spark Cloud function.

Another tricky discovery is sometimes I DFU my firmware for adding more Cloud variable registration, but these cloud variable won’t change after I manually do factory reset. I don’t know exactly, kind of trial and error to make things done, any thoughts?

xoxo,
Mamahow

Hi @mamahow,

Hmm, when you do a factory reset you’ll be overwriting any firmware you’ve loaded on your core with the stock version of Tinker from the factory. So any variables or anything custom you’ve added would get erased. If you’re dfu-ing your firmware locally, don’t do a factory reset to get back, just do a “:leave” like so:

sudo dfu-util -d 1d50:607f -a 0 -i 0 -s 0x08005000:leave -D my_firmware.bin

Thanks!
David