Is there an example using digital inputs from the esp32 ? I do not want to use the aux 1-4.
Thank you fred
Hi @fwarden thanks for the post, and welcome to the community!
I would be happy to help, but will need a bit more info from you. Are you looking for examples of how to read from digital inputs on the ESP32 in firmware and separate from any interaction with the Notecard? As in, is this a general ESP32 question and not a Blues Notecard question? Also, is this from esp_idf or an ESP32 in the Arduino IDE?
Brandon,
I’m using the Adafruit feather blues wireless development kit and trying to using the digital inputs of the feather to send info the notehub. So digital input 26 would tell me that a door is open .
ok, thanks for the context. If I understand what you are doing correctly, something like this should get you what you need. Note that this is a general sketch and you’ll want to adapt it for your use:
#include <Notecard.h>
#include <Wire.h>
#define DOOR 26
#define PRODUCT "<your_product_uid>"
Notecard notecard;
void setup() {
//start serial connection
Serial.begin(9600);
delay(2500);
// Start a Notecard Connection
Wire.begin();
notecard.begin();
pinMode(DOOR, INPUT);
J *req = notecard.newRequest("hub.set");
JAddStringToObject(req, "product", PRODUCT);
notecard.sendRequest(req);
}
void loop() {
int doorVal = digitalRead(DOOR);
if (doorVal == HIGH) {
Serial.println("Door is Open...");
J *req = notecard.newRequest("note.add");
if (req != NULL) {
JAddBoolToObject(req, "sync", true);
J *body = JCreateObject();
if (body != NULL) {
JAddStringToObject(body, "door_state", "open");
JAddItemToObject(req, "body", body);
}
notecard.sendRequest(req);
}
}
}
Brandon,
I will give this a shot tonight it looks like what i am trying to do.
Thank you
Fred
Brandon,
I tried the example and it works great on the serial port but does not show up on notehub.
thank you
Fred
Brandon,
see the attached photo of my screenshot
![Notehub _ Events|353x500](upload://hGMONGilUXwN7xSJRtXkQvGWGLr.jpeg)
Hey @fwarden can you re-upload that screenshot? It’s not showing up. Also, please post your Arduino sketch and I’ll take a look.
Brandon
#include <Notecard.h>
#include <Wire.h>
#define DOOR 26
#define myProductID "com.xxxxxxxxxxxxxxxxxx"
Notecard notecard;
void setup() {
//start serial connection
Serial.begin(9600);
delay(2500);
// Start a Notecard Connection
Wire.begin();
notecard.begin();
pinMode(DOOR, INPUT_PULLUP);
J *req = notecard.newRequest("hub.set");
JAddStringToObject(req, "product", myProductID);
JAddStringToObject(req, "mode", "continuous");
JAddNumberToObject(req, "outbound", 0);
notecard.sendRequest(req);
}
void loop() {
int doorVal = digitalRead(DOOR);
if (doorVal == HIGH) {
// Serial.println("Door is Open...");
J *req = notecard.newRequest("note.add");
if (req != NULL) {
JAddBoolToObject(req, "sync", true);
J *body = JCreateObject();
if (body != NULL) {
JAddStringToObject(body, "door_state", "open");
JAddItemToObject(req, "body", body);
}
notecard.sendRequest(req);
}
}
}
Great thanks. Two things:
- You don’t need to set
outbound
to 0 in thehub.set
as thesync:true
innote.add
will issue an immediate sync, regardless of the outbound rule. - Right after
notecard.begin()
can you add the following?
notecard.setDebugOutputStream(Serial);
This will output all of the Notecard requests to USB serial so you can make sure notes are actually being added to the Notecard. Once you’ve done that, re-run with the serial terminal open and let me know what you see.
Thanks,
Brandon
15:15:39.926 → {“req”:“note.add”,“sync”:true,“body”:{“door_state”:“open”}}
15:15:39.992 → {“err”:“error adding note: body fields not found in template: door_state {template-incompatible}”}
Ah, you’re using Note templates. You’ll need to either define door_state
in your template, or clear it out.
Brandon,
Where did the note template derive from i do not see it in the arduino sketch?
Brandon,
i did a reset on the notecard board and re uploaded my sketch and this is what i get , but it does not show up on notehub.
16:10:37.724 → Door is Open…
16:10:37.757 → Door is Open…
16:10:37.757 → Door is Open…
Brandon,
Using the Example1_notecard basic i get this
{“req”:“note.add”,“sync”:true,“body”:{“temp”:29.625,“voltage”:4.92919,“count”:16}}
{“err”:“error adding note: body fields not found in template: temp voltage count {template-incompatible}”}
is there an issue with my notecard?
@fwarden it’s not an issue with the Notecard per se, but your Notecard is configured to use templates on the default Notefile. Just out of curiosity, did you:
- Get this Notecard from someone else who had used it previously?
- Send API requests to the Notecard from the web serial terminal before starting your ESP32 application?
It’s possible that someone else configured the Notecard to use templates, or you did so previously. Either way, you can clear this by connecting to the Notecard via the Notecard Playground and sending the following request:
{"req":"note.template","file":"data.qo"}
Brandon
I purchased this direct from blues wireless and I may have done it as you stated I will try your answer
Thank you
Fred
Brandon,
I am not doing well with this i sent the {“req”:“note.template”,“file”:“data.qo”} and still no matter my sketch will not send data tot the notehub so i tried the example 5 usingTemplates it begins to send data to the notehub and then stops.
Ok, let’s just get the Notecard in a factory fresh state. Try this and then re-run your sketch.
{"req":"card.restore","delete":true}
Make sure to user serial debugging and if it works, you should see a response from the notecard like
{“total”:1}
After a note.add