Notecard stops send data for periods of time: vinbound/voutbound issues?

My device/application (Notecard-F + ESP32 Feather + temp sensors, etc.) is using the Sleepy Sensor application ( Arduino Low power (with deep sleep) sample code for Notecard with the Sleep time, PERIOD_S set to 1800 sec (30 min). The full code of the Sleepy Sensor app is here: https://github.com/blues/notecard-pseudo-sensor/blob/master/examples/SleepySensor/SleepySensor.ino

The application wakes up/ powers on the ESP32 every 30 minutes, then the ESP32 reboots, sends the sensor data and goes back to sleep. The NoteCarrier ATTN pin is connected to NoteCarrier F_EN pin (which is connected to the power EN pin on the ESP32 Feather)

{
// Create a “command” instead of a “request”, because the host
// MCU is going to power down and cannot receive a response.
J * req = NoteNewCommand(“card.attn”);
JAddStringToObject(req, “mode”, “sleep”);
JAddNumberToObject(req, “seconds”, PERIOD_S);
notecard.sendRequest(req);
}

In addition, my Arduino sketch has the following settings from Sleepy Sensor app, which are also mentioned in the Low Power guide (Low Power Design - Blues Developers).

{
“req”: “hub.set”,
“mode”: “periodic”,
“voutbound”: “usb:30;high:60;normal:90;low:120;dead:0”,
“vinbound”: “usb:60;high:120;normal:240;low:480;dead:0”
}

I rebooted the system at 11:32 today. The system rebooted and send the sensor data every 30 minutes as expected until the 2:03pm data was sent. Then it did not send data again until 5:29. It continued to send data at 5:59 and again at 6:29 and now has stopped for over an hour.

I suspect it has something to do with the voutbound and vinbound settings that I don’t really understand. Can someone please explain them?

For my particular application it seems like I don’t care about scheduling outbound sync. It happens every 30 minutes when Notehub send a card.attn signal to the Notecard, the system reboots, sends data and goes back to sleep.

As far as inbound sync, my app doesn’t ever need it, but I gather it is good to have for firmware updates and maybe something else I don’t yet understand.

In the Event Log from that time period, between the successful sensor data upload at 2:03 and the next data upload at 5:29 there are some messages about inbound and outbound sync being due that I don’t understand. Here are some sample entries.

Sun 03:34:55 PM Sun 03:34:57 PM Ann Arbor MI dev:867730051228983 _session.qo {“why”:“periodic inbound sync due”}

Sun 02:29:56 PM Sun 02:29:58 PM Ann Arbor MI dev:867730051228983 _session.qo {“why”:“periodic outbound sync due”}

Here is the full Event Log during that time period from reboot at 11:30am until 7:30pm.


Hi @tonyweil,

When you use the card.attn “sleep” mode, the Notecard doesn’t automatically sync when it wakes up the host. That’s what the voutbound and vinbound arguments are for. Let me explain those a little better.

"voutbound": "usb:30;high:60;normal:90;low:120;dead:0",

This is explicitly telling the Notecard to sync every 30 minutes if powered by USB, every 60 minutes if the voltage measures “high”, every 90 minutes if voltage measures “normal”, every 120 minutes if voltage measures “low”, and never if voltage is “dead”.

How does the Notecard know which voltage thresholds to use? That’s where the card.voltage API comes into play. You need to tell the Notecard what battery tech you are using (see the API reference for details on how to do that). For example:

{
  "req": "card.voltage",
  "mode": "lipo"
}

I hope that helps, but let me know if you have any follow up questions!

Rob

That makes sense. So, if I want to set my card.attn sleep time to 15 minutes, I should set at least the voutbound USB to 15 and probably some of the other battery settings if I think I have enough battery to support that. And I’ll set the card.voltage settings.

What should I set vinbound to? I’m assuming there is no inbound traffic in my application except an occasional firmware update vinbound", “usb:60;high:120;normal:240;low:480;dead:0”)

=====================

Somewhat unrelated , but maybe easy to answer:

In addition to waking up the MCU after 15 minutes, I would also like to connect the USB to AUX1 and have the MCU wake up if AUX1 goes low (USB off). I tried adding some code like this, but it did not work. What am I missing?

I added this code to setup:

{
J *req = NoteNewRequest(“card.aux”);
JAddStringToObject(req, “mode”, “gpio”);
J *pins = JAddArrayToObject(req, “usage”);
JAddItemToArray(pins, JCreateString(“input-pulldown”)); // AUX1
JAddItemToArray(pins, JCreateString(“off”)); // AUX2
JAddItemToArray(pins, JCreateString(“off”)); // AUX3
JAddItemToArray(pins, JCreateString(“off”)); // AUX4
JAddBoolToObject(req, “sync”, true);
NoteRequest(req);
}

And added this to loop:

{
// Create a “command” instead of a “request”, because the host
// MCU is going to power down and cannot receive a response.
J * req = NoteNewCommand(“card.attn”);
JAddStringToObject(req, “mode”, “sleep, auxgpio”); // added auxgpio to sleep
JAddNumberToObject(req, “seconds”, PERIOD_S);
notecard.sendRequest(req);
}

Hi @tonyweil,

It may help to consider the Notecard and your host as operating independently, to a certain extent. When the host wakes, it stores Notes in flash on the Notecard every x minutes, and the Notecard will then dictate when/how that data gets synced to the cloud. So you can gather data every 15 minutes from the host, but you don’t have to immediately sync that data (so your voutbound argument could have higher values if you wanted to save some battery life.

For vinbound, if you aren’t needing to check for inbound data often, you can increase those values up to check every few hours or once a day, whatever works best for your scenario.

Re: your other question. If you’re on Notecard firmware >= 3.5.1 take a look at the new usb argument of card.voltage. It’s a simpler way of monitoring USB power.

Rob

1 Like

I set voutbound to 15 and now I get consistent 15 minute updates.

JAddStringToObject(req, “voutbound”, “usb:15;high:15;normal:15;low:60;dead:0”);
JAddStringToObject(req, “vinbound”, “usb:60;high:60;normal:60;low:480;dead:0”);

=========================================

As far as monitoring quickly for power outages, I tested card.voltage and card.aux gpio mode. What I found was that card.voltage returns a text string and card.aux gpio returns a 0 or 1, which in my case was easier to parse and send to a Ubidots Indicator Widget (on/off).

Question: For my testing below, I just entered the card.voltage and card.aux requests directly into the Notecard through serial. Since I am using an ESP32 MCU, should I and can I just add these requests in the sketch with the other Notecard requests? However the requests are made, I assume they stick in the Notecard through reboots and power down until changed.

card.voltage testing

Setup in Notecard:

{
“req”: “card.voltage”,
“usb”: true,
“alert”: true,
“sync”: true
}

The following is returned in the _health.qo JSON Event:

“body”: {
“text”: “USB power ON {usb-enabled}”
},

card.aux gpio testing

Notecard Setup

{
“req”:“card.aux”,
“mode”:“gpio”,
“usage”:[
“input-pulldown”,
“off”,
“off”,
“off”
],
“sync”:true,
“file”:“power-outage.qo”
}

The following is returned in the power-outage.qo JSON Event:

“body”: {
“power”: true,
“state”: [
{
“low”: true
},
{},
{},
{}
]
},

This was easy to use JSONata to convert to a simple value of 0 or 1 that I wanted to use for an Indicator widget in Ubidots and then have Ubidots send SMS as needed.

// JSONata expression in route to Ubidots:
{
“power-state” : {“value” : (body.state.low ? “0” : “1”), “timestamp”: when * 1000}
}

// Resulting data send to Ubidots in their preferred format
// “value”: “1”, when JSON is “high”: true//
{
“power-state”: {
“value”: “0”,
“timestamp”: 1667261178000
}
}

Yes, many commands sent to the Notecard persist across power cycling and restarts (you would use the card.restore/delete=true API to perform a “factory reset” of the Notecard and reset those settings). So you can either send those manually via the terminal or add them to the setup method in your Arduino sketch.

Rob