Here's a brain teaser for all you geniuses out there... Unfortunately I am not in this group!!
I am on the point of writing a "Parameter Dashboard" for my daft little setup....
My requirements are:
Parameters to be easily accessible through drop down menus and sliders.(Pretty Easy)
They must be written to a file when set/updated.
They must have a "default safe value" should the parameter file not exist.(Not Difficult)
The system must create the parameter file automatically in its "Default Location" wherever that may be and it should be a plain text file for easy external manipulation.
The system should not only read the values on cold startup, but peek at them every so often to look for changes made externally.
Any "New" parameters that come about due to system development should be appended to the setup file.
Now... The million dollar question! How would YOU go about it?
You play. You learn. You watch the thousands of tutorials. You read the forum. You get stuck. You pop back with a specific question. We answer the specific question. You move on. Rinse and repeat.
Clues....
Look into (search) persistent context (for storage)
install dashboard and drop some elements on screen.
Honestly, this is not as difficult as you imagine. Give stuff a go and you'll be flying in no time.
Why didn't you use the section that is already there?
// Context Storage
// The following property can be used to enable context storage. The configuration
// provided here will enable file-based context that flushes to disk every 30 seconds.
// Refer to the documentation for further options: https://nodered.org/docs/api/context/
//
//contextStorage: {
// default: {
// module:"localfilesystem"
// },
//},
The section isnt there... I have an early version settings file carried over from a few years back, but the NR et al has been upgraded to the latest...
I did read it, and its exactly what I am after... Just trying to get the sections "enabled"...
/**
* Originale latest version: https://raw.githubusercontent.com/node-red/node-red/master/settings.js
**/
var fs = require("fs");
var i2c = require("i2c-bus");
var mySettings;
try {
mySettings = require("/home/pi/.node-red/redvars.js");
} catch(err) {
mySettings = {};
}
module.exports = {
uiPort: process.env.PORT || 1880,
mqttReconnectTime: 15000,
serialReconnectTime: 15000,
debugMaxLength: 1000,
flowFile: 'flows.json',
flowFilePretty: true,
httpStatic: '/home/pi/.node-red/public',
functionGlobalContext: {
os:require('os'),
moment:require('moment'),
fs:require('fs'),
i2c:require('i2c-bus'),
mySettings:mySettings
},
logging: {
console: {
level: "info",
metrics: false,
audit: false
}
},
adminAuth:
//<Section Removed>
editorTheme: { projects: { enabled: false }
}
// By default, credentials are encrypted in storage using a generated key. To
// specify your own secret, set the following property.
// If you want to disable encryption of credentials, set this property to false.
// Note: once you set this property, do not change it - doing so will prevent
// node-red from being able to decrypt your existing credentials and they will be
// lost.
//credentialSecret: "a-secret-key",
//https: {
// key: fs.readFileSync('privatekey.pem'),
// cert: fs.readFileSync('certificate.pem')
//},
//requireHttps: true
/* <Remarked this section out to keep going meantime>
//* Context Storage
//* The following property can be used to enable context storage. The configuration
//* provided here will enable file-based context that flushes to disk every 30 seconds.
//* Refer to the documentation for further options: https://nodered.org/docs/api/context/
//*
//* Default is to use 'memory' only.
//* 'memory' and 'localfilesystem' are both synchronous.
//*
contextStorage: {
default: {
module:'memory',
},
file: {
module: 'localfilesystem',
// config: {
// flushInterval: '30', // default is 30s
// },
},
},
*/
}