I’m using the Feather/Notecarrier-F setup. My Arduino sketch successfully reads a temperature and humidity sensor and sends the data to the notehub. The data sent has many decimal places that I would to truncate to 2 or less before sending to the notehub. I’m wondering if there is a way to do this in “JAddNumberToObject()” commands or some other way.
The Arduino Serial Monitor shows this:
Temp: 78.83 *F
Humidity: 40.19 %
{"req":"note.add","file":"sensors.qo","sync":true,"body":{"temp":78.82719459533692,"humidity":40.19379043579102}}
{"total":1}
Here is my code:
void loop() {
sensors_event_t humidity, temp;
htu.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
usbSerial.print("Temp: ");
usbSerial.print((temp.temperature)*1.8+32);
usbSerial.println(" *F");
usbSerial.print("Humidity: ");
usbSerial.print(humidity.relative_humidity);
usbSerial.println(" %");
J *req = notecard.newRequest("note.add");
if (req != NULL)
{
JAddStringToObject(req, "file", "sensors.qo");
JAddBoolToObject(req, "sync", true);
J *body = JAddObjectToObject(req, "body");
if (body)
{
JAddNumberToObject(body, "temp", temp.temperature*1.8+32);
JAddNumberToObject(body, "humidity", humidity.relative_humidity);
}
notecard.sendRequest(req);
}
delay(1800000); //30 minutes
}