Cloud API incorrectly parsing DOUBLE values

The cloud API doesn’t seem to parse DOUBLE values correctly. Here’s a quick sample app that demonstrates the problem:

double test = 0.5;

void setup() {
    Spark.variable("test", &test, DOUBLE);
}

When I request this variable through the cloud API, the response is:

{
  "cmd": "VarReturn",
  "name": "test",
  "TEMPORARY_allTypes": {
    "string": "\u0000\u0000\u0000\u0000\u0000\u0000�?",
    "uint32": 0,
    "number": 0,
    "double": 2.8363e-319,
    "raw": "\u0000\u0000\u0000\u0000\u0000\u0000�?"
  },
  "result": "\u0000\u0000\u0000\u0000\u0000\u0000�?",
  "coreInfo": {
    "last_app": "foo",
    "last_heard": "2013-12-29T20:00:57.377Z",
    "connected": false,
    "deviceID": "xxx"
  }
}

Not that long ago the double type wouldn’t even compile properly, so there is some progress there :wink:

However last I heard the only Spark.variable type officially supported was INT. I’m sure that’s in process of changing as well!

It seems that strings work pretty well:

char mystr[6];

void setup() {
    Spark.variable(“mystr”, &mystr, STRING);
}

void loop() {
    sprintf(mystr, “%.2f”, 12.34);
}

Yep, I’m using that as a workaround in the meantime, but it would be nice to not waste cpu/memory sprintf()ing the double value into a string buffer every cycle, especially since the cloud API does have a field for double values, it just doesn’t work :stuck_out_tongue:

I believe @Dave and @zachary are working on the parsing issue. I would confirm with them here.

Hey All,

@mohit is right, @zachary and I are working on this and I think the plan is to try and rollout a fix this week. When that happens the “temporary” fields will disappear from the API responses, and the result type should just accurately reflect what you returned. I’m guessing “double” is failing because of encoding differences. I’m guessing the core is probably actually encoding that double as a float, and we’re parsing it temporarily as a double. I’ll add ‘float’ to the list of temporary responses, and that’ll get included in our next code rollout.

Hey all,

Is it possible that there are also problems with the strings at the moment ? I just received my core and i tried a few simple things like accessing the variables … and by using the following code i just tested a few things :

    double temperature = 0.0;
int intTemperature =0;

char mystr[6];
int counter = 0;

void setup()
{
  Spark.variable("temperatures", &intTemperature, INT);
  Spark.variable("temperatureString", &mystr, STRING);
}

void loop()
{
    intTemperature = counter++;
    temperature = counter + (counter / 100);
    sprintf(mystr, "%.2f", temperature);
}

And it gave me the following result on the temperatures :

{
  "cmd": "VarReturn",
  "name": "temperatures",
  "TEMPORARY_allTypes": {
    "string": "\u0000\u0000\u00022",
    "uint32": 562,
    "number": 562,
    "double": null,
    "float": 7.875297369505472e-43,
    "raw": "\u0000\u0000\u00022"
  },
  "result": 562,
  "coreInfo": {
    "last_app": "",
    "last_heard": "2014-01-04T08:09:34.681Z",
    "connected": true,
    "deviceID": "48ff6c065067555028521587"
  }
}

And on the temperateString :

 {
  "cmd": "VarReturn",
  "name": "temperatureString",
  "TEMPORARY_allTypes": {
    "string": " \u0000P\u0000",
    "uint32": 536891392,
    "number": 536891392,
    "double": null,
    "float": 1.0868491504456741e-19,
    "raw": " \u0000P\u0000"
  },
  "result": " \u0000P\u0000",
  "coreInfo": {
    "last_app": "",
    "last_heard": "2014-01-04T08:09:51.312Z",
    "connected": true,
    "deviceID": "48ff6c065067555028521587"
  }
}

Am I missing something ? Or … is there a little bug somewhere ?

Thanks!!

@enicky String variables were working just a couple days ago… and INT should work! I tried your code… all seemed broken at first… no more Kegerator on Friday at Spark!!! xD

But then I remembered something about length of funcKey length max 12 characters…and even though the docs don’t say the same for varKey’s, you’d expect the same.

So I made this one change: Spark.variable("temp2", &mystr, STRING);

…and it works now. Apparently one bad varKey length spoils the broth.

1 Like

@BDub Thanks!! the int’s worked indeed. But i was trying to pass some floats, doubles, … nothing seemed to work …

But I’ll keep that in mind : maxLength = 12 ;o)

Really thanks for the info!!

oh my bad, I was using “temperature” instead of “temperatures” for your INT. So only varKey’s greater than 12 break, not all of them.

would love to hear if you manage to pass a float through the API. I just get garbage as it seems now. INT works nicely though.

found a temporary solution here

Just a heads up that we’re removing TEMPORARY_allTypes today!

1 Like