Floats getting mangled by JAddNumberToObject

Here is my note.add request:

J *req1 = notecard.newRequest(“note.add”);
if (req1 != NULL)
JAddBoolToObject(req1, “sync”, true);
J *body = JAddObjectToObject(req1, “body”);
if (body != NULL)
JAddNumberToObject(body, “CardTime”, time);
JAddNumberToObject(body, “CardTemp”, cardTemp);
JAddNumberToObject(body, “voltage”, voltage);
JAddNumberToObject(body, “AT”, data.TemperatureC);
JAddNumberToObject(body, “AH”, data.Humidity);
JAddNumberToObject(body, “probeTip”, probeTemps[0]);
JAddNumberToObject(body, “probe30cm”, probeTemps[2]);
JAddNumberToObject(body, “probe60cm”, probeTemps[3]);
JAddNumberToObject(body, “probe90cm”, probeTemps[5]);
JAddNumberToObject(body, “probe120cm”, probeTemps[4]);
JAddNumberToObject(body, “probe150cm”, probeTemps[1]);

The values for the probe temps are mangled, they should all be around 23 degrees but the output looks like this:


Hi @tjw_scion, good to see you again!

I’m going to try and reproduce your findings. Can you give me some additional context?

  1. How are you defining probeTemps[], I’m assuming it’s float probeTemps[6], but perhaps it’s double or something different yet.
  2. Have you placed a template on the Notefile?


Yeah just standard Arduino floats defined like this

float probeTemps[numberOfDevices];

I’ll plug away at it and see if I can better define the behaviour.

I forgot to ask, what are you using for a host microcontroller, and are you using the latest version of note-arduino?

I used the latest version of note-arduino and an Arduino Mega (AVR), and I was unable to reproduce your results.

    float sensor_readings[5];

    sensor_readings[0] = 1.2345;
    sensor_readings[1] = 12.345;
    sensor_readings[2] = 123.45;
    sensor_readings[3] = 1234.5;
    sensor_readings[4] = 12345;

    if (J *req = notecard.newRequest("note.add"))
        JAddBoolToObject(req, "sync", true);
        if (J *body = JAddObjectToObject(req, "body"))
            JAddNumberToObject(body, "probeTip", sensor_readings[0]);
            JAddNumberToObject(body, "probe30cm", sensor_readings[2]);
            JAddNumberToObject(body, "probe60cm", sensor_readings[3]);
            JAddNumberToObject(body, "probe120cm", sensor_readings[4]);
            JAddNumberToObject(body, "probe150cm", sensor_readings[1]);

On Notehub:

    "body": {
        "probe120cm": 12345,
        "probe150cm": 12.3450002735104,
        "probe30cm": 123.449996914688,
        "probe60cm": 1234.499999997952,
        "probeTip": 1.234500046979072

I also tested it on the Swan (ST), and it worked as well.

Perhaps if you can share which host microcontroller you are using with me, then I can reproduce your error.