Local Context Storage not working

Hey there,

before starting, I'd like to give you some infos about my setup.

Node-RED v4.0.8 running under Docker
mounted local folder to /tmp in container.

I wanted to activated local content storage to be able to store context in local filesystem.
The docs are pretty straight forward.
I added this to my settings.js:

contextStorage: {
    default: {
        module: "memory"
    },
    file: {
        module: "localfilesystem",
        config: {
            dir: "/tmp"
        }
    }
},

So writing seems to work, right?
My problem is, I cannot retrieve the stored files.

const average = msg.payload || 0; 

// Wert im Flow-Kontext aktualisieren
flow.set("LastPvPowerAverage", average);

// Wert im Datei-Kontext speichern
context.set("LastPvPowerAverage", average, "file");

//node.warn(`Gespeichert: ${average}`);
return msg;

With this function, I can store the input of the function node. I verified this on the filesystem.

When trying to retrieve it with this:

const lastAverage = context.get("LastPvPowerAverage", "file"); // Versuche, den Wert aus der Datei zu laden
if (lastAverage !== undefined) {
    node.warn(`Erfolgreich abgerufen: ${lastAverage}`);
    flow.set("LastPvPowerAverage", lastAverage); // In den Flow-Kontext speichern
    node.status({ fill: "blue", shape: "ring", text: `Initialisiert: ${lastAverage}` });
} else {
    node.warn("Kein gespeicherter Wert gefunden!");
    flow.set("LastPvPowerAverage", 0); // Standardwert setzen
    node.status({ fill: "red", shape: "ring", text: "Kein Wert gespeichert" });
}
return null;

I dont get anything at all.

Any help Is appreciated on troubleshooting this situation.

Is that 2nd code segment in the same function node as the 1st? If not, then you should be using flow or global instead of context.

Oh hell, you dont not how much I appreciate your help!
As it were two different function nodes, your solution helped me out!
thanks so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.