Hello,
We would like to issue a web.get with some variables as the response has to be specific to a customer name and truck number. Is there a way to do this as is or would I need to initiate an inbound note? I would like to have total transaction time as quick as possible as this is a feature that the user is interacting with in real time and awaiting the response. Thank you!
Sincerely,
Matt
Hey @shonky2, great question. It’s absolutely possible to do this using the name argument in a web.get request. In addition to using this to specify the endpoint relative to your API service, you can add query string arguments in this spot. Example:
{
"req": "web.get",
"route": "truckService",
"name": "/status?cust=<cust_name>&truck=<truck_no>"
}
Hope that helps!
Hey @bsatrom,
Thank you for your help. That is working. How would I view the server reply to the notecard, is it supposed to show up in the blues dev CLI terminal?
Also, are these requests logged in any way like notes are in events?
Thanks again!
Sincerely,
Matt
Hey @shonky2, the Notecard returns an object with the HTTP status code in result
and JSON body
from your endpoint, so you should be able to inspect it programmatically. For example:
{
"result": 200,
"body": { "temp": 75, "humidity": 49}
}
As for getting those in the event log, they aren’t currently but that’s an excellent feature request! We’ve logged it for future implementation.
Hey @bsatrom,
I’m struggling to visualize this and find an example of it in the documentation. Would you be able to help by providing some example code of what it would look like in Arduino IDE, I would really appreciate it. Thank you!
Sincerely,
Matt
Sure, here’s an example of what this could look like when using the note-arduino library:
J *req = notecard.newRequest("web.get");
JAddStringToObject(req, "route", "truckService");
JAddStringToObject(req, "name", "/status?cust=<cust_name>&truck=<truck_no>");
J *rsp = notecard.requestAndResponse(req);
if (rsp != NULL) {
int status_code = JGetNumber(rsp, "result");
notecard.logDebugf("Status: %d\n", status_code);
// Get the note's body
J *body = JGetObject(rsp, "body");
if (body != NULL) {
int temp = JGetNumber(body, "temp");
int humidity = JGetNumber(body, "humidity");
notecard.logDebugf("Temp: %s\nHumidity: %s\n\n", temp, humidity);
}
notecard.deleteResponse(rsp);
Hey @bsatrom,
You folks are awesome! I was able to get that part working now and we are successfully getting responses from our endpoint. We are however running into this error every so often.
{"req":"web.get","route":"getSiteList","name":"/?customer=test&truck=12"}
{"err":"hub request error: invalid character 'h' after object key:value pair"}
Then the only way to resolve it is by rebooting the notecard, sometimes a couple times.
Do you have any idea of what might be causing the error?
Sincerely,
Matt
Hey @shonky2 happy to help! Glad you’ve made progress, but sorry to hear you’ve run into another issue. Can you give me a few additional details so we can look into this?
- What firmware version are you running (You can use
card.wireless
to get the answer)?
- What Notecarrier (AF, AL, etc.) and host MCU are you using?
- Are you connected over Serial or I2C?
- Are you using the
note-arduino
library or accessing the Notecard directly? (I presume the latter given your previous message, but want to make sure)
Hey @bsatrom,
It has actually been working since I posted the last message.
- Did you actually want card.version?
{
"body": {
"org": "Blues Wireless",
"product": "Notecard",
"version": "notecard-1.5.3",
"ver_major": 1,
"ver_minor": 5,
"ver_patch": 3,
"ver_build": 12460,
"built": "Feb 25 2021 09:19:04"
},
"version": "notecard-1.5.3.12460",
"device": "dev:864475044252236",
"name": "Blues Wireless Notecard",
"sku": "NOTE-NBGL500",
"board": "1.11"
}
- I’m using the AF with the ESP32
- I2C
- I have actually seen this error through both interfaces, Arduino library and when accessing the notecard directly.
I wasn’t sure if that invalid character error was something you folks had seen before. I will let you know if I see it again and will try to help pinpoint what changed immediately prior to the error occurring again. Maybe I’ll never see it again!
On the general thread topic, is there any way to pass device UID through headers?
Thank you again!
Sincerely,
Matt
Yes card.version
, sorry about that. Please do let us know if it pops back up.
As for passing headers, there’s currently not a way to do this with web.get
, but you could append it to the query string of your request.