Amplifier Switch Plugin

@spyking: Thanks for the amazing work :slight_smile: The nomenclature looks good to me, also the UI design. At first I thought about merging the latching with the inverter flag into a drop down, like: operation mode: Normal, inverted, latching. But when looking at your solution I realised that you might also want to have inverted latching, so I think it makes more sense to make it two separate switches. I’m just not sure what you mean with the dual latching? Sending two pulses?
Already saw your PR, will look into it in the next few days and add the german translation :slight_smile:

You can solder together a pretty simple circuit that takes the output of the GPIO of the RPi 3 and drives a 12V output to the Amplifier Jack. I guess a MOSFET should suffice, if you really want to have it decoupled you may want to use an opto-isolator and an additional transistor.

1 Like

I initially wanted to have an “Normally Open, Normally Closed, Latching” drop down - but then I thought it became unnecessarily verbose and meh, so left it at this. When you toggle “Latching” - you get the on pulse and off pulse setting, keeping it simple.

Sooo… what next? Multi GPIOs? I do have a pre, and power amp… :smiley:

Good move :slight_smile:

Is this really a thing with the two GPIOs? I usually prefer hardwired solutions for this kind of thing, whenever it’s easily possible, gives more reliability and doesn’t unnecessarily populate the GPIOs, but I get the impression that I’m the only one with this idea here :smiley:

Btw, I added the PR for the german language strings. Volumio was faster to integrate your PR than I was with adding the strings :smiley:

1 Like

Any news on this? I am looking for a way to turn on/off my tube amps.

Is there a way to get the version of this plugin with relay pulse already now or do I have to wait for the official release in the plugin manager of Volumio?

Well - I pushed the changes to the official repo
But it looks like the plugin manager is not pulling the updated changes? :confused:

Can I install the new version of the plugin if I download the files from GitHub and upload them as zip file on my volumio

Yes - but I am unsure how the pluginmanager gets the node_modules which aren’t included in the git repo.
But you can try with the attached zip :slight_smile:
ampswitch.zip (1.05 MB)

@Fightclub

I just ran into this error while trying to uninstall the plugin - Any ideas?

Mar 01 18:14:21 volumio volumio[23345]: info: Starting Uninstall of plugin miscellanea - ampswitch
Mar 01 18:14:21 volumio volumio[23345]: info: Uninstalling plugin ampswitch
Mar 01 18:14:21 volumio volumio[23345]: info: PLUGIN STOP: ampswitch
Mar 01 18:14:21 volumio volumio[23345]: info: [ASDebug] Port: 14
Mar 01 18:14:21 volumio volumio[23345]: info: [ASDebug] Inverted: false
Mar 01 18:14:21 volumio volumio[23345]: info: [ASDebug] Delay: 720
Mar 01 18:14:21 volumio volumio[23345]: fs.js:610
Mar 01 18:14:21 volumio volumio[23345]: return binding.close(fd);
Mar 01 18:14:21 volumio volumio[23345]: ^
Mar 01 18:14:21 volumio volumio[23345]: Error: EBADF: bad file descriptor, close
Mar 01 18:14:21 volumio volumio[23345]: at Error (native)
Mar 01 18:14:21 volumio volumio[23345]: at Object.fs.closeSync (fs.js:610:18)
Mar 01 18:14:21 volumio volumio[23345]: at Object.<anonymous> (/volumio/node_modules/graceful-fs/graceful-fs.js:51:27)
Mar 01 18:14:21 volumio volumio[23345]: at Object.<anonymous> (/data/plugins/miscellanea/ampswitch/node_modules/graceful-fs/graceful-fs.js:51:27)
Mar 01 18:14:21 volumio volumio[23345]: at Object.closeSync (/data/plugins/music_service/volspotconnect2/node_modules/graceful-fs/graceful-fs.js:51:27)
Mar 01 18:14:21 volumio volumio[23345]: at Gpio.unexport (/data/plugins/miscellanea/ampswitch/node_modules/onoff/onoff.js:354:6)
Mar 01 18:14:21 volumio volumio[23345]: at AmpSwitchController.freeGPIO (/data/plugins/miscellanea/ampswitch/index.js:230:19)
Mar 01 18:14:21 volumio volumio[23345]: at AmpSwitchController.onStop (/data/plugins/miscellanea/ampswitch/index.js:84:10)
Mar 01 18:14:21 volumio volumio[23345]: at PluginManager.stopPlugin (/volumio/app/pluginmanager.js:292:27)
Mar 01 18:14:21 volumio volumio[23345]: at PluginManager.unInstallPlugin (/volumio/app/pluginmanager.js:1149:8)
Mar 01 18:14:21 volumio volumio[23345]: at CoreCommandRouter.unInstallPlugin (/volumio/app/index.js:1343:21)
Mar 01 18:14:21 volumio volumio[23345]: at Socket.<anonymous> (/volumio/app/plugins/user_interface/websocket/index.js:1094:55)
Mar 01 18:14:21 volumio volumio[23345]: at emitTwo (events.js:106:13)
Mar 01 18:14:21 volumio volumio[23345]: at Socket.emit (events.js:191:7)
Mar 01 18:14:21 volumio volumio[23345]: at /volumio/node_modules/socket.io/lib/socket.js:503:12
Mar 01 18:14:21 volumio volumio[23345]: at _combinedTickCallback (internal/process/next_tick.js:73:7)
Mar 01 18:14:21 volumio volumio[23345]: at process._tickCallback (internal/process/next_tick.js:104:9)
Mar 01 18:14:21 volumio volumio-remote-updater[574]: [2018-03-01 18:14:21] [error] handle_read_frame error: websocketpp.transport:7 (End of File)
Mar 01 18:14:21 volumio volumio-remote-updater[574]: [2018-03-01 18:14:21] [disconnect] Disconnect close local:[1006,End of File] remote:[1006]
Mar 01 18:14:21 volumio systemd[1]: volumio.service: main process exited, code=exited, status=1/FAILURE
Mar 01 18:14:21 volumio systemd[1]: Unit volumio.service entered failed state.

