[SOLVED]Plugin dev: cannot figure out how to save my conf

Sorry for reposting but I seem to have inadvertently deleted my original topic. :unamused:

I was having problems saving, loading and modifying my conf and I have finally managed to make it work. So this is mostly to publish my code for a plugin that does nothing and to thank Stefan for the help and guidance.

The problem was mostly down to my ignorance of JavaScript and node.js, and a few typos here and there that made the process fail silently.

I basically had a self.logger.info(""); (should have been this.logger … or declare a self variable) in the getConfigurationFiles function that was failing so the config.json was never loaded so could not be displayed or saved.
I also modified the save function from:

self.config.set('pina', data['pina_setting']);

to

self.config.set('pina', data['pina_setting'][value']);

And I finally changed the getUIConfig fucntion to display the value and the label like so:

uiconf.sections[0].content[0].value.value = self.config.get('pina');
uiconf.sections[0].content[0].value.label = self.config.get('pina').toString();

For me this is solved and I can proceed to make the actual plugin.

However I am still not sure of whether I am handling things correctly as I do not seem to have the same code as other plugins developers.

config.json

{ "enabled": { "type": "boolean", "value": false }, "pina": { "type": "number", "value": 2 }, "pinb": { "type": "number", "value": 3 }, "pinc": { "type": "number", "value": 4 } }
UIConfig.json

{ "page": { "label": "GPIO Rotary Encoder" }, "sections": [ { "id": "re_setup", "element": "section", "label": "Setup your Rotary Encoder PINs", "icon": "fa-plug", "onSave": { "type":"controller", "endpoint":"miscellanea/gpio-rotary", "method":"saveTriggers" }, "saveButton": { "label": "Save", "data": [ "pina_setting", "pinb_setting", "pinc_setting" ] }, "content": [ { "id": "pina_setting", "element": "select", "label": "GPIO for pin A", "value": { "value": 2, "label": "2" }, "options": [ { "value": 2, "label": "2" }, { "value": 3, "label": "3" }, { "value": 4, "label": "4" }, { "value": 5, "label": "5" }, { "value": 6, "label": "6" }, { "value": 7, "label": "7" }, { "value": 8, "label": "8" }, { "value": 9, "label": "9" }, { "value": 10, "label": "10" }, { "value": 11, "label": "11" }, { "value": 12, "label": "12" }, { "value": 13, "label": "13" }, { "value": 14, "label": "14" }, { "value": 15, "label": "15" }, { "value": 16, "label": "16" }, { "value": 17, "label": "17" }, { "value": 18, "label": "18" }, { "value": 19, "label": "19" }, { "value": 20, "label": "20" }, { "value": 21, "label": "21" }, { "value": 22, "label": "22" }, { "value": 23, "label": "23" }, { "value": 24, "label": "24" }, { "value": 25, "label": "25" }, { "value": 26, "label": "26" }, { "value": 27, "label": "27" } ] }, { "id": "pinb_setting", "element": "select", "label": "GPIO for pin B", "value": { "value": 3, "label": "3" }, "options": [ { "value": 2, "label": "2" }, { "value": 3, "label": "3" }, { "value": 4, "label": "4" }, { "value": 5, "label": "5" }, { "value": 6, "label": "6" }, { "value": 7, "label": "7" }, { "value": 8, "label": "8" }, { "value": 9, "label": "9" }, { "value": 10, "label": "10" }, { "value": 11, "label": "11" }, { "value": 12, "label": "12" }, { "value": 13, "label": "13" }, { "value": 14, "label": "14" }, { "value": 15, "label": "15" }, { "value": 16, "label": "16" }, { "value": 17, "label": "17" }, { "value": 18, "label": "18" }, { "value": 19, "label": "19" }, { "value": 20, "label": "20" }, { "value": 21, "label": "21" }, { "value": 22, "label": "22" }, { "value": 23, "label": "23" }, { "value": 24, "label": "24" }, { "value": 25, "label": "25" }, { "value": 26, "label": "26" }, { "value": 27, "label": "27" } ] }, { "id": "pinc_setting", "element": "select", "label": "GPIO for pin C", "value": { "value": 4, "label": "4" }, "options": [ { "value": 2, "label": "2" }, { "value": 3, "label": "3" }, { "value": 4, "label": "4" }, { "value": 5, "label": "5" }, { "value": 6, "label": "6" }, { "value": 7, "label": "7" }, { "value": 8, "label": "8" }, { "value": 9, "label": "9" }, { "value": 10, "label": "10" }, { "value": 11, "label": "11" }, { "value": 12, "label": "12" }, { "value": 13, "label": "13" }, { "value": 14, "label": "14" }, { "value": 15, "label": "15" }, { "value": 16, "label": "16" }, { "value": 17, "label": "17" }, { "value": 18, "label": "18" }, { "value": 19, "label": "19" }, { "value": 20, "label": "20" }, { "value": 21, "label": "21" }, { "value": 22, "label": "22" }, { "value": 23, "label": "23" }, { "value": 24, "label": "24" }, { "value": 25, "label": "25" }, { "value": 26, "label": "26" }, { "value": 27, "label": "27" } ] } ] } ] }
index.js

[code]‘use strict’;

var libQ = require(‘kew’);
//var fs = require(‘fs-extra’);
var Gpio = require(‘onoff’).Gpio;
var io = require(‘socket.io-client’);
var socket = io.connect(‘http://localhost:3000’);

module.exports = GPIORotary;

function GPIORotary(context) {
var self = this;

this.context = context;
this.commandRouter = this.context.coreCommand;
this.logger = this.context.logger;
this.configManager = this.context.configManager;

}
// demarrage de Volumio
GPIORotary.prototype.onVolumioStart = function() {
var self = this;
var configFile=self.commandRouter.pluginManager.getConfigurationFile(self.context,‘config.json’);

self.config = new (require('v-conf'))();
self.logger.info('GPIO-Rotary pre loadFile ' + configFile);
self.config.loadFile(configFile);
self.logger.info('GPIO-Rotary Initialized');
self.config.print();

};

// charge le fichier config.json
// c’est ce bout de bidule qui doit creer /data/configuration/miscellanea/gpio-rotary/config.json
// si il n’existe pas deja
// depuis /Volumio/app/pluginmanager.js
GPIORotary.prototype.getConfigurationFiles = function() {
this.logger.info(‘GPIO-Rotary Got config.json’);
return[‘config.json’];
};

// Demarrage du plugin
GPIORotary.prototype.onStart = function() {
var self = this;
var defer = libQ.defer();

self.logger.info('GPIO-Rotary Started');
defer.resolve();
return defer.promise;

};

// Arret du plugin
GPIORotary.prototype.onStop = function() {
var self = this;
var defer = libQ.defer();

self.logger.info('GPIO-Rotary Stopped');
defer.resolve();
return defer.promise;

};

// on utilise cette fonction lorsque on veut acceder a la configuration du plugin
GPIORotary.prototype.getUIConfig = function() {
var defer = libQ.defer();
var self = this;

var lang_code = 'en';

//self.logger.info('GPIO Rotary - getUIConfig - Start');

self.commandRouter.i18nJson(__dirname+'/i18n/strings_'+lang_code+'.json',
	__dirname+'/i18n/strings_en.json',
	__dirname +'/UIConfig.json')
	.then(function(uiconf)
	{
		uiconf.sections[0].content[0].value.value = self.config.get('pina');
		uiconf.sections[0].content[0].value.label = self.config.get('pina').toString();
		uiconf.sections[0].content[1].value.value = self.config.get('pinb');
		uiconf.sections[0].content[1].value.label = self.config.get('pinb').toString();
		uiconf.sections[0].content[2].value.value = self.config.get('pinc');
		uiconf.sections[0].content[2].value.label = self.config.get('pinc').toString();
		defer.resolve(uiconf);
	})
	.fail(function()
	{
		defer.reject(new Error());
	});
return defer.promise;

};

// cette fonction est appelee depuis la page de conf pour enregistrer les parametres
GPIORotary.prototype.saveTriggers = function(data) {
var defer = libQ.defer();
var self = this;

//self.logger.info('GPIO Rotary: Print conf pre save.')
//self.config.print();

self.logger.info('GPIO Rotary - Saving PINs');
//self.config.set('pina', data.pina.value);
self.config.set('pina', data['pina_setting']['value']);
//self.logger.info('GPIO Rotary - Saved PIN A, value: ' + data.pina_setting.value);
//self.config.set('pinb', data.pinb.value);
self.config.set('pinb', data['pinb_setting']['value']);
//self.config.set('pinc', data.pinc.value);
self.config.set('pinc', data['pinc_setting']['value']);
self.logger.info('GPIO Rotary - PINs saved');

self.commandRouter.pushToastMessage('success',"GPIO Rotary", "Configuration saved");
defer.resolve();

//self.logger.info('GPIO Rotary: Print conf post save.')
//self.config.print();

return defer.promise;

};
[/code]