Make a Plugin listen to custom Websocket commands

Discuss, contribute and orient Volumio development!

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.

Make a Plugin listen to custom Websocket commands

Postby Projektseminar4 » Sun Dec 22 2019 15:37

Hello everybody,

we are a group of german engineering students using a handful of RPis with Volumio to create a custom Multiroom Speaker Project.
We have been experimenting with writing our own Plugins based on existing ones. For example we have already written a plugin that reacts to gpio edges in a certain way (obviously based on the existing GPIO Control Plugin).

As of now we need the different Plugins (installed on the different RPis) to be able to communicate between one another to transmit their GPIO information. The idea was to use the npm package 'socket.io-client'. While we are able to successfully send commands with socket.emit(...), we have tried a lot of different ways to create a function which is executed when a custom Websocket command is sent from another device.

To make it more clear, here is our code using the example given on the top of the Volumio-doc-page https://volumio.github.io/docs/API/WebSocket_APIs (this code does NOT work for us):
Code: Select all
...
var io = require('socket.io-client');
var socket = io.connect('http://localhost:3000');
...
presenceRegistrator.prototype.onStart = function() {
    var self = this;
    socket.on('bringmepizza', function () {
         self.logger.info("brought pizza");
    });
};
...


So we have tried many different variations. Still, after activating the plugin and sending a Websocket command through a PC Programm called socket-io-tester.exe, nothing shows up on the volumio log.
I would like to add that the socket-io-tester works. For example by sending the command 'volume' and a number, the volume changes.
It may be noted, that the program is connected to 'http://rasppiIP:3000'.
Also other logging around the 'socket.on(..)' command seems to work perfectly.

Any help is very much appreciated, as we have been looking for a solution for about two weeks now and there is very little on that matter to be found on google etc and the volumio doc is not very extensive on that topic.

Best regards!
Random avatar
Projektseminar4
Fresh off the boat
Fresh off the boat
 
Posts: 5
Joined: Wed Nov 20 2019 14:28

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.


Make a Plugin listen to custom Websocket commands

Postby Projektseminar4 » Mon Jan 06 2020 15:00

Hey, we would really appreciate any answer pointing us in the right direction.
Maybe someone has an idea, even if it's not a solution?
Thx!
Random avatar
Projektseminar4
Fresh off the boat
Fresh off the boat
 
Posts: 5
Joined: Wed Nov 20 2019 14:28


Make a Plugin listen to custom Websocket commands

Postby michelangelo » Tue Jan 07 2020 11:56

Hi, sorry for the delayed reply, we were in vacation mode.

Something you can do is use the callMethod socket call. This way you can execute any function in any plugin.

See:
https://github.com/volumio/Volumio2/blo ... dev.js#L11

Let me know !
User avatar
michelangelo
Founder
 
Posts: 4471
Joined: Sun Dec 15 2013 23:18


Make a Plugin listen to custom Websocket commands

Postby Projektseminar4 » Tue Jan 07 2020 22:27

Thank you very much for your answer!

We just tried to push the topic up so it didn't go under after the holidays.

That looks promising, we will try to implement something with it this or the coming week and we will update you with our results.
Thanks again!!
Random avatar
Projektseminar4
Fresh off the boat
Fresh off the boat
 
Posts: 5
Joined: Wed Nov 20 2019 14:28


Make a Plugin listen to custom Websocket commands

Postby Projektseminar4 » Thu Jan 16 2020 13:41

Hi Michelangelo,

we now sucessfully implemented bidirectional communication between to plugins on different RPis!
Since the callMethod socket call only permits transferring data in one direction,e simply implemented it in such a way that the emitters IP-Adress is part of that data. As a consequence we successfully created a bidirectional communication!

Thank you very much again.
Random avatar
Projektseminar4
Fresh off the boat
Fresh off the boat
 
Posts: 5
Joined: Wed Nov 20 2019 14:28


Make a Plugin listen to custom Websocket commands

Postby michelangelo » Thu Jan 16 2020 14:04

Great to hear! Please let us know more about the progress of your project, I am very curious!
User avatar
michelangelo
Founder
 
Posts: 4471
Joined: Sun Dec 15 2013 23:18


Return to Development talks

Who is online

Users browsing this forum: No registered users and 0 guests