Skip to content

Commit

Permalink
Use a different port for virtual inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Jimenez Esun committed Apr 19, 2020
1 parent fe6cc52 commit 8b98a92
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ noting are:

## Communication

Music Servers expect to get and receive data via UDP, through the same address
specified for TCP and Loxone Miniserver communication (i.e. in the case of the
first Music Server, that will be `6091`). This data is key to get actions
executed in the interface and to push data back to it.
Music Servers expect to get and receive data via UDP. The addresses are set up
as follow:

- Internal communication to the Music Server (Loxone protocol): uses HTTP (TCP
protocol) to the port indicated (e.g. TCP/6091).

- External communication to the Music Server (e.g. `setTitle`, `setAlbum`,
etc.): uses UDP protocol to the port indicated (e.g. UDP/6091).

- External communication from the Music Server (e.g. `play`, `pause`, etc.):
uses UDP protocol to the port indicated + 1000 (e.g. UDP/7091).

### Data sent to Loxone Miniserver

Expand Down
18 changes: 16 additions & 2 deletions bin/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,27 @@ try {
}

for (let id = 1; id <= +config.data['music-servers']; id++) {
const port = 6090 + id;

const key = (name) => {
return config.data['music-server-' + id + '-' + name];
};

const receivers = key('receivers')
.trim()
.split(/\s*,\s*/g)
.map((receiver) => {
const [gotIp, gotPort] = receiver.split(':');

return {
ip: gotIp,
port: gotPort || port + 1000,
};
});

const server = new MusicServer({
port: 6090 + id,
receivers: key('receivers').split(/\s*,\s*/g),
port,
receivers,
miniserver: !!+key('miniserver'),
zones: +key('zones'),
});
Expand Down
4 changes: 3 additions & 1 deletion bin/service/music-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ module.exports = class MusicServer {
const message = [].concat(id, command, args).join('::');

const receivers = this._config.receivers.concat(
this._config.miniserver ? this._miniserverIp || [] : [],
this._config.miniserver
? [{ip: this._miniserverIp, port: this._config.port + 1000}] || []
: [],
);

console.log('[UDP4] Pushing ' + message);
Expand Down
4 changes: 3 additions & 1 deletion templates/lang/language_en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ HINT_MUSICSERVERPORT_2="listens on Port"
BUTTON_TEST="Test Server"
LABEL_ZONES="Zones:"
HINT_ZONES="Select how many Zones the server should provide."
LABEL_PORT="Port:"
LABEL_PORTS="Ports:"
LABEL_OUTPUTPORT="Virtual output port:"
LABEL_INPUTPORT="Virtual input port:"
HINT_PORT="The Port the server listens on."
LABEL_SENDTOMINISERVER="Send to Miniserver:"
HINT_SENDTOMINISERVER="Send to Miniserver as virtual input/outputs."
Expand Down
15 changes: 9 additions & 6 deletions webfrontend/htmlauth/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@
<?php for ($id = 1; $id <= $cfg['data']['music-servers']; $id++) { ?>
<?php
$vi = $vo = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
$port = 6090 + $id;
$portOut = 6090 + $id;
$portIn = $portOut + 1000;

$vi .= "<VirtualInUdp Title=\"Music server $id\" Comment=\"\" Address=\"\" Port=\"$port\">";
$vo .= "<VirtualOut Title=\"Music server $id\" Comment=\"\" Address=\"/dev/udp/&lt;LOXBERRY_IP&gt;/$port\" CmdInit=\"\" CloseAfterSend=\"false\" CmdSep=\";\">";
$vi .= "<VirtualInUdp Title=\"Music server $id\" Comment=\"\" Address=\"\" Port=\"$portIn\">";
$vo .= "<VirtualOut Title=\"Music server $id\" Comment=\"\" Address=\"/dev/udp/&lt;LOXBERRY_IP&gt;/$portOut\" CmdInit=\"\" CloseAfterSend=\"false\" CmdSep=\";\">";

for ($zone = 1; $zone <= $cfg['data']["music-server-$id-zones"]; $zone++) {
$vi .= "<VirtualInUdpCmd Title=\"Zone $zone, play\" Comment=\"\" Address=\"\" Check=\"$zone::play\" Signed=\"true\" Analog=\"false\" SourceValLow=\"0\" DestValLow=\"0\" SourceValHigh=\"1\" DestValHigh=\"1\" DefVal=\"0\" MinVal=\"-10000\" MaxVal=\"10000\" />";
Expand Down Expand Up @@ -203,7 +204,7 @@
</b>

<a
href="http://<?= LBSystem::get_localip() ?>:<?= 6090 + $id ?>/audio/cfg/all"
href="http://<?= LBSystem::get_localip() ?>:<?= $portOut ?>/audio/cfg/all"
class="ui-btn ui-btn-inline ui-mini"
target="_blank"
>
Expand All @@ -216,14 +217,16 @@ class="ui-btn ui-btn-inline ui-mini"
<div class="lb_flex-container">
<div class="lb_flex-item-label">
<label class="control-label">
<?= $L['SETTINGS.LABEL_PORT'] ?>
<?= $L['SETTINGS.LABEL_PORTS'] ?>
</label>
</div>

<div class="lb_flex-item-spacer"></div>

<div class="lb_flex-item">
<b><?= 6090 + $id ?></b>
<b>
<?= $L['SETTINGS.LABEL_OUTPUTPORT'] ?>: <?= $portOut ?>,
<?= $L['SETTINGS.LABEL_INPUTPORT'] ?>: <?= $portIn ?>
</div>

<div class="lb_flex-item-spacer"></div>
Expand Down

0 comments on commit 8b98a92

Please sign in to comment.