Thanks for packing the plugin now it works

@spyking: At the time of writing the initial version of the plugin I ran into this problem once or twice, but, at least to me, it was not reproducible. From what I get from the log it runs into a problem when stopping the plugin and returning its privileges on the GPIO. I’m unsure whether this happens when
a) Plugin is installed and before activation deinstalled again, i.e. it has not been started and thus never claimed the default GPIO
b) a GPIO is being claimed/released that is still allocated by something else
c) some hiccup occurs in the underlying node modules, e.g. onoff

I always wanted to make it a bit more robust using some error handling like try ... catch .... , but I have not run into this problem again and no one else reported it until now, so motivation was rather low :wink:
Maybe you can try to fiddle around with it a bit to verify that one or none of the above points is actually the case, I’m currently pretty busy and just sporadically find the time to look in here.

Dear all,

has anyone used ampswitch on the pine64?
i’m not too much into coding, if you could me direct me in the right direction i would be really happy :slight_smile:

cheers

journalctl says the following:

Mar 31 16:41:37 pandit volumio[3899]: Discovery: Started advertising... pandit - undefined
Mar 31 16:41:37 pandit volumio[3899]: info: CoreCommandRouter::executeOnPlugin: system , registerCallback
Mar 31 16:41:37 pandit volumio[3899]: info: Loading plugin "albumart"...
** Mar 31 16:41:37 pandit volumio[3899]: info: Plugin example_plugin is not enabled
Mar 31 16:41:37 pandit volumio[3899]: info: Loading plugin "updater_comm"...
Mar 31 16:41:37 pandit volumio[3899]: info: Plugin mpdemulation is not enabled
Mar 31 16:41:37 pandit volumio[3899]: info: Loading plugin "rest_api"...
Mar 31 16:41:37 pandit volumio[3899]: info: Loading plugin "websocket"...
Mar 31 16:41:37 pandit volumio[3899]: info: Loading plugin "volspotconnect2"...
Mar 31 16:41:38 pandit volumio[3899]: info: ___________ START PLUGINS ___________
** Mar 31 16:41:38 pandit volumio[3899]: info: PLUGIN START: ampswitch
Mar 31 16:41:38 pandit volumio[3899]: fs.js:641
Mar 31 16:41:38 pandit volumio[3899]: return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
Mar 31 16:41:38 pandit volumio[3899]: ^
Mar 31 16:41:38 pandit volumio[3899]: Error: EACCES: permission denied, open '/sys/class/gpio/export'
Mar 31 16:41:38 pandit volumio[3899]: at Error (native)
Mar 31 16:41:38 pandit volumio[3899]: at Object.fs.openSync (fs.js:641:18)
Mar 31 16:41:38 pandit volumio[3899]: at Object.fs.writeFileSync (fs.js:1347:33)
Mar 31 16:41:38 pandit volumio[3899]: at new Gpio (/data/plugins/miscellanea/ampswitch/node_modules/onoff/onoff.js:84:8)
Mar 31 16:41:38 pandit volumio[3899]: at AmpSwitchController.ampGPIOInit (/data/plugins/miscellanea/ampswitch/index.js:155:21)
Mar 31 16:41:38 pandit volumio[3899]: at AmpSwitchController.onStart (/data/plugins/miscellanea/ampswitch/index.js:60:10)
Mar 31 16:41:38 pandit volumio[3899]: at PluginManager.startPlugin (/volumio/app/pluginmanager.js:256:27)
Mar 31 16:41:38 pandit volumio[3899]: at HashMap.<anonymous> (/volumio/app/pluginmanager.js:332:29)
Mar 31 16:41:38 pandit volumio[3899]: at HashMap.forEach (/volumio/node_modules/hashmap/hashmap.js:157:10)
Mar 31 16:41:38 pandit volumio[3899]: at HashMap.proto.(anonymous function) [as forEach] (/volumio/node_modules/hashmap/hashmap.js:169:7)
Mar 31 16:41:38 pandit systemd[1]: volumio.service: main process exited, code=exited, status=1/FAILURE
Mar 31 16:41:38 pandit systemd[1]: Unit volumio.service entered failed state.

