Octave 3.0.0 non-volatile data storage for Edge actions

Hi

I’m testing on a mangOH yellow
image

I have edge action which I’d like to be able to maintain a non-volatile value - the current code looks like this

function(event) {
...
    var cycleCount = Datahub.read("virtual/config/cyclecount/value",0);
    var retVal = {};
...
	if(cycleCount === null)				// manage lack of cyclecount config on new systems 
	{
		var cycleCount = {};
		cycleCount.value = 0;
		retVal["vr://config/cyclecount"] = [0];
	}
...
		case "wait":
			if(startSwitch.value == true)
			{
...
				retVal["vr://config/cyclecount"] = [cycleCount.value + 1];
...
			}
}

This code creates an entry in “vr://config/cyclecount”

image

But the cyclecount/value is volatile I was hoping it would be non-volatile
How do I implement a non-volatile value from an edge action?

Thanks

John

Hi John,

If you declare your virtual resource in the config (that is, create it via the ADD VIRTUAL RESOURCE button), then the value will be persisted on the flash.

More details at https://docs.octave.dev/docs/resources#persistence-of-virtual-resources

Regards,
Nicolas

Hi Nicolas

Is it possible to write to a persistent virtual resource from an Edge Function?
virtual/config/
image

My use case is a cycle counter

  • The cycle counter value is incremented by an Edge Action
  • The cycle counter value needs to be persistent (value survives a reboot / power cycle)
  • The cycle counter needs to function even when Octave connectivity is not available

I manually used the ADD VIRTUAL RESOURCE button to add a variable to config (virtual/config
)

I tried a few tests but was unable to make a persistent change to virtual/config
variables from an Edge Action.

The following is one of my attempts

...
var cycleCountp = Datahub.read("/virtual/cyclecountp/value",0);

retVal["vr://cyclecountp"] = [103];
return retVal

What happens

After a reset the config/cyclecountp value is erased

Any ideas?

Thanks

John

Hi John,

I duplicated your config and JS code and was not able to reproduce your issue.

How do you reboot the device ?

The values of the resources are written in the flash memory :

  • every 60 seconds,
  • when the Virtual Resource configuration is updated,
  • when the device goes to low power mode,
  • when device reboot command is triggered: /util/reboot/trigger.

If you hard reboot the device, be sure you wait a least one minute the data gets persisted to the flash.

Regards,
Nicolas

Hi

So it should be possible to write to non-volatile (virtual/config) storage from a JavaScript edge action?

Which firmware version are you using ? (# legato version or )

image

I have created a standalone edge JavaScript event handler that writes ok to volatile values but there is no evidence that it can write to non-volatile storage

Code only

// incoming event is volatile count
// like this {"value":7,"timestamp":315981795.732932}
function(event) {
	var retVal = {};

	// Your code here…
	console.log(event);
	var cycleCountp = Datahub.read("/virtual/resource/value",0);
	
	console.log(cycleCountp);

	var nv = {"resource":{"dt":2, "v":22}};

	nv.resource.v = event.value;

	retVal["vr://config"] = [nv];

	//retVal["vr://config/resource"] = [event.value];
	//retVal["vr://resource"] = [event.value];

	console.log(retVal);

	return retVal;
}

After pressing [ADD] button

Javascript changes the value

JavaScript console.log OP
image

Now the config/config is different from the config - leave it a while before testing again.

After 30 minutes - issued a reboot from the Octave web GUI

After the Edge Action handled an event

Does anyone have working JavaScript that demo’s writing to non-volatile “virtual/config/config” ?

Cheers

John

Hi John,

/virtual/config is an Octave JSON resource that represents the list and the initial values of the Virtual Resources.

From your screenshots, it appears that you unfold this resource, not your “config” Virtual Resource. Please note that the UI allows to display JSON resources by unfolding all its keys and displaying them like if they were actual resources - this is what you are doing here.

All the Virtual Resources, (created from UI with the ADD button or from an Edge Action) are located under /virtual, that is, in you case :
/virtual/config/value

Another remark to make it totally clear : with
retVal["vr://config"] = [nv];
you are not pushing into the Virtual Resources configuration (this is impossible and if it was, then I would strongly discourage doing that) but you are creating a Virtual Resource named “config” which value is {"dt":2, "v":22}.
You should see in the resource tree :

/virtual/config/value {"dt":2, "v":22}

If what you want to do is persist resource named “resource”, then you can

  1. create the “resource” Virtual Resource in the UI with the ADD VIRTUAL RESOURCE… button
  2. push new values in it with retVal[“vr://resource”] = [22];

HTH.

Cheers
Nicolas

Hi Nicolas

Many thanks for trying to help with this.

I understand how standard volatile virtual resources managed by the datahub work (they disappear following a reboot) and also how non-volatile data elements can be pushed from the cloud to the special virtual/config key / value store (They are retained following a reboot).

What I mean by non-volatile storage is that the Key and the last Value written are retained if there is a power cycle or software reboot. In other words - the Key and Value are stored in FLASH and restored by the Octave system following a power cycle.

However my question is about how to write/read to/from non-volatile Key/Values storage from an Edge Action. I have tried every combination I can think of but have not been able to successfully implement an Edge Action non-volatile storage value write.

Could this be an issue with the particular firmware that I am using? image

Could it be that it just is not possible to implement an Edge Action which makes a non-volatile write. To be fair I haven’t yet found any documentation that says it is possible to make a non-volatile write from an Edge Action.

Could you please provide a fully working example for me of Edge Action source code that writes a Key/Value pair to non-volatile storage and also any additional process steps to implement ?

Example test procedure (after implementation)

  1. JavaScript Edge Action writes a Key/Value pair to non-volatile storage
  2. I wait for the Flash Write to complete (X minutes)
  3. I Reboot the Edge Device
  4. Manually check the Key/Value from the Cloud GUI
  5. Edge action successfully reads the value from non-volatile storage

Thanks

John