How to force sync environment variables from the Notecard?

My Configuration: Notecarrier AF, Notecard cellular, ESP32 board. hub.set mode: minimum. Notecard is set to wake up at PollTime interval where PollTime is a device environment variable, ESP32 then collects data and writes to notecard file, then does a hub.sync to send data file to Notehub. This works extremely well.

The Problem: When I change PollTime interval on the Notehub, the new PollTime value does not sync to the Notecard on the next hub.sync. It can take hours or days to sync. I tried setting to inbound to 60 minutes, still didn’t sync the environment variables.

The Questions:

  1. Is there a way to force sync the environment variables from the Notecard?
  2. Does the inbound and outbound intervals do anything when hub.set mode is minimum?
  3. What are the ranges for hub.set inbound and outbound?

Thanks,
Karl

Hi @Karl_iWell,

All environment variables (whether they are project, fleet, or device-level) should sync between the Notecard and Notehub upon every hub.sync request. What level of environment variable are you setting on Notehub? Is it just for that device or does it apply to a fleet or project?

To answer your questions specifically:

  1. As mentioned, a hub.sync from the Notecard will sync environment variables.
  2. The inbound and outbound parameters are ignored when in minimum mode, as syncing must be performed “manually” with hub.sync.
  3. There are no value ranges enforced on the Notecard for inbound or outbound. However, it’s important to remember that using periodic mode with a very low inbound or outbound value is going to bring the modem online and the shut it down, over and over, so in those cases it’s better to use continuous mode.

Rob

Thanks Rob for the info. I confirmed that hub.sync in minimum mode does sync the environment values.

I mentioned a few things so they are documented in this thread.

  1. In minimum mode, after a hub.sync, I was monitoring hub.status until in returned connected:true, then I used card.attn to put the mcu to sleep until the next read cycle. This always send the note file to the notehub, but did not download the updated environment values from the Notehub. I don’t know if this is the intended operation or not, but with the mcu asleep, I can still see the notecard activity on the LED.

  2. I resolved the issue by monitoring hub.sync.status after a hub.sync until I received a completed response.

  3. I noticed that the upload of the note file to the Notehub was a fairly quick operation, but the download of the env file to the Notecard takes much longer and there is a multi-second delay after the env.dbs has a been received and hub.sync.status says completed.

1 Like

Rob,

I’m unable to reliably sync the environment variables from the note hub to the notecard when in minimum mode.

A brief description of my setup:

  • ESP32 Feather board on Notecarrier AF
  • Notecard with “version”: “notecard-3.5.1.15545”
  • ESP32 app wakes up, reads sensor then
    issues {“req”: “hub.sync”}
    then does a {“req”: “hub.status”} until the notecard is connected
    once notecard is connected is in a loop checking

{
“req”: “hub.sync.status”,
“sync”: true
}

“completed” > 30

The ESP32 app then computes the time to the next reading, issues a card.attn and goes to sleep.

This code is working properly and not generating any errors or unexpected responses.

I’m setting a device environment variable called PollTime, which is the interval between readings in minutes.

Here is an example of what I’m seeing:

  1. PollTime was 60 minutes (every hour)
  2. At 5 minutes before the hour, In Notehub I change PollTime to 30 minutes and save it.
  3. At the hour, the ESP32 wakes up, takes the sensor readings, wires them to a Notefile, then syncs and goes to sleep.
  4. The environment variable doesn’t change.
    Here are the note hub events:

From the WebUI, I then do an env.get and also see PollTime has not changed:

