Local save note and fetch note issue

Description:
I am new and want to try to test the notecard in a local manner. On a brand new Notecard (SKU: NOTE-NBNAW, v9.1.1, Arduino Notecard library v1.7.1), local note retrieval with note.get fails—regardless of file name or options, immediately after adding a note. See code and log below.

Code:

#include <Wire.h>
#include <Notecard.h>

Notecard notecard;

void setup() {
  Serial.begin(115200);
  while (!Serial);

  Wire.begin();
  notecard.begin();
  notecard.setDebugOutputStream(Serial);

  J *req = notecard.newRequest("note.add");
  JAddStringToObject(req, "file", "superlocal.qo"); 
  J *body = JCreateObject();
  JAddNumberToObject(body, "demo", 10.12);
  JAddItemToObject(req, "body", body);
  J *rsp = notecard.requestAndResponse(req);

  if (rsp != NULL) {
    Serial.println("Note added");
  } else {
    Serial.println("Failed to add note");
  }

  req = notecard.newRequest("note.get");
  JAddStringToObject(req, "file", "superlocal.qo");
  rsp = notecard.requestAndResponse(req);

  if (rsp != NULL) {
    char *fullJson = JPrint(rsp);
    Serial.print("Full note.get response: ");
    Serial.println(fullJson);
    JFree(fullJson);

    J *body = JGetObject(rsp, "body");
    if (body != NULL) {
      char *json = JPrint(body);
      Serial.print("Fetched note body: ");
      Serial.println(json);
      JFree(json);

      double value = JGetNumber(body, "demo");
      Serial.print("Fetched value: ");
      Serial.println(value);
    } else {
      Serial.println("No 'body' field found in response.");
    }
}
}

void loop() {}

Output:

[INFO] {"req":"note.add","file":"superlocal.qo","body":{"demo":10.12},"crc":"0000:DCC0FD9A"}
[INFO] {"total":3}
Note added
[INFO] {"req":"note.get","file":"superlocal.qo","crc":"0001:5E0893DE"}
[INFO] {"err":"no notes available {note-noexist}","crc":"0001:2455BF6F"}

Full note.get response: {
    "err": "no notes available {note-noexist}",
    "crc": "0001:2455BF6F"
}
No 'body' field found in response.

Can anybody check what’s wrong with the setup? Thanks.

Hi @Jaden welcome to the forums!

The note.get API works slightly differently to how you are trying to use it. note.get is designed to retrieve inbound Notefiles, delivered via Notehub, to the Notecard. As such the file argument “must either be a DB Notefile or inbound queue file”. You can generate an inbound Notefile from Notehub to test out this feature.

Can you help me out by letting me know what you are hoping to achieve with your code? Do you want to read an inbound Notefile or are you trying to read back a Notefile that you created earlier?

Thanks,
Alex

Hi Alex,

Thanks a lot. It explains the behavior.

I am new and tried to learn some fundamental things. I just wish to test the local write and fetch the data. The env.set() and env.get() worked out. Thanks once again!

Best regards,

Jaden

1 Like