Hi, it would look like the volumio user doesn’t have access to the GPIO group (which might be needed ala Raspberry pi), you might have to manually add it,

groupadd gpio
usermod -a -G gpio volumio

You should then see something like gpio:x:999:volumio from cat /etc/group
But countercheck with someone with a pine64 if this is indeed needed.

EDIT: A quick search throws up forum.pine64.org/showthread.php?tid=2233

@apunktl I ran into similar issues with my Orange PI with the plugin, and found a better way to solve it - Proper udev rules.

su -
groupadd -f --system gpio
usermod -aG gpio volumio
touch /etc/udev/rules.d/99-gpio.rules
echo "SUBSYSTEM==\"gpio\", ACTION==\"add\", RUN=\"/bin/sh -c '
        chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\
        chown -R root:gpio /sys$DEVPATH && chmod -R 770 /sys$DEVPATH\
'\"" > /etc/udev/rules.d/99-gpio.rules

I still don’t completely get how udev sets the $DEVPATH variable, but it works! :slight_smile:

PSA – This plugin will cause issues with the new update (2.411).
OnOff needs a version of epoll that is compiled for node v8.

Find attached a version for it if you don’t fancy compiling it yourself :slight_smile:
ampswitch.zip (1.04 MB)

Please let’s stop distributing plugins zip!!!

Our goal is to make Volumio easy to use, and resistant to failures. This requires effort and cooperation.
I am releasing this new plugin.

An easy way for you would be

clone the whole plugins
cd to your plugin directory
volumio plugin publish

this will send me a PR, after you’ve checked it works :wink:

1 Like

@michelangelo but that will make a version that is not compatible for people who haven’t upgraded yet.
also - my last PR’s were merged - but no package made it to the gh-pages branch! But I see that this the job of volumio plugin publish

Now I published it :wink:
Let me know if we’re all set

Hi
As mention earlier in this thread, how about the implementation of user defined scripts when starting and stopping the playback?

Regards
Martin

Awesome job man. This plugin I almost what I need 

I have two sources, one is TV and the second one pi. Both of them are connected to the same amp.
My problem now is when I stop the music in volumio, my amp turns off and I can watch TV but without sound.

I have played with your plugin and I understand how the plugin works. I would change it to turn on/off the amp with a single switch.
My question is “can somebody give me an example of changing UI”.
I would like to put a button and with that button I would like to open a new page.
In that new page on the top I would put On/Off switch to control the amp.
Here is an example where I would like to put the button for opening the new page.

If that is to complicated, can somebody suggest me something else to try out?

Thank you,
Sarma_men
volumio2.png