> {"req":"env.get"}
{
 "time": 1667943477,
 "body": {
  "_tri_mins": "1440",
  "CL1Enable": "1",
  "CL1Offset": "-310",
  "CL1Slope": "0.0034",
  "CL2Enable": "1",
  "CL2Offset": "-175",
  "CL2Slope": "0.0005",
  "CL3Enable": "0",
  "CL3Offset": "-391",
  "CL3Slope": "0.0025",
  "CL4Enable": "0",
  "CL4Offset": "266",
  "CL4Slope": "0.0034",
  "PollTime": "60"
 }

I’m at a loss. Any ideas? A firmware, a missing JSON command, or a dummy programmer (me!)

Thanks,
Karl

Hi @Karl_iWell,

Sorry to hear this is such a struggle. I’m going to try a full reproduction of this scenario today and will let you know my findings.

Rob

Hi @Karl_iWell,

The good news (bad news?) is that I’m not able to replicate this issue. For reference, here are the steps I tested to mimic what you are effectively doing:

// just making sure i'm starting from scratch
{"req":"card.restore","delete":true}

{"req":"hub.set","product":"<productuid>","mode":"minimum"}

{"req":"hub.sync"}

// ...wait...verify device appears on Notehub...

// set device-level env var on Notehub `polltime` to 60

{"req":"hub.sync"}

// ...wait...

{"req":"env.get","name":"polltime"}

// response:
{"text":"60"}

// ...go back to Notehub, update `polltime` to 30

{"req":"hub.sync"}

// ...wait...

{"req":"env.get","name":"polltime"}
// response:
{"text":"30"}

Two other things I would check on your end:

  1. You shouldn’t need to issue the "sync":true argument on your call to hub.sync.status. If you’re already sending a hub.sync request when the ESP32 wakes, that’ll be all you need.
  2. Can you compare the Uploaded time in Notehub to the "time": 1667943477 response from the Notecard (I don’t know what timezone you are in). Because I think I see the updated “30” in that event…which means that an env.get on the device AFTER that event shows up in Notehub should show you the updated variable.

Rob

Thanks Rob, I tried what you did using the blues WebUI and I got the same results, i.e. the env variables updated.

I’m in the Mountain time zone. I checked the time (1667943477) and it is Tuesday, November 8, 2022 2:37:57 PM GMT-07:00

This is the problem, Notehub says it sent the environment variables at 4:00:37 PM on Tuesday, but the env.get showed the last update at 2:37:57 PM on Tuesday.

I don’t know why when I’m issuing the same JSON commands from the ESP32 Feather that it doesn’t work. I’ll try to capture some serial debug logs from the ESP32. The only differences is the ESP32 uses card.attn command to put the ESP32 to sleep.

Thanks for doing the test.

Karl

Here is the debug log from the ESP32 attempting to sync after changing PollTime from 60 to 30:

16:00:08.978 → {“req”:“hub.sync”}
16:00:09.016 → {}
16:00:09.016 → {“req”:“hub.status”}
16:00:09.084 → {“status”:“idle (since 2022-11-09T22:37:09Z) {disconnected} {idle}”}
16:00:12.078 → {“req”:“hub.status”}
16:00:12.111 → {“status”:“1s starting communications {wait-module} {connecting}”}
16:00:21.267 → {“req”:“hub.status”}
16:00:21.333 → {“status”:“11s starting communications {wait-module} {connecting}”}
16:00:24.330 → {“req”:“hub.status”}
16:00:24.398 → {“status”:“14s starting communications {wait-module} {connecting}”}
16:00:27.377 → {“req”:“hub.status”}
16:00:28.070 → {“status”:“connected (session open) {connected}”}
16:00:31.051 → {“req”:“hub.sync.status”}
16:00:31.126 → {“status”:“get notebox change summary”,“sync”:true,“requested”:22}

16:00:38.792 → {“req”:“hub.sync.status”}
16:00:38.929 → {“status”:“merge notefile: sensor.qos”,“sync”:true,“requested”:29}

16:00:39.937 → {“req”:“hub.sync.status”}
16:00:40.078 → {“status”:“sync: disconnecting partially-opened session so that it may be opened more power-efficiently {sync-disconnecting}”,“time”:1668034839,“completed”:1}

16:00:41.125 → {“req”:“hub.sync.status”}
16:00:41.196 → {“status”:“idle {disconnected}”,“time”:1668034839,“completed”:1}

Here are the events in Notehub:

Here is the WebUI env.get results at about 3:55PM and 4:05 PM:

> {"req":"env.get"}
{
 "time": 1668033377,
 "body": {
  "_tri_mins": "1440",
  "PollTime": "30"
 }
}
> {"req":"env.get"}
{
 "time": 1668033377,
 "body": {
  "_tri_mins": "1440",
  "PollTime": "30"
 }
}

As I read this, Notehub thinks it sent the env file successfully, but the Notecard never received it.

Karl

Very interesting. Can you send me your complete sketch (it should work to DM me here). I’d like to do a full repro with the exact hardware and sketch to see what I might be missing.

Thanks for your patience!
Rob