Ok, just an update on the “created_at” timestamp issue. It turns our that ThinkSpeak ignores the “when” timestamp because it is in epoch format, not the ISO8601 format (e.g. 2014-12-31 23:59:59) that it wants. It then creates its own timestamp which is close to the “routed” timestamp. So, unfortunately we can’t use the automatically generated timestamp. Instead we have to create our own.
In my case:
#include <TimeLib.h>
char timeString[32];
void setup() {
//time from Notecard
{
JTIME ncTime = 0;
J *rsp = notecard.requestAndResponse(notecard.newRequest("card.time"));
if (rsp != NULL) {
ncTime = JGetNumber(rsp, "time");
notecard.deleteResponse(rsp);
}
//print long time
sprintf(timeString, "%02d-%02d-%02d %02d:%02d:%02d", year(ncTime), month(ncTime), day(ncTime), hour(ncTime), minute(ncTime), second(ncTime));
serialDebugOut.println(timeString);
}
// add note
J *req = notecard.newRequest("note.add");
if (req != NULL) {
JAddBoolToObject(req, "sync", true);
J *body = JCreateObject();
if (body != NULL) {
JAddItemToObject(req, "body", body);
JAddNumberToObject(body, "temp", air_temp);
JAddNumberToObject(body, "bat", voltage);
JAddNumberToObject(body, "soc", soc);
JAddNumberToObject(body, "weight", Weight);
JAddNumberToObject(body, "netrawwt", NetRawWt);
JAddStringToObject(body, "key",api_key);
JAddStringToObject(body, "createdTime",timeString);
}
notecard.sendRequest(req); // send and sync
}
}
void loop() {
}
And changed my JSONata to:
{
“created_at”: body.createdTime,
“api_key”: body.key,
“field1”: body.weight,
“field2”: body.temp,
“field3”: body.bat,
“field4”: body.soc,
“field5”: body.netrawwt
}
Hope this helps anyone else stuck on this.