The Node-RED plugin for Signal-K allows you to run automation flows within the navigation system, but by default, context storage is only kept in memory. If we want the data to persist over time, we need to configure contextStorage
to use the file system.
Unlike a standard Node-RED installation, the Signal-K plugin does not read settings.js
, but its configuration is located in the following file:
/home/user/.signalk/plugin-config-data/signalk-node-red.json
(Replace user
with your Linux username)
contextStorage
in the JSON FileTo enable disk storage, open the signalk-node-red.json
file and add the following configuration in the settings
section:
{
"configuration": {
"logging": "trace",
"settings": [
{
"name": "contextStorage",
"value": "{\"default\":{\"module\":\"localfilesystem\",\"config\":{\"dir\":\"/home/user/.signalk/red/context/\", \"flushInterval\":180000}}}"
}
]
},
"enabled": true
}
settings
arrayIn the Signal-K configuration file, the settings
section is an array of objects, where each object defines a specific setting for Node-RED. Each object must have two keys:
name
: The name of the configuration we want to modify (in this case, contextStorage
).value
: The value of the configuration, which should be written as a string. If the value is a JSON object, the quotes ("
) must be escaped so that it is interpreted correctly within the string.Example of a valid structure:
"settings": [
{
"name": "contextStorage",
"value": "{\"default\":{\"module\":\"localfilesystem\",\"config\":{\"dir\":\"/path/to/storage/\", \"flushInterval\":60000}}}"
},
{
"name": "anotherConfig",
"value": "true"
}
]
flushInterval
While flushInterval
can be useful for controlling the frequency of data written to disk, it has been observed that adding this configuration (e.g., with an interval of 3 minutes or 180000 ms) can lead to erratic behavior in the persistence of global or flow variables in Node-RED. In some cases, this may prevent data from being saved correctly or updated properly after a restart.
To avoid these issues, it is recommended to remove or not use the flushInterval
parameter, as shown in the following example:
"settings": [
{
"name": "contextStorage",
"value": "{\"default\":{\"module\":\"localfilesystem\",\"config\":{\"dir\":\"/home/user/.signalk/red/context/\"}}}"
}
]
This way, the data will be stored immediately without waiting for the configured interval.
Once the file has been edited and saved, restart Signal-K to apply the configuration:
sudo systemctl restart signalk
Then, check the logs to confirm there are no errors:
journalctl -u signalk -n 50 --no-pager
If everything is correct, Node-RED will begin storing the context on disk in the specified folder.
To ensure Node-RED is using disk storage:
global.set("test", 123)
)./home/user/.signalk/red/context/
and verify that files are being created.global.get("test")
.Unknown context store 'file' specified. Using default store.
, check that the JSON is properly formatted and that value
is a valid string with escaped quotes ("
).With this configuration, Node-RED's context data within Signal-K will now be persistent, improving system reliability. 🚀