Send readings
Write a value to a datastream's key and it reaches that datastream, its widgets and its automations.
write()
MaxwellTrack.write("temperature", 25.3); // float or double
MaxwellTrack.write("humidity", 60); // any integer type
MaxwellTrack.write("door", "OPEN"); // textThe key must belong to a datastream on the device's template, or the reading is ignored. Keys match exactly, so write them as they are in the template, in lower case. virtualWrite() is the same call under another name.
Numbers are sent as numbers and text as text, with quotes and control characters escaped. Something that only looks like a number but is not a valid one, such as 1.2.3 or 007, is sent as text.
Several values at once
Values that belong together, such as the readings of one sensor, can go in one message. They share one timestamp, so they line up exactly in charts and exports, and they count as one message.
char json[64];
snprintf(json, sizeof(json), "{\"temperature\":%.1f,\"humidity\":%d}", temperature, humidity);
MaxwellTrack.sendBatch(json);Return value
write(), virtualWrite() and sendBatch() return false only when a message is refused: larger than the largest message size, or out of memory. Being offline is not an error; the message is buffered.
How often
Send on a timer with millis(), or when a value changes enough to matter. Every value you send is metered as one reading, and a sensor read on every pass of loop() sends thousands of identical readings an hour.
float lastSent = NAN;
void loop() {
MaxwellTrack.run();
float t = readTemperature();
if (isnan(lastSent) || fabs(t - lastSent) >= 0.5) { // changed by 0.5 or more
if (MaxwellTrack.write(TEMPERATURE, t)) lastSent = t;
}
}Something unclear or out of date on this page? Tell support.
