How to use ATTN pin when env variables are updated?

I’ve decided the best way to broadcast data to multiple devices is by setting an application wide environment variable. When I update the env variable how does the notecard get notified of the change ? Do I need to have my host mcu poll the card via env.modified ? If in continuous mode will the changes be automatic and attn will be triggered automatically ? Thanks.

Hi @tavis,

The Notecard will receive updated environment variables whenever it next syncs with Notehub. You likely know already that you can set the inbound and outbound frequencies in the hub.set command, so any type of Notehub sync will also pull in environment variables.

Continuous mode won’t make a difference (aside from making the connection time faster), as there still has to be an explicit sync with Notehub (whether it’s a periodic inbound/outbound sync or an explicit sync on a note.add etc).

I hope that answers your question!

Thanks,
Rob

I’m facing a similar problem - I’d like have environment updates in Notehub propagate asap to Notecard in continuous mode.

I’m using "sync”:true with hub.set, which the documentation says:

sync
boolean (optional)

If in continuous mode, automatically and immediately sync each time an inbound Notefile change is detected on Notehub.

Don’t environment variable changes (posted to _env.dbs) count as inbound changes?

I am pretty certain this used to work, since I was able to make an env change and see the results almost immediately (setting a LED color.)

I’m also using the ATTN pin (configured using the code below), and checking the modified time with env.modified. The ATTN pin status doesn’t change (both the logic level of the pin and the response from a card.attn query.) env.modified doesn’t change unless I issue a hub.sync request.

Do I need to clear/reset the inbound setting perhaps?

Tested on 9.1.1 and 9.3.1 notecard firmware.

Here’s the code to setup the ATTN pin:

J* req = notecard.newRequest("card.attn");
JAddStringToObject(req, "mode", "arm,env,files");
JAddBoolToObject(req, "on", true);
J* files = JAddArrayToObject(req, "files");
JAddItemToArray(files, JCreateString("command.qi"));
notecard.sendRequestWithRetry(req, NOTECARD_REQUEST_TIMEOUT_SECONDS);

pinMode(attn_pin, INPUT);
attachInterrupt(digitalPinToInterrupt(attn_pin), attention_requested, RISING)

Hi @devElert,

It sounds like you’re using "sync":true the right way. I just triple-checked this myself to make sure there wasn’t some crazy regression, but using that arg in my hub.set request does cause environment variable changes to propagate to my device (usually within 5 seconds). The inbound argument doesn’t impact this at all.

Can you send me the output from a card.version request and a hub.get request (just mask out the product uid)?

Thanks,
Rob