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.
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 )
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;
}
/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
create the “resource” Virtual Resource in the UI with the ADD VIRTUAL RESOURCE… button
push new values in it with retVal[“vr://resource”] = [22];
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?
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)
JavaScript Edge Action writes a Key/Value pair to non-volatile storage
I wait for the Flash Write to complete (X minutes)
I Reboot the Edge Device
Manually check the Key/Value from the Cloud GUI
Edge action successfully reads the value from non-volatile storage
Hi John, Nicolas is in vacation, so I’ll try to answer your question:
For persistence VR, you need to create them using /virtual/config (don’t try to write this entry from an edge action, it’s only used for the configuration)
then if you write any VR, they will be persisted on shutdown (util ulpm, reboot) or by a timer every minutes.
Can you confirm that 3.0.0 doesn’t support non-volatile JavaScript edge action writes.
The reason I ask is that many of your SW colleagues have indicated that non-volatile write from the edge is possible but form my testing I agree with you that it is not.
I confirm you It’s supported.
From your previous try I see you change /virtual/config from the edge action where you are support to change the resource value you should change and not the config