Skip to content

Update fact during runtime (OPC UA), then trigger rule evaluation #252

@mikakaraila

Description

@mikakaraila

I would like to use OPC UA and as I got new value I am trying to update fact first.

Then I want to run actual rules. So it will be more event based.

For some reason this snippet does not call actual addFact:

monitoredItemGroup.on("changed", (monitoredItem, dataValue, index) => {
          var tag = items[index].nodeId.toString();
          var val = dataValue.value.value.toString();
          if (dataValue.value.dataType === 10) {
              val = dataValue.value.value.toFixed(2).toString();
          }
          // update facts!!
          console.log("update facts:" + tag + " value: " + val);
          engine.addFact('pump-information', function (params, almanac) {
            console.log('Updating live values...' + JSON.stringify(params) + " " + JSON.stringify(almanac));
            return almanac.factValue('nodeId')
              .then((tag) => {
                console.log("Updating facts for nodeId: " + tag + " value:" + val);
                return { value: val }
              })
          });
      });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions