Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a device variable only when it changes: Implementing data streams. #7

Open
instanceofMA opened this issue Apr 21, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@instanceofMA
Copy link
Contributor

instanceofMA commented Apr 21, 2020

Currently, device variables are only updated when the device calls set(), which it has to do in loop() to push updates onto Grandeur, which in most of the cases is redundant data. We can add a function to the SDK that watches a variable, and calls the underlying when an update occurs. Like a stream of data. A variable can be piped to its version on Grandeur.

This looks useful to me. Tell me your thoughts about it.

@instanceofMA instanceofMA added the enhancement New feature or request label Apr 21, 2020
@instanceofMA instanceofMA changed the title Setting Summary/Parms only when they change Setting Data only when they change Dec 19, 2020
@instanceofMA instanceofMA changed the title Setting Data only when they change Setting a device variable only when it changes Dec 19, 2020
@instanceofMA
Copy link
Contributor Author

instanceofMA commented Feb 18, 2021

What I mean is something like this:

data.pipe("state", state);

If the user does something like state = 1 (basically just updates the variable), sdk detects the update and if it's different from the previous value, it calls data.set("state", /* New State Value */). And when an update occurs on Grandeur we simply put the new value into the state variable.

My idea is to implement this with references.

map allVariableReferences;
map allVariableValues;

data.pipe(String path, Var& reference) {
  allVariableReferences[path] = reference;
}

project.loop() {
  // Check all references to see if any of their values is updated and call data.set
  // for any variable that is.
  allVariableReferences.forEach([=](String path, Var& reference) {
    if(allVariableValues[path] != reference) {
      data.set(path, reference);
      allVariableValues[path] = reference;
    }
  });
}
/** when update packet is received */
allVariableReferences[payload["event"] + "/" +payload["path"]] = payload["data"];

@instanceofMA instanceofMA changed the title Setting a device variable only when it changes Setting a device variable only when it changes: Implementing data streams. Feb 18, 2021
@instanceofMA instanceofMA added good first issue Good for newcomers and removed good first issue Good for newcomers labels Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants