Session Close/Open Behavior while Swan sleeps

is there a way to force a new session open after the previous session has been closed? From what I see, if there is a note waiting to be sent to notehub, this will happen automatically. But if my Swan is in sleep mode and the session is closed, it can’t wake up on, say, an environment variable change since there is no connection from notehub to the notecard. I must be missing something.

I have the hub.set duration set to -1 but it still closes the session after some time has elapsed (it seems like every few days).

Thanks,

Joe

Hey @scavoj,

How often your Notecard receives environment variables updates is determined by your inbound interval and not your session duration.

For example, if you want to check for inbound data (including environment variable updates) every hour you can use the following hub.set configuration:

{"req":"hub.set","mode":"periodic","inbound":60}

or

{"req":"hub.set","mode":"continuous","inbound":60}

If you want your Notecard immediately receive environment variable updates you could utilize the hub.set request’s sync argument.

{"req":"hub.set","mode":"continuous","sync":true}

With either of those configuration approaches in place, you can then use the card.attn request to set up your Notecard to wake your Swan when it receives environment variables updates. If you have questions on any of this let me know.

Thanks,

TJ

1 Like

TJ,

Yes, thank you. I have all of these settings in place and the notecard is waking up the Swan when an environment variable is changed. I do have sync set to true and I am getting environment variable updates immediately.

My question is regarding the the session close/open.

If the session is closed and an environment variable is changed, does the notecard receive the new environment variable value? My guess is no, since notehub has no connection to the notecard. Correct? And this would also apply to any inbound notes sent through the api. The notecard won’t get them since the session is closed.

So, how do I open a new session on the notecard without having to send a new note to the notecard (a note waiting to be sent seems to automatically open another session). The Swan is sleeping, so it can’t queue up a note on the notecard.

I guess this is a long winded way of asking if I can tell the notecard to open another session after a previous session has closed. Because even if I set the duration to -1, it still closes the session eventually.

Thanks,

Joe

Hey @scavoj,

When in periodic mode, Notecard starts new sessions whenever it makes a connection to Notehub, either because of its inbound or outbound interval is up, or because of an explicit hub.sync request.

When in continuous mode, Notecard starts new sessions according to the duration argument you set as part of the hub.set request.

You might find part of this video I recorded a few weeks ago helpful as I cover the hub.set request and how all this works in detail (around the 3-minute mark).

I guess this is a long winded way of asking if I can tell the notecard to open another session after a previous session has closed. Because even if I set the duration to -1, it still closes the session eventually.

If you’re in continuous mode you cannot explicitly start a new session. The minimum value for the duration argument is 15, and so the shortest sessions you can have are 15 minutes long.

I’m curious why you’re looking to start a new session though. Sessions only determine how often Notecard sends session-specific data to Notehub in _session.qo Notes. Sessions do not control how often Notecard sends or receives inbound or outbound data.

TJ

Here is what I am seeing:

hub.set inbound set to 1, outbound set to 0 (Software does an explicit sync), mode is continuous, sync is True. Duration set to 1440.

Notecard on battery. Swan sleeping.

1:00 pm - notecard ends session

Notecard changed to USB. Swan wakes on USB. Swan software sends a note to notecard outbound queue.

1:06pm - I change an environment variable

1:09pm - new session open and notehub gets the note and notecard gets the environment variable change.

The problem is that if I change an environment variable, I need to see the change right away. It works fine if I change an environment variable while a session is open. It’s like the session closure is getting in the way of my environment variable change response time.

And it doesn’t matter if I have duration set to the default. It WILL end the session eventually and I have the same problem as setting the duration to 1440.

If I missed a setting that I should have mentioned, please let me know.

Thanks,

Joe

Hey Joe,

You’re correct that you should be seeing environment variable updates relatively immediately with this configuration.

Can you try this:

  1. Connect your Notecard to the In-Browser Terminal.

  2. In the Terminal, ensure you’re connected to Notehub by running a {"req":"hub.status"} command, and making sure you get "connected": true back.

  3. In Notehub, update some environment variable for that device.

  4. In the Terminal, run a {"req":"env.get"} request every few seconds to see how long it takes you to get the update.

I just ran this test on factory-reset Notecard with {"mode": "continuous","sync": true} (and no duration specified), and I’m consistently seeing my environment-variable updates within 2–3 seconds.

TJ

TJ,

Yes, I am seeing environment variable changes immediately when there is an open session. However, when the session gets closed and the swan is sleeping (it can’t add notes), the environment variable changes don’t get through to the notecard to wake the Swan. Seems like a deadlock situation.

Even if I have duration set to the default, the session does get closed eventually. And I have the same problem.

Thanks,

Joe

Hey @scavoj,

Sorry for the late response here. I’ll do some asking around today and see if anyone has any ideas. In the meantime can you let me know what firmware version your Notecard is using?

TJ

Also, when this situation occurs, do you know how long it takes before you start receiving environment variable updates again?

When a session ends Notecard does temporarily drop its connection to Notehub, but it should re-establish it fairly quickly.

TJ

TJ,

Current Notecard version is:

“version”: “notecard-u5-9.2.3”, “ver_major”: 9, “ver_minor”: 2, “ver_patch”: 3, “ver_build”: 17324, “built”: “Aug 11 2025 12:07:58”

The most recent session was opened in about a minute, but there was a geolocate in there that may have effected it. I’m still trying to figure out why it sometimes waits so long to reopen the connection. I’ve seen it go 10+ minutes or even longer. Sometimes I’ll try and test it and my low battery skews the results. That’s why it’s taking me so long. That and working on other issues at the same time.

Thanks,

Joe