Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. [Vorlage] Busch Jäger Radio iNet 8216 U

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.5k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    2.0k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    16
    1
    2.7k

[Vorlage] Busch Jäger Radio iNet 8216 U

Geplant Angeheftet Gesperrt Verschoben JavaScript
38 Beiträge 8 Kommentatoren 5.6k Aufrufe 7 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • crunchipC crunchip

    @intruder7 gibt es hier schon was neues zu berichten?

    I Offline
    I Offline
    intruder7
    schrieb am zuletzt editiert von
    #9

    @crunchip Nicht wirklich. Das Skript liefert mir alles was ich benötige. Über einen Adapter hatte ich nachgedacht und versucht auch etwas reinzulesen. Aber ohne Unterstützung bzw einer genauen Step by Step Anleitung werde ich das nicht schaffen. Auch fehlt mir dafür gerade die Zeit.

    Sollten natürlich noch Fehler sein, werde ich diese auch beseitigen.

    Grüße

    crunchipC 1 Antwort Letzte Antwort
    0
    • I intruder7

      @crunchip Nicht wirklich. Das Skript liefert mir alles was ich benötige. Über einen Adapter hatte ich nachgedacht und versucht auch etwas reinzulesen. Aber ohne Unterstützung bzw einer genauen Step by Step Anleitung werde ich das nicht schaffen. Auch fehlt mir dafür gerade die Zeit.

      Sollten natürlich noch Fehler sein, werde ich diese auch beseitigen.

      Grüße

      crunchipC Abwesend
      crunchipC Abwesend
      crunchip
      Forum Testing Most Active
      schrieb am zuletzt editiert von
      #10

      @intruder7 ok, ich hatte selbst bisher auch kaum Zeit, das überhaupt umzusetzen bzw zu integrieren.
      Muss erst mal schaun wie das funktioniert.

      umgestiegen von Proxmox auf Unraid

      1 Antwort Letzte Antwort
      0
      • I intruder7

        Moin Leute,

        ich habe mich die letzten Tage mal rangesetzt und ein Skript zum Steuern des Radios 8216U von Busch-Jäger erstellt.
        Vorraussetzung ist , der Energy Mode vom Radio muss auf Premium stehen damit das Radio jederzeit erreichbar ist.
        Änderungen (Befehle) werden sofort umgesetzt. Genauso werden Eingaben am Radio sofort erfasst da das Skript einen UDP Server erstellt welcher dauerhaft am Port lauscht.

        Im Skript einfach eure IP Adresse des Radios eintragen und es sollte funktionieren.

        Würde dies auch gerne in einen Adapter packen aber dafür benötige ich etwas Support. ;-)

        Also viel Spass beim testen.
        Hoffe es funktioniert bei euch

        var pfad = 'Geraete.BuschJaeger.RadioINet.';
        var pfad2 = 'javascript.0.' + pfad
        
        var UDPListenPort = 4242; //nicht ändern 
        var UDPPort = 4244; //nicht ändern 
        var RadioIPadress = '192.168.100.73' // IP Adresse des Radios
        var HOST = '0.0.0.0'; //nicht ändern 
        
        var logging = false;
        
        
        // ab hier nichts mehr ändern 
        
        var dgram = require('dgram');
        var socket = dgram.createSocket('udp4');
        var server = dgram.createSocket('udp4');
        //var server2 = dgram.createSocket('udp4');
        
        createState(pfad + "Command", '', { type: 'string', name: 'Last command', write: false });
        createState(pfad + "WLAN_STRENGTH", '', { type: 'string', name: 'WLAN strength', write: false, unit: 'dBm' });
        createState(pfad + "NAME", '', { type: 'string', name: 'Name of radio', write: false });
        createState(pfad + "ID", '', { type: 'string', name: 'UDP ID', write: false });
        createState(pfad + "IPADDR", '', { type: 'string', name: 'IP adress', write: false });
        createState(pfad + "IPMASK", '', { type: 'string', name: 'IP Mask', write: false });
        createState(pfad + "IPMODE", '', { type: 'string', name: 'IP  Mode', write: false });
        createState(pfad + "GATEWAY", '', { type: 'string', name: 'Gateway', write: false });
        createState(pfad + "SSID", '', { type: 'string', name: 'SSID', write: false });
        createState(pfad + "MAC_ADRESS", '', { type: 'string', name: 'MAC adress', write: false });
        createState(pfad + "COUNTRY", '', { type: 'string', name: 'Country', write: false });
        createState(pfad + "SERIAL_NR", '', { type: 'string', name: 'Serial Nr', write: false });
        createState(pfad + "SW-VERSION", '', { type: 'string', name: 'Software version', write: false });
        createState(pfad + "WLAN-FW", '', { type: 'string', name: 'WLAN Firmware', write: false });
        
        
        
        createState(pfad + "POWER", '', { type: 'string', name: 'Current state of radio', write: false });
        createState(pfad + "ENERGY_MODE", '', { type: 'string', name: '', write: false });
        createState(pfad + "VOLUME", '', { type: 'number', name: 'VOLUME', write: false });
        createState(pfad + "PLAYING_MODE", '', { type: 'string', name: '', write: false });
        createState(pfad + "PLAYING", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATION_ID_PLAYING", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATION_URL_PLAYING", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATION_PLAYING", '', { type: 'string', name: '', write: false });
        createState(pfad + "TUNEIN_ID", '', { type: 'string', name: '', write: false });
        createState(pfad + "TUNEIN_SNR", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_1_NAME", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_1_URL", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_2_NAME", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_2_URL", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_3_NAME", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_3_URL", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_4_NAME", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_4_URL", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_5_NAME", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_5_URL", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_6_NAME", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_6_URL", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_7_NAME", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_7_URL", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_8_NAME", '', { type: 'string', name: '', write: false });
        createState(pfad + "STATIONS.STATION_8_URL", '', { type: 'string', name: '', write: false });
        
        createState(pfad + "COMMAND.VOLUME_INC", false, { type: 'boolean', name: '', read: false, write: true, role: 'button' });
        createState(pfad + "COMMAND.VOLUME_DEC", false, { type: 'boolean', name: '', read: false, write: true, role: 'button' });
        createState(pfad + "COMMAND.VOLUME_MUTE", false, { type: 'boolean', name: '', read: false, write: true, role: 'switch' });
        createState(pfad + "COMMAND.RADIO_ON", false, { type: 'boolean', name: '', read: false, write: true, role: 'switch' });
        createState(pfad + "COMMAND.PLAY_STATION", 1, { type: 'number', name: 'PLAYING STATION 1-8', read: false, write: true });
        createState(pfad + "COMMAND.VOLUME_SET", 1, { type: 'number', name: 'SET VOLUME 0-31', read: false, write: true });
        //createState(pfad+"COMMAND.VOLUME_DEC",      0,   {type: 'boolean', name: '', read: false, write: true, role:'button'});
        
        server.on('error', (err) => {
            log(`server error:\n${err.stack}`);
            server.close();
        });
        server.on('listening', function () {
            var address = server.address();
            log('UDP Server listening on ' + address.address + ":" + address.port);
        });
        server.bind(UDPListenPort, HOST);
        
        /* server2.on('listening', function () {
            server2.setBroadcast(true);
            server2.setMulticastLoopback(true);
            var address = server2.address();
           log('UDP Server 2 listening on ' + address.address + ":" + address.port);
        });
        server2.bind(PORT2, HOST); */
        
        // Antworten vom Radio auf Abfragen
        
        server.on('message', function (message, remote) {
            if (logging) log('Meldung vom RADIO: ' + message);
            var command = findstr("COMMAND:", message);
            if (command == "GET") {
                if (message.indexOf("INFO_BLOCK") >= 0) {
                    setState(pfad + "Command", findstr("COMMAND:", message));
                    setState(pfad + "WLAN_STRENGTH", findstr("WLAN STRENGTH:", message));
                    setState(pfad + "NAME", findstr("NAME:", message));
                    setState(pfad + "ID", findstr("ID:", message));
                    setState(pfad + "IPADDR", findstr("IPADDR:", message));
                    setState(pfad + "IPMASK", findstr("IPMASK:", message));
                    setState(pfad + "IPMODE", findstr("IPMODE:", message));
                    setState(pfad + "GATEWAY", findstr("GATEWAY:", message));
                    setState(pfad + "SSID", findstr("SSID:", message));
                    setState(pfad + "MAC_ADRESS", findstr("MAC:", message));
                    setState(pfad + "COUNTRY", findstr("COUNTRY:", message));
                    setState(pfad + "SERIAL_NR", findstr("SERNO:", message));
                    setState(pfad + "SW-VERSION", findstr("SW-VERSION:", message));
                    setState(pfad + "WLAN-FW", findstr("WLAN-FW:", message));
                } else if (message.indexOf("VOLUME") >= 0) {
                    setState(pfad + "Command", findstr("COMMAND:", message));
                    setState(pfad + "ID", findstr("ID:", message));
                    setState(pfad + "VOLUME", parseInt(findstr("VOLUME_SET:", message)));
                    if (parseInt(findstr("VOLUME_SET:", message)) >= 0 && parseInt(findstr("VOLUME_SET:", message)) <= 31 && message.indexOf("RESPONSE:ACK") >= 0) {
                        setState(pfad + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true);
                    }
                } else if (message.indexOf("POWER_STATUS") >= 0) {
                    setState(pfad + "Command", findstr("COMMAND:", message));
                    setState(pfad + "ID", findstr("ID:", message));
                    setState(pfad + "POWER", findstr("POWER:", message));
                    if (findstr("POWER:", message) == "ON") {
                        setState(pfad + "COMMAND.RADIO_ON", true, true)
                    } else if (findstr("POWER:", message) == "OFF") {
                        setState(pfad + "COMMAND.RADIO_ON", false, true)
                    };
                    setState(pfad + "ENERGY_MODE", findstr("ENERGY_MODE:", message));
                } else if (message.indexOf("TUNEIN_PARTNER_ID") >= 0) {
                    setState(pfad + "Command", findstr("COMMAND:", message));
                    setState(pfad + "ID", findstr("ID:", message));
                    setState(pfad + "TUNEIN_ID", findstr("PARTNERID:", message));
                    setState(pfad + "TUNEIN_SNR", findstr("SERNO:", message));
                } else if (message.indexOf("ALL_STATION_INFO") >= 0) {
                    setState(pfad + "Command", findstr("COMMAND:", message));
                    setState(pfad + "ID", findstr("ID:", message));
                    setState(pfad + "STATIONS.STATION_1_NAME", findstr("1\r\nNAME:", message));
                    setState(pfad + "STATIONS.STATION_1_URL", findstr(findstr("1\r\nNAME:", message) + '\r\nURL:', message));
                    setState(pfad + "STATIONS.STATION_2_NAME", findstr("2\r\nNAME:", message));
                    setState(pfad + "STATIONS.STATION_2_URL", findstr(findstr("2\r\nNAME:", message) + '\r\nURL:', message));
                    setState(pfad + "STATIONS.STATION_3_NAME", findstr("3\r\nNAME:", message));
                    setState(pfad + "STATIONS.STATION_3_URL", findstr(findstr("3\r\nNAME:", message) + '\r\nURL:', message));
                    setState(pfad + "STATIONS.STATION_4_NAME", findstr("4\r\nNAME:", message));
                    setState(pfad + "STATIONS.STATION_4_URL", findstr(findstr("4\r\nNAME:", message) + '\r\nURL:', message));
                    setState(pfad + "STATIONS.STATION_5_NAME", findstr("5\r\nNAME:", message));
                    setState(pfad + "STATIONS.STATION_5_URL", findstr(findstr("5\r\nNAME:", message) + '\r\nURL:', message));
                    setState(pfad + "STATIONS.STATION_6_NAME", findstr("6\r\nNAME:", message));
                    setState(pfad + "STATIONS.STATION_6_URL", findstr(findstr("6\r\nNAME:", message) + '\r\nURL:', message));
                    setState(pfad + "STATIONS.STATION_7_NAME", findstr("7\r\nNAME:", message));
                    setState(pfad + "STATIONS.STATION_7_URL", findstr(findstr("7\r\nNAME:", message) + '\r\nURL:', message));
                    setState(pfad + "STATIONS.STATION_8_NAME", findstr("8\r\nNAME:", message));
                    setState(pfad + "STATIONS.STATION_8_URL", findstr(findstr("8\r\nNAME:", message) + '\r\nURL:', message));
                } else if (message.indexOf("PLAYING_MODE") >= 0) {
                    setState(pfad + "Command", findstr("COMMAND:", message));
                    setState(pfad + "ID", findstr("ID:", message));
                    setState(pfad + "PLAYING_MODE", findstr("MODE:", message));
                    setState(pfad + "PLAYING", findstr("PLAYING:", message));
                    setState(pfad + "STATION_ID_PLAYING", findstr("N\r\nID:", message));
                    setState(pfad + "STATION_URL_PLAYING", findstr("URL:", message));
                    setState(pfad + "STATION_PLAYING", findstr("NAME:", message));
                };
            } else if (command == "NOTIFICATION") {
                var event = findstr("EVENT:", message);
                setState(pfad + "Command", findstr("COMMAND:", message));
                setState(pfad + "IPADDR", findstr("IP:", message));
                setState(pfad + "NAME", findstr("NAME:", message));
                if (logging) log("Event = '" + event + "'");
                if (event == 'POWER_OFF' || event == 'POWER_ON') {
                    sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                };
                if (event == "VOLUME_CHANGED") {
                    sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                };
                if (event == 'STATION_CHANGED') {
                };
            } else if (command == "SET") {
                if (message.indexOf("VOLUME_ABSOLUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                    setState(pfad + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                    setState(pfad + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                }
                if (message.indexOf("VOLUME_DEC") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                    setState(pfad + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                    setState(pfad + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                }
                if (message.indexOf("VOLUME_INC") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                    setState(pfad + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                    setState(pfad + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                }
                if (message.indexOf("VOLUME_UNMUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                    setState(pfad + "COMMAND.VOLUME_MUTE", false, true)
                }
                if (message.indexOf("VOLUME_MUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                    setState(pfad + "COMMAND.VOLUME_MUTE", true, true)
                }
                if (message.indexOf("RADIO_OFF") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                    setState(pfad + "COMMAND.RADIO_ON", false, true);
                    setState(pfad + "POWER", "OFF");
                }
                if (message.indexOf("RADIO_ON") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                    setState(pfad + "COMMAND.RADIO_ON", true, true);
                    setState(pfad + "POWER", "ON");
                }
            } else if (command == "PLAY") {
                if (message.indexOf("STATION") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                    setState(pfad + "COMMAND.PLAY_STATION", parseInt(findstr("STATION:", message)), true);
                    setState(pfad + "STATION_ID_PLAYING", parseInt(findstr("STATION:", message)), true);
                    setState(pfad + "STATION_PLAYING", findstr("PLAYING:", message), true);
                }
            } else {
        
                if (logging) log('unexpected message: ' + message);
        
            }
        });
        
        // starten der Abfragen nach Empfang von Broadcasts
        /* var timer = null;
        
        server2.on('message', function (message, remote) {
            if (timer) clearTimeout(timer);
            if (logging) log('Broadcast vom Radio: ' + message);
            if (logging) log(JSON.stringify(message));
            //var obj = JSON.parse('{'+message+'}');
            sendcmd(buf2);
            timer = setTimeout(function () {
                sendcmd(buf3);
            }, 1000);
        }); */
        function findstr(name, str) {
            var suchstring = String(name);
            var teststring = String(str);
            var pos = parseInt(teststring.indexOf(suchstring) + suchstring.length);
            var zaehler = parseInt(pos) + 1;
            //log("String: " + suchstring + "befindet sich an " + pos + " Stelle")
            do {
                var Zeichen = String(teststring).charCodeAt(zaehler);
                //log ("Zeichen: " + Zeichen + " Zähler: " + (zaehler - pos));
                zaehler = zaehler + 1;
            } while (Zeichen != 13 && zaehler - pos <= 100);
        
        
            //log("Start: " + pos + "Ende: " + zaehler);
            var ergebnis = String(str).substring(pos, zaehler - 1);
            if (teststring.indexOf(suchstring) == -1) {
                ergebnis = ""
            };
        
            //log("Objekt: " + name + " Wert: '" + ergebnis + "'");
            return ergebnis
        }
        
        
        function sendcmd(cmd) {
            socket.send(cmd, 0, cmd.length, UDPPort, RadioIPadress, function (err, result) {
                if (err) log('Fehler Senden ' + cmd, 'error');
                else {
                    if (logging) log('Kommando gesendet: ' + cmd);
                }
            });
        }
        //einmalige Ausführung beim  Starten des Skriptes
        sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
        sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
        sendcmd('COMMAND:GET\r\nINFO_BLOCK\r\nID:ioBroker\r\n\r\n');
        sendcmd('COMMAND:GET\r\nPLAYING_MODE\r\nID:ioBroker\r\n\r\n');
        sendcmd('COMMAND:GET\r\nALL_STATION_INFO\r\nID:ioBroker\r\n\r\n');
        
        var timer1 = null;
        var timer2 = null;
        var timer3 = null;
        var timer4 = null;
        schedule('*/1 * * * *', function () {  // jede Minute die wichtigsten Infos aktualisieren
        
            if (timer1) clearTimeout(timer1);
            timer1 = setTimeout(function () {
                sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
            }, 1000);
            if (timer2) clearTimeout(timer2);
            timer2 = setTimeout(function () {
                sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
            }, 2000);
            if (timer3) clearTimeout(timer3);
            timer3 = setTimeout(function () {
                sendcmd('COMMAND:GET\r\nINFO_BLOCK\r\nID:ioBroker\r\n\r\n');
            }, 3000);
            if (timer4) clearTimeout(timer4);
            timer4 = setTimeout(function () {
                sendcmd('COMMAND:GET\r\nPLAYING_MODE\r\nID:ioBroker\r\n\r\n');
            }, 4000);
        });
        
        schedule('*/30 * * * *', function () {  // alle 30 Minuten die Stationsliste aktualisieren
            sendcmd('COMMAND:GET\r\nALL_STATION_INFO\r\nID:ioBroker\r\n\r\n');
        });
        // Reaktionen auf Befehle
        on({ id: pfad2 + "COMMAND.VOLUME_INC", val: true }, function (obj) {
            if (logging) log('COMMAND.VOLUME_INC');
            sendcmd('COMMAND:SET\r\nVOLUME_INC\r\nID:ioBroker\r\n\r\n');
            sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
        });
        on({ id: pfad2 + "COMMAND.VOLUME_DEC", val: true }, function (obj) {
            if (logging) log('COMMAND.VOLUME_DEC');
            sendcmd('COMMAND:SET\r\nVOLUME_DEC\r\nID:ioBroker\r\n\r\n');
            sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
        });
        on({ id: pfad2 + "COMMAND.VOLUME_MUTE", change: "ne" }, function (obj) {
            if (logging) log('COMMAND.VOLUME_MUTE');
            if (obj.state.val === true) {
                sendcmd('COMMAND:SET\r\nVOLUME_MUTE\r\nID:ioBroker\r\n\r\n');
            }
            if (obj.state.val === false) {
                sendcmd('COMMAND:SET\r\nVOLUME_UNMUTE\r\nID:ioBroker\r\n\r\n');
            }
            sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
        });
        on({ id: pfad2 + "COMMAND.RADIO_ON", change: "ne", ack: false }, function (obj) {
            if (logging) log('COMMAND.RADIO_ON');
            if (obj.state.val === true) {
                sendcmd('COMMAND:SET\r\nRADIO_ON\r\nID:ioBroker\r\n\r\n');
            }
            if (obj.state.val === false) {
                sendcmd('COMMAND:SET\r\nRADIO_OFF\r\nID:ioBroker\r\n\r\n');
            }
            sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
        });
        on({ id: pfad2 + "COMMAND.PLAY_STATION", change: "ne", ack: false }, function (obj) {
            if (logging) log('COMMAND.PLAY_STATION');
            if (obj.state.val <= 8 && obj.state.val > 0) {
                sendcmd('COMMAND:PLAY\r\nSTATION:' + obj.state.val + '\r\nID:ioBroker\r\n\r\n');
            }
        });
        on({ id: pfad2 + "COMMAND.VOLUME_SET", change: "ne", ack: false }, function (obj) {
            if (logging) log('COMMAND.PLAY_STATION');
            if (obj.state.val <= 31 && obj.state.val >= 0) {
                sendcmd('COMMAND:SET\r\nVOLUME_ABSOLUTE:' + obj.state.val + '\r\nID:ioBroker\r\n\r\n');
            }
        }); 
        
        E Offline
        E Offline
        Eaterhnk
        schrieb am zuletzt editiert von
        #11

        @intruder7

        Hey das Skript läuft einwandfrei für ein Radio, habe allerdings 2 davon und möchte gerne beide bedienen. Wenn ich allerdings in der erste Zeile den Pfad ändere und auch die IP ändere, das ganze in ein weiteres Skript kopiere, bekomme ich garkeine Daten. Bin leider in Java nicht so zuhause... was mache ich falsch bzw. muss ich noch ändern um 2 Radios steuern zu können?

        VG

        I 1 Antwort Letzte Antwort
        0
        • E Eaterhnk

          @intruder7

          Hey das Skript läuft einwandfrei für ein Radio, habe allerdings 2 davon und möchte gerne beide bedienen. Wenn ich allerdings in der erste Zeile den Pfad ändere und auch die IP ändere, das ganze in ein weiteres Skript kopiere, bekomme ich garkeine Daten. Bin leider in Java nicht so zuhause... was mache ich falsch bzw. muss ich noch ändern um 2 Radios steuern zu können?

          VG

          I Offline
          I Offline
          intruder7
          schrieb am zuletzt editiert von
          #12

          @Eaterhnk mein erster Gedanke wäre auch gewesen das Skript zu kopieren und für das zweite Radio einen eigenen Pfad anzulegen und die IP zu ändern. wobei die IP nur zum senden von Befehlen nötig ist. die Antworten kommen von beiden Radios über UDP rein. Ich kann es leider nicht testen weil ich keine zwei Radios habe

          E 1 Antwort Letzte Antwort
          0
          • I intruder7

            @Eaterhnk mein erster Gedanke wäre auch gewesen das Skript zu kopieren und für das zweite Radio einen eigenen Pfad anzulegen und die IP zu ändern. wobei die IP nur zum senden von Befehlen nötig ist. die Antworten kommen von beiden Radios über UDP rein. Ich kann es leider nicht testen weil ich keine zwei Radios habe

            E Offline
            E Offline
            Eaterhnk
            schrieb am zuletzt editiert von
            #13

            @intruder7
            ok. schade, hast du denn vielleicht noch einen anderen Ansatz für mich was ich vielleicht mal testen könnte?

            I 1 Antwort Letzte Antwort
            0
            • E Eaterhnk

              @intruder7
              ok. schade, hast du denn vielleicht noch einen anderen Ansatz für mich was ich vielleicht mal testen könnte?

              I Offline
              I Offline
              intruder7
              schrieb am zuletzt editiert von
              #14

              @Eaterhnk einen Ansatz kann ich dir leider nicht liefern. Ich würde versuchen auf dem try and error Weg eine Lösung zu erreichen. Mir die ganzen UDP Messages anschauen u.s.w. Ich denke schwer ist es nicht aber ohne zweites Radio nicht möglich. Sorry

              1 Antwort Letzte Antwort
              0
              • N Offline
                N Offline
                Nahasapee
                schrieb am zuletzt editiert von
                #15

                Hi,
                ich steck zwar nicht wirklich drin,
                da ich nicht so nen Radio habe bzw. udp Geschichte nicht in nodejs programmiert habe.

                Allerdings glaube ich, wenn ihr das script einfach nur in ne neue Datei kopiert und die IpAdresse des Clients ändert würden zwei Server versuchen auf den gleichen Port zu lauschen und das geht glaube ich nicht,
                ich steck da allerdings nicht drin, wenns einer genauer weiß berichtigt mich bitte.
                Ich glaube eher, dass ihr das Scrpt in Zeile 93 bzw 217 erweitern müsst
                auf die unterschiedlichen Clients.
                entweder steht in der message || remote welches Radio gerade sendet.
                gebt doch mal das log von der message bzw remote variable aus und postet es.
                Viele Grüße

                E 1 Antwort Letzte Antwort
                0
                • N Nahasapee

                  Hi,
                  ich steck zwar nicht wirklich drin,
                  da ich nicht so nen Radio habe bzw. udp Geschichte nicht in nodejs programmiert habe.

                  Allerdings glaube ich, wenn ihr das script einfach nur in ne neue Datei kopiert und die IpAdresse des Clients ändert würden zwei Server versuchen auf den gleichen Port zu lauschen und das geht glaube ich nicht,
                  ich steck da allerdings nicht drin, wenns einer genauer weiß berichtigt mich bitte.
                  Ich glaube eher, dass ihr das Scrpt in Zeile 93 bzw 217 erweitern müsst
                  auf die unterschiedlichen Clients.
                  entweder steht in der message || remote welches Radio gerade sendet.
                  gebt doch mal das log von der message bzw remote variable aus und postet es.
                  Viele Grüße

                  E Offline
                  E Offline
                  Eaterhnk
                  schrieb am zuletzt editiert von
                  #16

                  @Nahasapee
                  Guten Abend,
                  das ist ein Auszug aus dem LOG von gestern: hier wurde das Skript kopiert und nur der Pfad und die IP geändert. Mit den Änderungen in den von dir benannten Zeilen komm ich nicht weiter:

                  2019-12-09 19:52:00.068 - warn: javascript.0 (29194) Wrong type of javascript.0.Geraete.BuschJaeger.RadioINet.STATION_ID_PLAYING: "number". Please fix, while deprecated and will not work in next versions.
                  2019-12-09 19:52:00.069 - warn: javascript.0 (29194) at setState (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1258:20)
                  2019-12-09 19:52:00.069 - warn: javascript.0 (29194) at Socket. (script.js.Skrypte_in_Betrieb.Radio_EG:204:13)
                  2019-12-09 19:52:00.070 - warn: javascript.0 (29194) at Socket.emit (events.js:198:13)
                  2019-12-09 19:52:00.070 - warn: javascript.0 (29194) at UDP.onMessage (dgram.js:628:8)

                  1 Antwort Letzte Antwort
                  0
                  • N Offline
                    N Offline
                    Nahasapee
                    schrieb am zuletzt editiert von
                    #17

                    Sorry,
                    du hast mich jetzt falsch verstanden, du solltest einfach mal die zwei
                    Variablen ausgeben mit
                    füge am besten in einer der benannten Zeilen mal folgendes log ein

                    console.log(JSON.stringify(message));
                    console.log(JSON.stringify(remote));
                    

                    ich vermute ja, dass in der Variable remote die Adresse steht welches Radio gerade gesendet hat
                    dann müsste man entsprechend in den jeweiligen Pfad speichern.
                    Wie oben schon gesagt, denke ich das du keine zwei skripte anlegen darfst, sondern dieses an den besagten stellen erweitern musst
                    dass es mit zwei oder mehr Radios umgehen kann.

                    E 1 Antwort Letzte Antwort
                    0
                    • N Offline
                      N Offline
                      Nahasapee
                      schrieb am zuletzt editiert von
                      #18

                      Hi,
                      ich hab das Skript mal angepasst, so wie ich glaube
                      das es funktionieren könnte.

                      das einzige was ich nicht angepasst habe ist ganz unten im Abschnitt "reaktion auf Befehle"
                      da müssen die Pfade noch angepasst werden aber ich bin jetzt müde ;)
                      habs erst mal auskommentiert.

                      ich hab jetzt quasi die ganzen createstate geraffel in ne Funktion gebastelt und und am Anfang ne Liste mit Radios hinterlegt
                      die müsstest du dann füllen mit korrekten IP Adressen.
                      bei mir sah das im Objektbaum dann so aus:

                      cd783475-1b2b-4da9-b89a-5d496354f547-image.png

                      zum Schluss hab ich den server angepasst damit er auf unterschiedliche IP reagieren kann und entsprechend mappt
                      die sendcmd hab ich auch modifiziert damit die ganzen scheduler unten Funktionieren

                      für den "Abschnitt Reaktion auf Befehle" bräuchte man wahrscheinlich noch mal ne explizite sendcmd die an eine spezielle ipadresse sendet
                      für die gesamten on befehle die danach kommen.
                      hier das modifizierte skript konnte ich natürlich nur bedingt testen
                      Grüße und guten Nacht!

                      var pfad = 'Geraete.BuschJaeger.RadioINet.';
                      var pfad2 = 'javascript.0.' + pfad
                       
                      var UDPListenPort = 4242; //nicht ändern 
                      var UDPPort = 4244; //nicht ändern 
                      var RadioIPadress = '192.168.100.73' // IP Adresse des Radios
                      var HOST = '0.0.0.0'; //nicht ändern 
                       
                      var logging = false;
                       
                      const radios =  [
                           {
                                   IP: '192.168.100.73',
                                   pfad: 'Bad'
                                  },
                          {
                                   IP: '192.168.100.74',
                                   pfad: 'Keller'
                                  }        
                      ];
                      
                       
                      // ab hier nichts mehr ändern 
                       
                      var dgram = require('dgram');
                      var socket = dgram.createSocket('udp4');
                      var server = dgram.createSocket('udp4');
                      //var server2 = dgram.createSocket('udp4');
                      
                      const getRadioForIP= (IP)=>{
                          return radios.find(radio=>radio.IP == IP )
                      }
                      
                      const createAllStates = ()=>{
                          console.log("createALL");
                          radios.forEach((radio)=>{createRadioState(radio);});    
                      };
                      
                      const createRadioState = (radio)=>{
                      createState(pfad+ radio.pfad +"."+ "Command", '', { type: 'string', name: 'Last command', write: false });
                      createState(pfad+ radio.pfad +"."+ "WLAN_STRENGTH", '', { type: 'string', name: 'WLAN strength', write: false, unit: 'dBm' });
                      createState(pfad+ radio.pfad +"."+ "NAME", '', { type: 'string', name: 'Name of radio', write: false });
                      createState(pfad+ radio.pfad +"."+ "ID", '', { type: 'string', name: 'UDP ID', write: false });
                      createState(pfad+ radio.pfad +"."+ "IPADDR", '', { type: 'string', name: 'IP adress', write: false });
                      createState(pfad+ radio.pfad +"."+ "IPMASK", '', { type: 'string', name: 'IP Mask', write: false });
                      createState(pfad+ radio.pfad +"."+ "IPMODE", '', { type: 'string', name: 'IP  Mode', write: false });
                      createState(pfad+ radio.pfad +"."+ "GATEWAY", '', { type: 'string', name: 'Gateway', write: false });
                      createState(pfad+ radio.pfad +"."+ "SSID", '', { type: 'string', name: 'SSID', write: false });
                      createState(pfad+ radio.pfad +"."+ "MAC_ADRESS", '', { type: 'string', name: 'MAC adress', write: false });
                      createState(pfad+ radio.pfad +"."+ "COUNTRY", '', { type: 'string', name: 'Country', write: false });
                      createState(pfad+ radio.pfad +"."+ "SERIAL_NR", '', { type: 'string', name: 'Serial Nr', write: false });
                      createState(pfad+ radio.pfad +"."+ "SW-VERSION", '', { type: 'string', name: 'Software version', write: false });
                      createState(pfad+ radio.pfad +"."+ "WLAN-FW", '', { type: 'string', name: 'WLAN Firmware', write: false });
                      
                       
                      createState(pfad +radio.pfad+ "." + "POWER", '', { type: 'string', name: 'Current state of radio', write: false });
                      createState(pfad +radio.pfad+ "." + "ENERGY_MODE", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "VOLUME", '', { type: 'number', name: 'VOLUME', write: false });
                      createState(pfad +radio.pfad+ "." + "PLAYING_MODE", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "PLAYING", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATION_ID_PLAYING", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATION_URL_PLAYING", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATION_PLAYING", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "TUNEIN_ID", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "TUNEIN_SNR", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_1_NAME", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_1_URL", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_2_NAME", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_2_URL", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_3_NAME", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_3_URL", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_4_NAME", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_4_URL", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_5_NAME", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_5_URL", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_6_NAME", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_6_URL", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_7_NAME", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_7_URL", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_8_NAME", '', { type: 'string', name: '', write: false });
                      createState(pfad +radio.pfad+ "." + "STATIONS.STATION_8_URL", '', { type: 'string', name: '', write: false });
                       
                      createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_INC", false, { type: 'boolean', name: '', read: false, write: true, role: 'button' });
                      createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_DEC", false, { type: 'boolean', name: '', read: false, write: true, role: 'button' });
                      createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_MUTE", false, { type: 'boolean', name: '', read: false, write: true, role: 'switch' });
                      createState(pfad + radio.pfad +"." + "COMMAND.RADIO_ON", false, { type: 'boolean', name: '', read: false, write: true, role: 'switch' });
                      createState(pfad + radio.pfad +"." + "COMMAND.PLAY_STATION", 1, { type: 'number', name: 'PLAYING STATION 1-8', read: false, write: true });
                      createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_SET", 1, { type: 'number', name: 'SET VOLUME 0-31', read: false, write: true });
                      //createState(pfad+"COMMAND.VOLUME_DEC",      0,   {type: 'boolean', name: '', read: false, write: true, role:'button'});
                      };
                      createAllStates();
                      
                      
                       server.on('error', (err) => {
                          log(`server error:\n${err.stack}`);
                          server.close();
                      });
                      server.on('listening', function () {
                          var address = server.address();
                          log('UDP Server listening on ' + address.address + ":" + address.port);
                      });
                      server.bind(UDPListenPort, HOST);
                       
                      /* server2.on('listening', function () {
                          server2.setBroadcast(true);
                          server2.setMulticastLoopback(true);
                          var address = server2.address();
                         log('UDP Server 2 listening on ' + address.address + ":" + address.port);
                      });
                      server2.bind(PORT2, HOST); */
                       
                      // Antworten vom Radio auf Abfragen
                       
                      server.on('message', function (message, remote) {
                          if (logging) log('Meldung vom RADIO: ' + message);
                          const radio = getRadioForIP(remote.address);
                          
                          var command = findstr("COMMAND:", message);
                      if (command == "GET") {
                          if (message.indexOf("INFO_BLOCK") >= 0) {
                              setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                              setState(pfad + radio.pfad + "." + "WLAN_STRENGTH", findstr("WLAN STRENGTH:", message));
                              setState(pfad + radio.pfad + "." + "NAME", findstr("NAME:", message));
                              setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                              setState(pfad + radio.pfad + "." + "IPADDR", findstr("IPADDR:", message));
                              setState(pfad + radio.pfad + "." + "IPMASK", findstr("IPMASK:", message));
                              setState(pfad + radio.pfad + "." + "IPMODE", findstr("IPMODE:", message));
                              setState(pfad + radio.pfad + "." + "GATEWAY", findstr("GATEWAY:", message));
                              setState(pfad + radio.pfad + "." + "SSID", findstr("SSID:", message));
                              setState(pfad + radio.pfad + "." + "MAC_ADRESS", findstr("MAC:", message));
                              setState(pfad + radio.pfad + "." + "COUNTRY", findstr("COUNTRY:", message));
                              setState(pfad + radio.pfad + "." + "SERIAL_NR", findstr("SERNO:", message));
                              setState(pfad + radio.pfad + "." + "SW-VERSION", findstr("SW-VERSION:", message));
                              setState(pfad + radio.pfad + "." + "WLAN-FW", findstr("WLAN-FW:", message));
                          } else if (message.indexOf("VOLUME") >= 0) {
                              setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                              setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                              setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)));
                              if (parseInt(findstr("VOLUME_SET:", message)) >= 0 && parseInt(findstr("VOLUME_SET:", message)) <= 31 && message.indexOf("RESPONSE:ACK") >= 0) {
                                  setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true);
                              }
                          } else if (message.indexOf("POWER_STATUS") >= 0) {
                              setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                              setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                              setState(pfad + radio.pfad + "." + "POWER", findstr("POWER:", message));
                              if (findstr("POWER:", message) == "ON") {
                                  setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", true, true)
                              } else if (findstr("POWER:", message) == "OFF") {
                                  setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", false, true)
                              };
                              setState(pfad + radio.pfad + "." + "ENERGY_MODE", findstr("ENERGY_MODE:", message));
                          } else if (message.indexOf("TUNEIN_PARTNER_ID") >= 0) {
                              setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                              setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                              setState(pfad + radio.pfad + "." + "TUNEIN_ID", findstr("PARTNERID:", message));
                              setState(pfad + radio.pfad + "." + "TUNEIN_SNR", findstr("SERNO:", message));
                          } else if (message.indexOf("ALL_STATION_INFO") >= 0) {
                              setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                              setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_1_NAME", findstr("1\r\nNAME:", message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_1_URL", findstr(findstr("1\r\nNAME:", message) + '\r\nURL:', message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_2_NAME", findstr("2\r\nNAME:", message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_2_URL", findstr(findstr("2\r\nNAME:", message) + '\r\nURL:', message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_3_NAME", findstr("3\r\nNAME:", message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_3_URL", findstr(findstr("3\r\nNAME:", message) + '\r\nURL:', message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_4_NAME", findstr("4\r\nNAME:", message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_4_URL", findstr(findstr("4\r\nNAME:", message) + '\r\nURL:', message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_5_NAME", findstr("5\r\nNAME:", message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_5_URL", findstr(findstr("5\r\nNAME:", message) + '\r\nURL:', message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_6_NAME", findstr("6\r\nNAME:", message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_6_URL", findstr(findstr("6\r\nNAME:", message) + '\r\nURL:', message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_7_NAME", findstr("7\r\nNAME:", message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_7_URL", findstr(findstr("7\r\nNAME:", message) + '\r\nURL:', message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_8_NAME", findstr("8\r\nNAME:", message));
                              setState(pfad + radio.pfad + "." + "STATIONS.STATION_8_URL", findstr(findstr("8\r\nNAME:", message) + '\r\nURL:', message));
                          } else if (message.indexOf("PLAYING_MODE") >= 0) {
                              setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                              setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                              setState(pfad + radio.pfad + "." + "PLAYING_MODE", findstr("MODE:", message));
                              setState(pfad + radio.pfad + "." + "PLAYING", findstr("PLAYING:", message));
                              setState(pfad + radio.pfad + "." + "STATION_ID_PLAYING", findstr("N\r\nID:", message));
                              setState(pfad + radio.pfad + "." + "STATION_URL_PLAYING", findstr("URL:", message));
                              setState(pfad + radio.pfad + "." + "STATION_PLAYING", findstr("NAME:", message));
                          };
                      } else if (command == "NOTIFICATION") {
                          var event = findstr("EVENT:", message);
                          setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                          setState(pfad + radio.pfad + "." + "IPADDR", findstr("IP:", message));
                          setState(pfad + radio.pfad + "." + "NAME", findstr("NAME:", message));
                          if (logging) log("Event = '" + event + "'");
                          if (event == 'POWER_OFF' || event == 'POWER_ON') {
                              sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                          };
                          if (event == "VOLUME_CHANGED") {
                              sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                          };
                          if (event == 'STATION_CHANGED') {
                          };
                      } else if (command == "SET") {
                          if (message.indexOf("VOLUME_ABSOLUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                              setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                              setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                          }
                          if (message.indexOf("VOLUME_DEC") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                              setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                              setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                          }
                          if (message.indexOf("VOLUME_INC") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                              setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                              setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                          }
                          if (message.indexOf("VOLUME_UNMUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                              setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_MUTE", false, true)
                          }
                          if (message.indexOf("VOLUME_MUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                              setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_MUTE", true, true)
                          }
                          if (message.indexOf("RADIO_OFF") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                              setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", false, true);
                              setState(pfad + radio.pfad + "." + "POWER", "OFF");
                          }
                          if (message.indexOf("RADIO_ON") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                              setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", true, true);
                              setState(pfad + radio.pfad + "." + "POWER", "ON");
                          }
                      } else if (command == "PLAY") {
                          if (message.indexOf("STATION") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                              setState(pfad + radio.pfad + "." + "COMMAND.PLAY_STATION", parseInt(findstr("STATION:", message)), true);
                              setState(pfad + radio.pfad + "." + "STATION_ID_PLAYING", parseInt(findstr("STATION:", message)), true);
                              setState(pfad + radio.pfad + "." + "STATION_PLAYING", findstr("PLAYING:", message), true);
                          }
                      } else {
                      
                          if (logging) log('unexpected message: ' + message);
                      
                      }
                      });
                       
                      // starten der Abfragen nach Empfang von Broadcasts
                      /* var timer = null;
                       
                      server2.on('message', function (message, remote) {
                          if (timer) clearTimeout(timer);
                          if (logging) log('Broadcast vom Radio: ' + message);
                          if (logging) log(JSON.stringify(message));
                          //var obj = JSON.parse('{'+message+'}');
                          sendcmd(buf2);
                          timer = setTimeout(function () {
                              sendcmd(buf3);
                          }, 1000);
                      }); */
                      function findstr(name, str) {
                          var suchstring = String(name);
                          var teststring = String(str);
                          var pos = parseInt(teststring.indexOf(suchstring) + suchstring.length);
                          var zaehler = parseInt(pos) + 1;
                          //log("String: " + suchstring + "befindet sich an " + pos + " Stelle")
                          do {
                              var Zeichen = String(teststring).charCodeAt(zaehler);
                              //log ("Zeichen: " + Zeichen + " Zähler: " + (zaehler - pos));
                              zaehler = zaehler + 1;
                          } while (Zeichen != 13 && zaehler - pos <= 100);
                       
                       
                          //log("Start: " + pos + "Ende: " + zaehler);
                          var ergebnis = String(str).substring(pos, zaehler - 1);
                          if (teststring.indexOf(suchstring) == -1) {
                              ergebnis = ""
                          };
                       
                          //log("Objekt: " + name + " Wert: '" + ergebnis + "'");
                          return ergebnis
                      }
                       
                       
                      function sendcmd(cmd) {
                          radios.forEach(radio=>{
                          socket.send(cmd, 0, cmd.length, UDPPort, radio.IP, function (err, result) {
                              if (err) log('Fehler Senden ' + cmd, 'error');
                              else {
                                  if (logging) log('Kommando gesendet: ' + cmd);
                              }
                          });
                      
                          })
                          
                      }
                      //einmalige Ausführung beim  Starten des Skriptes
                      
                      
                      sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                      sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                      sendcmd('COMMAND:GET\r\nINFO_BLOCK\r\nID:ioBroker\r\n\r\n');
                      sendcmd('COMMAND:GET\r\nPLAYING_MODE\r\nID:ioBroker\r\n\r\n');
                      sendcmd('COMMAND:GET\r\nALL_STATION_INFO\r\nID:ioBroker\r\n\r\n');
                      
                       
                      var timer1 = null;
                      var timer2 = null;
                      var timer3 = null;
                      var timer4 = null;
                      schedule('*/1 * * * *', function () {  // jede Minute die wichtigsten Infos aktualisieren
                       
                          if (timer1) clearTimeout(timer1);
                          timer1 = setTimeout(function () {
                              sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                          }, 1000);
                          if (timer2) clearTimeout(timer2);
                          timer2 = setTimeout(function () {
                              sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                          }, 2000);
                          if (timer3) clearTimeout(timer3);
                          timer3 = setTimeout(function () {
                              sendcmd('COMMAND:GET\r\nINFO_BLOCK\r\nID:ioBroker\r\n\r\n');
                          }, 3000);
                          if (timer4) clearTimeout(timer4);
                          timer4 = setTimeout(function () {
                              sendcmd('COMMAND:GET\r\nPLAYING_MODE\r\nID:ioBroker\r\n\r\n');
                          }, 4000);
                      });
                       
                      schedule('*/30 * * * *', function () {  // alle 30 Minuten die Stationsliste aktualisieren
                          sendcmd('COMMAND:GET\r\nALL_STATION_INFO\r\nID:ioBroker\r\n\r\n');
                      });
                      
                      // Reaktionen auf Befehle
                      // on({ id: pfad2 + "COMMAND.VOLUME_INC", val: true }, function (obj) {
                      //     if (logging) log('COMMAND.VOLUME_INC');
                      //     sendcmd('COMMAND:SET\r\nVOLUME_INC\r\nID:ioBroker\r\n\r\n');
                      //     sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                      // });
                      // on({ id: pfad2 + "COMMAND.VOLUME_DEC", val: true }, function (obj) {
                      //     if (logging) log('COMMAND.VOLUME_DEC');
                      //     sendcmd('COMMAND:SET\r\nVOLUME_DEC\r\nID:ioBroker\r\n\r\n');
                      //     sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                      // });
                      // on({ id: pfad2 + "COMMAND.VOLUME_MUTE", change: "ne" }, function (obj) {
                      //     if (logging) log('COMMAND.VOLUME_MUTE');
                      //     if (obj.state.val === true) {
                      //         sendcmd('COMMAND:SET\r\nVOLUME_MUTE\r\nID:ioBroker\r\n\r\n');
                      //     }
                      //     if (obj.state.val === false) {
                      //         sendcmd('COMMAND:SET\r\nVOLUME_UNMUTE\r\nID:ioBroker\r\n\r\n');
                      //     }
                      //     sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                      // });
                      // on({ id: pfad2 + "COMMAND.RADIO_ON", change: "ne", ack: false }, function (obj) {
                      //     if (logging) log('COMMAND.RADIO_ON');
                      //     if (obj.state.val === true) {
                      //         sendcmd('COMMAND:SET\r\nRADIO_ON\r\nID:ioBroker\r\n\r\n');
                      //     }
                      //     if (obj.state.val === false) {
                      //         sendcmd('COMMAND:SET\r\nRADIO_OFF\r\nID:ioBroker\r\n\r\n');
                      //     }
                      //     sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                      // });
                      // on({ id: pfad2 + "COMMAND.PLAY_STATION", change: "ne", ack: false }, function (obj) {
                      //     if (logging) log('COMMAND.PLAY_STATION');
                      //     if (obj.state.val <= 8 && obj.state.val > 0) {
                      //         sendcmd('COMMAND:PLAY\r\nSTATION:' + obj.state.val + '\r\nID:ioBroker\r\n\r\n');
                      //     }
                      // });
                      // on({ id: pfad2 + "COMMAND.VOLUME_SET", change: "ne", ack: false }, function (obj) {
                      //     if (logging) log('COMMAND.PLAY_STATION');
                      //     if (obj.state.val <= 31 && obj.state.val >= 0) {
                      //         sendcmd('COMMAND:SET\r\nVOLUME_ABSOLUTE:' + obj.state.val + '\r\nID:ioBroker\r\n\r\n');
                      //     }
                      // }); 
                      
                      1 Antwort Letzte Antwort
                      0
                      • N Nahasapee

                        Sorry,
                        du hast mich jetzt falsch verstanden, du solltest einfach mal die zwei
                        Variablen ausgeben mit
                        füge am besten in einer der benannten Zeilen mal folgendes log ein

                        console.log(JSON.stringify(message));
                        console.log(JSON.stringify(remote));
                        

                        ich vermute ja, dass in der Variable remote die Adresse steht welches Radio gerade gesendet hat
                        dann müsste man entsprechend in den jeweiligen Pfad speichern.
                        Wie oben schon gesagt, denke ich das du keine zwei skripte anlegen darfst, sondern dieses an den besagten stellen erweitern musst
                        dass es mit zwei oder mehr Radios umgehen kann.

                        E Offline
                        E Offline
                        Eaterhnk
                        schrieb am zuletzt editiert von Eaterhnk
                        #19

                        @Nahasapee
                        vielen Dank für deine Hilfe, habe das geänderte Skript kopiert und die IPs bzw den Pfad angepasst. Leider funktioniert es nicht. Habe aber in dem vorherigen Skript in Zeile 97 die von dir genannten Befehle eingefügt und im LOG wird folgendes ausgegeben:

                        javascript.0 2019-12-11 20:38:26.941 info at process._tickCallback (internal/process/next_tick.js:63:19)
                        javascript.0 2019-12-11 20:38:26.941 info at state.handle.lookup (dgram.js:242:18)
                        javascript.0 2019-12-11 20:38:26.941 info Error: bind EADDRINUSE 0.0.0.0:4242
                        javascript.0 2019-12-11 20:38:26.941 info (29194) script.js.Skrypte_in_Betrieb.Radio_Kueche: server error:
                        javascript.0 2019-12-11 20:38:26.940 info (29194) script.js.Skrypte_in_Betrieb.Radio_Kueche: registered 6 subscriptions and 2 schedules
                        javascript.0 2019-12-11 20:38:26.927 info (29194) Start javascript script.js.Skrypte_in_Betrieb.Radio_Kueche

                        1 Antwort Letzte Antwort
                        0
                        • N Offline
                          N Offline
                          Nahasapee
                          schrieb am zuletzt editiert von
                          #20

                          @Eaterhnk sagte in [Vorlage] Busch Jäger Radio iNet 8216 U:

                          javascript.0 2019-12-11 20:38:26.941 info Error: bind EADDRINUSE 0.0.0.0:4242

                          du musst deine java script Instanz stoppen und wieder starten , das Skript scheint die ports nicht wieder freizugeben
                          und
                          @Eaterhnk sagte in [Vorlage] Busch Jäger Radio iNet 8216 U:

                          . Leider funktioniert es nicht.

                          die info ist bisschen wenig um dir zu helfen ;)

                          E 1 Antwort Letzte Antwort
                          0
                          • N Nahasapee

                            @Eaterhnk sagte in [Vorlage] Busch Jäger Radio iNet 8216 U:

                            javascript.0 2019-12-11 20:38:26.941 info Error: bind EADDRINUSE 0.0.0.0:4242

                            du musst deine java script Instanz stoppen und wieder starten , das Skript scheint die ports nicht wieder freizugeben
                            und
                            @Eaterhnk sagte in [Vorlage] Busch Jäger Radio iNet 8216 U:

                            . Leider funktioniert es nicht.

                            die info ist bisschen wenig um dir zu helfen ;)

                            E Offline
                            E Offline
                            Eaterhnk
                            schrieb am zuletzt editiert von Eaterhnk
                            #21

                            @Nahasapee
                            Ich habe das bisherige Skript gestoppt, alle bisherigen Ordner in den Objekten gelöscht, deine neue Version in ein neues Skript gepackt die Einstellungen angepasst und dies gestartet. Zudem wurde Iobroker neugestartet per Restart. In den Objekten wird zwar die neue Ordnerstruktur angezeigt aber nicht mit Werte gefüllt... im LOG waren bestimmt über 20 Warnungen diesbezüglich. (Kann ich gerne nachreichen)
                            Nachdem wurde das neue Skript gestoppt, Ordner gelöscht, das alte Skript in Zeile 97 um beide Befehle ergänzt. Skript gestartet, Iobroker restart und den LOG siehst du hier in dem Beitrag.

                            1 Antwort Letzte Antwort
                            0
                            • N Offline
                              N Offline
                              Nahasapee
                              schrieb am zuletzt editiert von Nahasapee
                              #22

                              hi
                              ich hab jetzt noch mal den letzten teil ergänzt der gestern gefehlt hatte damit er auf die commands reagiert.

                              var pfad = 'Geraete.BuschJaeger.RadioINet.';
                              var pfad2 = 'javascript.0.' + pfad
                               
                              var UDPListenPort = 4242; //nicht ändern 
                              var UDPPort = 4244; //nicht ändern 
                              var RadioIPadress = '192.168.100.73' // IP Adresse des Radios
                              var HOST = '0.0.0.0'; //nicht ändern 
                               
                              var logging = false;
                               
                              const radios =  [
                                   {
                                           IP: '192.168.100.73',
                                           pfad: 'Bad'
                                          },
                                  {
                                           IP: '192.168.100.74',
                                           pfad: 'Keller'
                                          }        
                              ];
                              
                               
                              // ab hier nichts mehr ändern 
                               
                              var dgram = require('dgram');
                              var socket = dgram.createSocket('udp4');
                              var server = dgram.createSocket('udp4');
                              //var server2 = dgram.createSocket('udp4');
                              
                              const getRadioForIP= (IP)=>{
                                  return radios.find(radio=>radio.IP == IP )
                              }
                              
                              const createAllStates = ()=>{    
                                  radios.forEach((radio)=>{createRadioState(radio);});    
                              };
                              
                              const createRadioState = (radio)=>{
                              createState(pfad+ radio.pfad +"."+ "Command", '', { type: 'string', name: 'Last command', write: false });
                              createState(pfad+ radio.pfad +"."+ "WLAN_STRENGTH", '', { type: 'string', name: 'WLAN strength', write: false, unit: 'dBm' });
                              createState(pfad+ radio.pfad +"."+ "NAME", '', { type: 'string', name: 'Name of radio', write: false });
                              createState(pfad+ radio.pfad +"."+ "ID", '', { type: 'string', name: 'UDP ID', write: false });
                              createState(pfad+ radio.pfad +"."+ "IPADDR", '', { type: 'string', name: 'IP adress', write: false });
                              createState(pfad+ radio.pfad +"."+ "IPMASK", '', { type: 'string', name: 'IP Mask', write: false });
                              createState(pfad+ radio.pfad +"."+ "IPMODE", '', { type: 'string', name: 'IP  Mode', write: false });
                              createState(pfad+ radio.pfad +"."+ "GATEWAY", '', { type: 'string', name: 'Gateway', write: false });
                              createState(pfad+ radio.pfad +"."+ "SSID", '', { type: 'string', name: 'SSID', write: false });
                              createState(pfad+ radio.pfad +"."+ "MAC_ADRESS", '', { type: 'string', name: 'MAC adress', write: false });
                              createState(pfad+ radio.pfad +"."+ "COUNTRY", '', { type: 'string', name: 'Country', write: false });
                              createState(pfad+ radio.pfad +"."+ "SERIAL_NR", '', { type: 'string', name: 'Serial Nr', write: false });
                              createState(pfad+ radio.pfad +"."+ "SW-VERSION", '', { type: 'string', name: 'Software version', write: false });
                              createState(pfad+ radio.pfad +"."+ "WLAN-FW", '', { type: 'string', name: 'WLAN Firmware', write: false });
                              
                               
                              createState(pfad +radio.pfad+ "." + "POWER", '', { type: 'string', name: 'Current state of radio', write: false });
                              createState(pfad +radio.pfad+ "." + "ENERGY_MODE", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "VOLUME", '', { type: 'number', name: 'VOLUME', write: false });
                              createState(pfad +radio.pfad+ "." + "PLAYING_MODE", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "PLAYING", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATION_ID_PLAYING", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATION_URL_PLAYING", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATION_PLAYING", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "TUNEIN_ID", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "TUNEIN_SNR", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_1_NAME", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_1_URL", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_2_NAME", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_2_URL", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_3_NAME", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_3_URL", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_4_NAME", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_4_URL", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_5_NAME", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_5_URL", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_6_NAME", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_6_URL", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_7_NAME", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_7_URL", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_8_NAME", '', { type: 'string', name: '', write: false });
                              createState(pfad +radio.pfad+ "." + "STATIONS.STATION_8_URL", '', { type: 'string', name: '', write: false });
                               
                              createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_INC", false, { type: 'boolean', name: '', read: false, write: true, role: 'button' });
                              createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_DEC", false, { type: 'boolean', name: '', read: false, write: true, role: 'button' });
                              createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_MUTE", false, { type: 'boolean', name: '', read: false, write: true, role: 'switch' });
                              createState(pfad + radio.pfad +"." + "COMMAND.RADIO_ON", false, { type: 'boolean', name: '', read: false, write: true, role: 'switch' });
                              createState(pfad + radio.pfad +"." + "COMMAND.PLAY_STATION", 1, { type: 'number', name: 'PLAYING STATION 1-8', read: false, write: true });
                              createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_SET", 1, { type: 'number', name: 'SET VOLUME 0-31', read: false, write: true });
                              //createState(pfad+"COMMAND.VOLUME_DEC",      0,   {type: 'boolean', name: '', read: false, write: true, role:'button'});
                              };
                              createAllStates();
                              
                              
                               server.on('error', (err) => {
                                  log(`server error:\n${err.stack}`);
                                  server.close();
                              });
                              server.on('listening', function () {
                                  var address = server.address();
                                  log('UDP Server listening on ' + address.address + ":" + address.port);
                              });
                              
                              try{
                              server.bind(UDPListenPort);
                              }
                              catch(error){console.log(error);}
                              
                               
                              /* server2.on('listening', function () {
                                  server2.setBroadcast(true);
                                  server2.setMulticastLoopback(true);
                                  var address = server2.address();
                                 log('UDP Server 2 listening on ' + address.address + ":" + address.port);
                              });
                              server2.bind(PORT2, HOST); */
                               
                              // Antworten vom Radio auf Abfragen
                               
                              server.on('message', function (message, remote) {   
                                  if (logging) log('Meldung vom RADIO: ' + message);
                                  const radio = getRadioForIP(remote.address);
                                  
                                  var command = findstr("COMMAND:", message);
                                  if (command == "GET") {
                                  if (message.indexOf("INFO_BLOCK") >= 0) {
                                      setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                      setState(pfad + radio.pfad + "." + "WLAN_STRENGTH", findstr("WLAN STRENGTH:", message));
                                      setState(pfad + radio.pfad + "." + "NAME", findstr("NAME:", message));
                                      setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                      setState(pfad + radio.pfad + "." + "IPADDR", findstr("IPADDR:", message));
                                      setState(pfad + radio.pfad + "." + "IPMASK", findstr("IPMASK:", message));
                                      setState(pfad + radio.pfad + "." + "IPMODE", findstr("IPMODE:", message));
                                      setState(pfad + radio.pfad + "." + "GATEWAY", findstr("GATEWAY:", message));
                                      setState(pfad + radio.pfad + "." + "SSID", findstr("SSID:", message));
                                      setState(pfad + radio.pfad + "." + "MAC_ADRESS", findstr("MAC:", message));
                                      setState(pfad + radio.pfad + "." + "COUNTRY", findstr("COUNTRY:", message));
                                      setState(pfad + radio.pfad + "." + "SERIAL_NR", findstr("SERNO:", message));
                                      setState(pfad + radio.pfad + "." + "SW-VERSION", findstr("SW-VERSION:", message));
                                      setState(pfad + radio.pfad + "." + "WLAN-FW", findstr("WLAN-FW:", message));
                                  } else if (message.indexOf("VOLUME") >= 0) {
                                      setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                      setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                      setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)));
                                      if (parseInt(findstr("VOLUME_SET:", message)) >= 0 && parseInt(findstr("VOLUME_SET:", message)) <= 31 && message.indexOf("RESPONSE:ACK") >= 0) {
                                          setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true);
                                      }
                                  } else if (message.indexOf("POWER_STATUS") >= 0) {
                                      setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                      setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                      setState(pfad + radio.pfad + "." + "POWER", findstr("POWER:", message));
                                      if (findstr("POWER:", message) == "ON") {
                                          setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", true, true)
                                      } else if (findstr("POWER:", message) == "OFF") {
                                          setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", false, true)
                                      };
                                      setState(pfad + radio.pfad + "." + "ENERGY_MODE", findstr("ENERGY_MODE:", message));
                                  } else if (message.indexOf("TUNEIN_PARTNER_ID") >= 0) {
                                      setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                      setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                      setState(pfad + radio.pfad + "." + "TUNEIN_ID", findstr("PARTNERID:", message));
                                      setState(pfad + radio.pfad + "." + "TUNEIN_SNR", findstr("SERNO:", message));
                                  } else if (message.indexOf("ALL_STATION_INFO") >= 0) {
                                      setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                      setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_1_NAME", findstr("1\r\nNAME:", message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_1_URL", findstr(findstr("1\r\nNAME:", message) + '\r\nURL:', message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_2_NAME", findstr("2\r\nNAME:", message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_2_URL", findstr(findstr("2\r\nNAME:", message) + '\r\nURL:', message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_3_NAME", findstr("3\r\nNAME:", message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_3_URL", findstr(findstr("3\r\nNAME:", message) + '\r\nURL:', message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_4_NAME", findstr("4\r\nNAME:", message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_4_URL", findstr(findstr("4\r\nNAME:", message) + '\r\nURL:', message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_5_NAME", findstr("5\r\nNAME:", message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_5_URL", findstr(findstr("5\r\nNAME:", message) + '\r\nURL:', message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_6_NAME", findstr("6\r\nNAME:", message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_6_URL", findstr(findstr("6\r\nNAME:", message) + '\r\nURL:', message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_7_NAME", findstr("7\r\nNAME:", message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_7_URL", findstr(findstr("7\r\nNAME:", message) + '\r\nURL:', message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_8_NAME", findstr("8\r\nNAME:", message));
                                      setState(pfad + radio.pfad + "." + "STATIONS.STATION_8_URL", findstr(findstr("8\r\nNAME:", message) + '\r\nURL:', message));
                                  } else if (message.indexOf("PLAYING_MODE") >= 0) {
                                      setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                      setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                      setState(pfad + radio.pfad + "." + "PLAYING_MODE", findstr("MODE:", message));
                                      setState(pfad + radio.pfad + "." + "PLAYING", findstr("PLAYING:", message));
                                      setState(pfad + radio.pfad + "." + "STATION_ID_PLAYING", findstr("N\r\nID:", message));
                                      setState(pfad + radio.pfad + "." + "STATION_URL_PLAYING", findstr("URL:", message));
                                      setState(pfad + radio.pfad + "." + "STATION_PLAYING", findstr("NAME:", message));
                                  };
                              } else if (command == "NOTIFICATION") {
                                  var event = findstr("EVENT:", message);
                                  setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                  setState(pfad + radio.pfad + "." + "IPADDR", findstr("IP:", message));
                                  setState(pfad + radio.pfad + "." + "NAME", findstr("NAME:", message));
                                  if (logging) log("Event = '" + event + "'");
                                 
                                  if (event == 'POWER_OFF' || event == 'POWER_ON') {
                                      sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                                  };
                                  if (event == "VOLUME_CHANGED") {
                                      sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                                  };
                                  if (event == 'STATION_CHANGED') {
                                  };
                              } else if (command == "SET") {
                                  if (message.indexOf("VOLUME_ABSOLUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                      setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                                      setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                                  }
                                  if (message.indexOf("VOLUME_DEC") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                      setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                                      setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                                  }
                                  if (message.indexOf("VOLUME_INC") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                      setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                                      setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                                  }
                                  if (message.indexOf("VOLUME_UNMUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                      setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_MUTE", false, true)
                                  }
                                  if (message.indexOf("VOLUME_MUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                      setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_MUTE", true, true)
                                  }
                                  if (message.indexOf("RADIO_OFF") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                      setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", false, true);
                                      setState(pfad + radio.pfad + "." + "POWER", "OFF");
                                  }
                                  if (message.indexOf("RADIO_ON") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                      setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", true, true);
                                      setState(pfad + radio.pfad + "." + "POWER", "ON");
                                  }
                              } else if (command == "PLAY") {
                                  if (message.indexOf("STATION") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                      setState(pfad + radio.pfad + "." + "COMMAND.PLAY_STATION", parseInt(findstr("STATION:", message)), true);
                                      setState(pfad + radio.pfad + "." + "STATION_ID_PLAYING", parseInt(findstr("STATION:", message)), true);
                                      setState(pfad + radio.pfad + "." + "STATION_PLAYING", findstr("PLAYING:", message), true);
                                  }
                              } else {
                              
                                  if (logging) log('unexpected message: ' + message);
                              
                              }
                              });
                               
                              // starten der Abfragen nach Empfang von Broadcasts
                              /* var timer = null;
                               
                              server2.on('message', function (message, remote) {
                                  if (timer) clearTimeout(timer);
                                  if (logging) log('Broadcast vom Radio: ' + message);
                                  if (logging) log(JSON.stringify(message));
                                  //var obj = JSON.parse('{'+message+'}');
                                  sendcmd(buf2);
                                  timer = setTimeout(function () {
                                      sendcmd(buf3);
                                  }, 1000);
                              }); */
                              function findstr(name, str) {
                                  var suchstring = String(name);
                                  var teststring = String(str);
                                  var pos = parseInt(teststring.indexOf(suchstring) + suchstring.length);
                                  var zaehler = parseInt(pos) + 1;
                                  //log("String: " + suchstring + "befindet sich an " + pos + " Stelle")
                                  do {
                                      var Zeichen = String(teststring).charCodeAt(zaehler);
                                      //log ("Zeichen: " + Zeichen + " Zähler: " + (zaehler - pos));
                                      zaehler = zaehler + 1;
                                  } while (Zeichen != 13 && zaehler - pos <= 100);
                               
                               
                                  //log("Start: " + pos + "Ende: " + zaehler);
                                  var ergebnis = String(str).substring(pos, zaehler - 1);
                                  if (teststring.indexOf(suchstring) == -1) {
                                      ergebnis = ""
                                  };
                               
                                  //log("Objekt: " + name + " Wert: '" + ergebnis + "'");
                                  return ergebnis
                              }
                               
                               
                              function sendcmd(cmd) {
                                  radios.forEach(radio=>{       
                                  socket.send(cmd, 0, cmd.length, UDPPort, radio.IP, function (err, result) {
                                      if (err) log('Fehler Senden ' + cmd, 'error');
                                      else {
                                          if (logging) log('Kommando gesendet: ' + cmd);
                                      }
                                  });})   
                              }
                              
                              function sendcmdToIp(cmd,IP) {    
                                  socket.send(cmd, 0, cmd.length, UDPPort, IP, function (err, result) {
                                      if (err) log('Fehler Senden ' + cmd, 'error');
                                      else {
                                          if (logging) log('Kommando gesendet: ' + cmd);
                                      }
                                  });   
                              }
                              
                              //einmalige Ausführung beim  Starten des Skriptes
                              sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                              sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                              sendcmd('COMMAND:GET\r\nINFO_BLOCK\r\nID:ioBroker\r\n\r\n');
                              sendcmd('COMMAND:GET\r\nPLAYING_MODE\r\nID:ioBroker\r\n\r\n');
                              sendcmd('COMMAND:GET\r\nALL_STATION_INFO\r\nID:ioBroker\r\n\r\n');
                              
                               
                              var timer1 = null;
                              var timer2 = null;
                              var timer3 = null;
                              var timer4 = null;
                              schedule('*/1 * * * *', function () {  // jede Minute die wichtigsten Infos aktualisieren
                               
                                  if (timer1) clearTimeout(timer1);
                                  timer1 = setTimeout(function () {
                                      sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                                  }, 1000);
                                  if (timer2) clearTimeout(timer2);
                                  timer2 = setTimeout(function () {
                                      sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                                  }, 2000);
                                  if (timer3) clearTimeout(timer3);
                                  timer3 = setTimeout(function () {
                                      sendcmd('COMMAND:GET\r\nINFO_BLOCK\r\nID:ioBroker\r\n\r\n');
                                  }, 3000);
                                  if (timer4) clearTimeout(timer4);
                                  timer4 = setTimeout(function () {
                                      sendcmd('COMMAND:GET\r\nPLAYING_MODE\r\nID:ioBroker\r\n\r\n');
                                  }, 4000);
                              });
                               
                              schedule('*/30 * * * *', function () {  // alle 30 Minuten die Stationsliste aktualisieren
                                  sendcmd('COMMAND:GET\r\nALL_STATION_INFO\r\nID:ioBroker\r\n\r\n');
                              });
                              
                              const initOnForAllRadios =()=>{
                                  radios.forEach(radio=>
                                  {
                                    on({ id: pfad2 + radio.pfad + ".COMMAND.VOLUME_INC", val: true }, function (obj) {                        
                                          
                                               sendcmdToIp('COMMAND:SET\r\nVOLUME_INC\r\nID:ioBroker\r\n\r\n',radio.IP);
                                               sendcmdToIp('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n',radio.IP);
                                           });                                                                         
                              
                                     on({ id: pfad2 + radio.pfad + ".COMMAND.VOLUME_DEC", val: true }, function (obj) {        
                                       sendcmdToIp('COMMAND:SET\r\nVOLUME_DEC\r\nID:ioBroker\r\n\r\n',radio.IP);
                                       sendcmdToIp('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n',radio.IP);});
                                     on({ id: pfad2  + radio.pfad + ".COMMAND.VOLUME_MUTE", change: "ne" }, function (obj) {            
                                          if (obj.state.val === true) {
                                              sendcmdToIp('COMMAND:SET\r\nVOLUME_MUTE\r\nID:ioBroker\r\n\r\n',radio.IP);}
                                          if (obj.state.val === false) {
                                            sendcmdToIp('COMMAND:SET\r\nVOLUME_UNMUTE\r\nID:ioBroker\r\n\r\n',radio.IP);
                                          }
                                       sendcmdToIp('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n',radio.IP);
                                       });
                                     on({ id: pfad2 +radio.pfad+ ".COMMAND.RADIO_ON", change: "ne", ack: false }, function (obj) {    
                                              if (obj.state.val === true) 
                                                  sendcmdToIp('COMMAND:SET\r\nRADIO_ON\r\nID:ioBroker\r\n\r\n',radio.IP);                
                                              if (obj.state.val === false) 
                                                  sendcmdToIp('COMMAND:SET\r\nRADIO_OFF\r\nID:ioBroker\r\n\r\n',radio.IP);    
                                              sendcmdToIp('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n',radio.IP);});
                                    on({ id: pfad2 +radio.pfad+ ".COMMAND.PLAY_STATION", change: "ne", ack: false }, function (obj) {    
                                      if (obj.state.val <= 8 && obj.state.val > 0) {
                                          sendcmdToIp('COMMAND:PLAY\r\nSTATION:' + obj.state.val + '\r\nID:ioBroker\r\n\r\n',radio.IP);}}); 
                                    on({ id: pfad2+radio.pfad + ".COMMAND.VOLUME_SET", change: "ne", ack: false }, function (obj) {    
                                      if (obj.state.val <= 31 && obj.state.val >= 0) {
                                          sendcmdToIp('COMMAND:SET\r\nVOLUME_ABSOLUTE:' + obj.state.val + '\r\nID:ioBroker\r\n\r\n',radio.IP);}});         
                                  });
                              };
                              initOnForAllRadios();
                              

                              das Skript einach nur stoppen und starten reicht glaube ich nicht du musst den ganzen javascript adapter neustarten, da die port weiter belegt sind wenn du nur das skript neustartest.
                              geil wäre es wenn du mal so ne message von so einem radio posten könntest.
                              ich hatte es bei mir mit nen fake udp radio local getestet , da scheinen die meldung im borker anzukommen ich kann leider nicht ne genau message von so nem radio simulieren , da ich nicht weiß wie die aussieht.
                              grüße

                              E 1 Antwort Letzte Antwort
                              -1
                              • N Nahasapee

                                hi
                                ich hab jetzt noch mal den letzten teil ergänzt der gestern gefehlt hatte damit er auf die commands reagiert.

                                var pfad = 'Geraete.BuschJaeger.RadioINet.';
                                var pfad2 = 'javascript.0.' + pfad
                                 
                                var UDPListenPort = 4242; //nicht ändern 
                                var UDPPort = 4244; //nicht ändern 
                                var RadioIPadress = '192.168.100.73' // IP Adresse des Radios
                                var HOST = '0.0.0.0'; //nicht ändern 
                                 
                                var logging = false;
                                 
                                const radios =  [
                                     {
                                             IP: '192.168.100.73',
                                             pfad: 'Bad'
                                            },
                                    {
                                             IP: '192.168.100.74',
                                             pfad: 'Keller'
                                            }        
                                ];
                                
                                 
                                // ab hier nichts mehr ändern 
                                 
                                var dgram = require('dgram');
                                var socket = dgram.createSocket('udp4');
                                var server = dgram.createSocket('udp4');
                                //var server2 = dgram.createSocket('udp4');
                                
                                const getRadioForIP= (IP)=>{
                                    return radios.find(radio=>radio.IP == IP )
                                }
                                
                                const createAllStates = ()=>{    
                                    radios.forEach((radio)=>{createRadioState(radio);});    
                                };
                                
                                const createRadioState = (radio)=>{
                                createState(pfad+ radio.pfad +"."+ "Command", '', { type: 'string', name: 'Last command', write: false });
                                createState(pfad+ radio.pfad +"."+ "WLAN_STRENGTH", '', { type: 'string', name: 'WLAN strength', write: false, unit: 'dBm' });
                                createState(pfad+ radio.pfad +"."+ "NAME", '', { type: 'string', name: 'Name of radio', write: false });
                                createState(pfad+ radio.pfad +"."+ "ID", '', { type: 'string', name: 'UDP ID', write: false });
                                createState(pfad+ radio.pfad +"."+ "IPADDR", '', { type: 'string', name: 'IP adress', write: false });
                                createState(pfad+ radio.pfad +"."+ "IPMASK", '', { type: 'string', name: 'IP Mask', write: false });
                                createState(pfad+ radio.pfad +"."+ "IPMODE", '', { type: 'string', name: 'IP  Mode', write: false });
                                createState(pfad+ radio.pfad +"."+ "GATEWAY", '', { type: 'string', name: 'Gateway', write: false });
                                createState(pfad+ radio.pfad +"."+ "SSID", '', { type: 'string', name: 'SSID', write: false });
                                createState(pfad+ radio.pfad +"."+ "MAC_ADRESS", '', { type: 'string', name: 'MAC adress', write: false });
                                createState(pfad+ radio.pfad +"."+ "COUNTRY", '', { type: 'string', name: 'Country', write: false });
                                createState(pfad+ radio.pfad +"."+ "SERIAL_NR", '', { type: 'string', name: 'Serial Nr', write: false });
                                createState(pfad+ radio.pfad +"."+ "SW-VERSION", '', { type: 'string', name: 'Software version', write: false });
                                createState(pfad+ radio.pfad +"."+ "WLAN-FW", '', { type: 'string', name: 'WLAN Firmware', write: false });
                                
                                 
                                createState(pfad +radio.pfad+ "." + "POWER", '', { type: 'string', name: 'Current state of radio', write: false });
                                createState(pfad +radio.pfad+ "." + "ENERGY_MODE", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "VOLUME", '', { type: 'number', name: 'VOLUME', write: false });
                                createState(pfad +radio.pfad+ "." + "PLAYING_MODE", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "PLAYING", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATION_ID_PLAYING", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATION_URL_PLAYING", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATION_PLAYING", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "TUNEIN_ID", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "TUNEIN_SNR", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_1_NAME", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_1_URL", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_2_NAME", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_2_URL", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_3_NAME", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_3_URL", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_4_NAME", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_4_URL", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_5_NAME", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_5_URL", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_6_NAME", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_6_URL", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_7_NAME", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_7_URL", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_8_NAME", '', { type: 'string', name: '', write: false });
                                createState(pfad +radio.pfad+ "." + "STATIONS.STATION_8_URL", '', { type: 'string', name: '', write: false });
                                 
                                createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_INC", false, { type: 'boolean', name: '', read: false, write: true, role: 'button' });
                                createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_DEC", false, { type: 'boolean', name: '', read: false, write: true, role: 'button' });
                                createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_MUTE", false, { type: 'boolean', name: '', read: false, write: true, role: 'switch' });
                                createState(pfad + radio.pfad +"." + "COMMAND.RADIO_ON", false, { type: 'boolean', name: '', read: false, write: true, role: 'switch' });
                                createState(pfad + radio.pfad +"." + "COMMAND.PLAY_STATION", 1, { type: 'number', name: 'PLAYING STATION 1-8', read: false, write: true });
                                createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_SET", 1, { type: 'number', name: 'SET VOLUME 0-31', read: false, write: true });
                                //createState(pfad+"COMMAND.VOLUME_DEC",      0,   {type: 'boolean', name: '', read: false, write: true, role:'button'});
                                };
                                createAllStates();
                                
                                
                                 server.on('error', (err) => {
                                    log(`server error:\n${err.stack}`);
                                    server.close();
                                });
                                server.on('listening', function () {
                                    var address = server.address();
                                    log('UDP Server listening on ' + address.address + ":" + address.port);
                                });
                                
                                try{
                                server.bind(UDPListenPort);
                                }
                                catch(error){console.log(error);}
                                
                                 
                                /* server2.on('listening', function () {
                                    server2.setBroadcast(true);
                                    server2.setMulticastLoopback(true);
                                    var address = server2.address();
                                   log('UDP Server 2 listening on ' + address.address + ":" + address.port);
                                });
                                server2.bind(PORT2, HOST); */
                                 
                                // Antworten vom Radio auf Abfragen
                                 
                                server.on('message', function (message, remote) {   
                                    if (logging) log('Meldung vom RADIO: ' + message);
                                    const radio = getRadioForIP(remote.address);
                                    
                                    var command = findstr("COMMAND:", message);
                                    if (command == "GET") {
                                    if (message.indexOf("INFO_BLOCK") >= 0) {
                                        setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                        setState(pfad + radio.pfad + "." + "WLAN_STRENGTH", findstr("WLAN STRENGTH:", message));
                                        setState(pfad + radio.pfad + "." + "NAME", findstr("NAME:", message));
                                        setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                        setState(pfad + radio.pfad + "." + "IPADDR", findstr("IPADDR:", message));
                                        setState(pfad + radio.pfad + "." + "IPMASK", findstr("IPMASK:", message));
                                        setState(pfad + radio.pfad + "." + "IPMODE", findstr("IPMODE:", message));
                                        setState(pfad + radio.pfad + "." + "GATEWAY", findstr("GATEWAY:", message));
                                        setState(pfad + radio.pfad + "." + "SSID", findstr("SSID:", message));
                                        setState(pfad + radio.pfad + "." + "MAC_ADRESS", findstr("MAC:", message));
                                        setState(pfad + radio.pfad + "." + "COUNTRY", findstr("COUNTRY:", message));
                                        setState(pfad + radio.pfad + "." + "SERIAL_NR", findstr("SERNO:", message));
                                        setState(pfad + radio.pfad + "." + "SW-VERSION", findstr("SW-VERSION:", message));
                                        setState(pfad + radio.pfad + "." + "WLAN-FW", findstr("WLAN-FW:", message));
                                    } else if (message.indexOf("VOLUME") >= 0) {
                                        setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                        setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                        setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)));
                                        if (parseInt(findstr("VOLUME_SET:", message)) >= 0 && parseInt(findstr("VOLUME_SET:", message)) <= 31 && message.indexOf("RESPONSE:ACK") >= 0) {
                                            setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true);
                                        }
                                    } else if (message.indexOf("POWER_STATUS") >= 0) {
                                        setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                        setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                        setState(pfad + radio.pfad + "." + "POWER", findstr("POWER:", message));
                                        if (findstr("POWER:", message) == "ON") {
                                            setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", true, true)
                                        } else if (findstr("POWER:", message) == "OFF") {
                                            setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", false, true)
                                        };
                                        setState(pfad + radio.pfad + "." + "ENERGY_MODE", findstr("ENERGY_MODE:", message));
                                    } else if (message.indexOf("TUNEIN_PARTNER_ID") >= 0) {
                                        setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                        setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                        setState(pfad + radio.pfad + "." + "TUNEIN_ID", findstr("PARTNERID:", message));
                                        setState(pfad + radio.pfad + "." + "TUNEIN_SNR", findstr("SERNO:", message));
                                    } else if (message.indexOf("ALL_STATION_INFO") >= 0) {
                                        setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                        setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_1_NAME", findstr("1\r\nNAME:", message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_1_URL", findstr(findstr("1\r\nNAME:", message) + '\r\nURL:', message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_2_NAME", findstr("2\r\nNAME:", message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_2_URL", findstr(findstr("2\r\nNAME:", message) + '\r\nURL:', message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_3_NAME", findstr("3\r\nNAME:", message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_3_URL", findstr(findstr("3\r\nNAME:", message) + '\r\nURL:', message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_4_NAME", findstr("4\r\nNAME:", message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_4_URL", findstr(findstr("4\r\nNAME:", message) + '\r\nURL:', message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_5_NAME", findstr("5\r\nNAME:", message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_5_URL", findstr(findstr("5\r\nNAME:", message) + '\r\nURL:', message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_6_NAME", findstr("6\r\nNAME:", message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_6_URL", findstr(findstr("6\r\nNAME:", message) + '\r\nURL:', message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_7_NAME", findstr("7\r\nNAME:", message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_7_URL", findstr(findstr("7\r\nNAME:", message) + '\r\nURL:', message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_8_NAME", findstr("8\r\nNAME:", message));
                                        setState(pfad + radio.pfad + "." + "STATIONS.STATION_8_URL", findstr(findstr("8\r\nNAME:", message) + '\r\nURL:', message));
                                    } else if (message.indexOf("PLAYING_MODE") >= 0) {
                                        setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                        setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message));
                                        setState(pfad + radio.pfad + "." + "PLAYING_MODE", findstr("MODE:", message));
                                        setState(pfad + radio.pfad + "." + "PLAYING", findstr("PLAYING:", message));
                                        setState(pfad + radio.pfad + "." + "STATION_ID_PLAYING", findstr("N\r\nID:", message));
                                        setState(pfad + radio.pfad + "." + "STATION_URL_PLAYING", findstr("URL:", message));
                                        setState(pfad + radio.pfad + "." + "STATION_PLAYING", findstr("NAME:", message));
                                    };
                                } else if (command == "NOTIFICATION") {
                                    var event = findstr("EVENT:", message);
                                    setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message));
                                    setState(pfad + radio.pfad + "." + "IPADDR", findstr("IP:", message));
                                    setState(pfad + radio.pfad + "." + "NAME", findstr("NAME:", message));
                                    if (logging) log("Event = '" + event + "'");
                                   
                                    if (event == 'POWER_OFF' || event == 'POWER_ON') {
                                        sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                                    };
                                    if (event == "VOLUME_CHANGED") {
                                        sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                                    };
                                    if (event == 'STATION_CHANGED') {
                                    };
                                } else if (command == "SET") {
                                    if (message.indexOf("VOLUME_ABSOLUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                        setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                                        setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                                    }
                                    if (message.indexOf("VOLUME_DEC") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                        setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                                        setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                                    }
                                    if (message.indexOf("VOLUME_INC") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                        setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                                        setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                                    }
                                    if (message.indexOf("VOLUME_UNMUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                        setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_MUTE", false, true)
                                    }
                                    if (message.indexOf("VOLUME_MUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                        setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_MUTE", true, true)
                                    }
                                    if (message.indexOf("RADIO_OFF") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                        setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", false, true);
                                        setState(pfad + radio.pfad + "." + "POWER", "OFF");
                                    }
                                    if (message.indexOf("RADIO_ON") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                        setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", true, true);
                                        setState(pfad + radio.pfad + "." + "POWER", "ON");
                                    }
                                } else if (command == "PLAY") {
                                    if (message.indexOf("STATION") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                        setState(pfad + radio.pfad + "." + "COMMAND.PLAY_STATION", parseInt(findstr("STATION:", message)), true);
                                        setState(pfad + radio.pfad + "." + "STATION_ID_PLAYING", parseInt(findstr("STATION:", message)), true);
                                        setState(pfad + radio.pfad + "." + "STATION_PLAYING", findstr("PLAYING:", message), true);
                                    }
                                } else {
                                
                                    if (logging) log('unexpected message: ' + message);
                                
                                }
                                });
                                 
                                // starten der Abfragen nach Empfang von Broadcasts
                                /* var timer = null;
                                 
                                server2.on('message', function (message, remote) {
                                    if (timer) clearTimeout(timer);
                                    if (logging) log('Broadcast vom Radio: ' + message);
                                    if (logging) log(JSON.stringify(message));
                                    //var obj = JSON.parse('{'+message+'}');
                                    sendcmd(buf2);
                                    timer = setTimeout(function () {
                                        sendcmd(buf3);
                                    }, 1000);
                                }); */
                                function findstr(name, str) {
                                    var suchstring = String(name);
                                    var teststring = String(str);
                                    var pos = parseInt(teststring.indexOf(suchstring) + suchstring.length);
                                    var zaehler = parseInt(pos) + 1;
                                    //log("String: " + suchstring + "befindet sich an " + pos + " Stelle")
                                    do {
                                        var Zeichen = String(teststring).charCodeAt(zaehler);
                                        //log ("Zeichen: " + Zeichen + " Zähler: " + (zaehler - pos));
                                        zaehler = zaehler + 1;
                                    } while (Zeichen != 13 && zaehler - pos <= 100);
                                 
                                 
                                    //log("Start: " + pos + "Ende: " + zaehler);
                                    var ergebnis = String(str).substring(pos, zaehler - 1);
                                    if (teststring.indexOf(suchstring) == -1) {
                                        ergebnis = ""
                                    };
                                 
                                    //log("Objekt: " + name + " Wert: '" + ergebnis + "'");
                                    return ergebnis
                                }
                                 
                                 
                                function sendcmd(cmd) {
                                    radios.forEach(radio=>{       
                                    socket.send(cmd, 0, cmd.length, UDPPort, radio.IP, function (err, result) {
                                        if (err) log('Fehler Senden ' + cmd, 'error');
                                        else {
                                            if (logging) log('Kommando gesendet: ' + cmd);
                                        }
                                    });})   
                                }
                                
                                function sendcmdToIp(cmd,IP) {    
                                    socket.send(cmd, 0, cmd.length, UDPPort, IP, function (err, result) {
                                        if (err) log('Fehler Senden ' + cmd, 'error');
                                        else {
                                            if (logging) log('Kommando gesendet: ' + cmd);
                                        }
                                    });   
                                }
                                
                                //einmalige Ausführung beim  Starten des Skriptes
                                sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                                sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                                sendcmd('COMMAND:GET\r\nINFO_BLOCK\r\nID:ioBroker\r\n\r\n');
                                sendcmd('COMMAND:GET\r\nPLAYING_MODE\r\nID:ioBroker\r\n\r\n');
                                sendcmd('COMMAND:GET\r\nALL_STATION_INFO\r\nID:ioBroker\r\n\r\n');
                                
                                 
                                var timer1 = null;
                                var timer2 = null;
                                var timer3 = null;
                                var timer4 = null;
                                schedule('*/1 * * * *', function () {  // jede Minute die wichtigsten Infos aktualisieren
                                 
                                    if (timer1) clearTimeout(timer1);
                                    timer1 = setTimeout(function () {
                                        sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                                    }, 1000);
                                    if (timer2) clearTimeout(timer2);
                                    timer2 = setTimeout(function () {
                                        sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                                    }, 2000);
                                    if (timer3) clearTimeout(timer3);
                                    timer3 = setTimeout(function () {
                                        sendcmd('COMMAND:GET\r\nINFO_BLOCK\r\nID:ioBroker\r\n\r\n');
                                    }, 3000);
                                    if (timer4) clearTimeout(timer4);
                                    timer4 = setTimeout(function () {
                                        sendcmd('COMMAND:GET\r\nPLAYING_MODE\r\nID:ioBroker\r\n\r\n');
                                    }, 4000);
                                });
                                 
                                schedule('*/30 * * * *', function () {  // alle 30 Minuten die Stationsliste aktualisieren
                                    sendcmd('COMMAND:GET\r\nALL_STATION_INFO\r\nID:ioBroker\r\n\r\n');
                                });
                                
                                const initOnForAllRadios =()=>{
                                    radios.forEach(radio=>
                                    {
                                      on({ id: pfad2 + radio.pfad + ".COMMAND.VOLUME_INC", val: true }, function (obj) {                        
                                            
                                                 sendcmdToIp('COMMAND:SET\r\nVOLUME_INC\r\nID:ioBroker\r\n\r\n',radio.IP);
                                                 sendcmdToIp('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n',radio.IP);
                                             });                                                                         
                                
                                       on({ id: pfad2 + radio.pfad + ".COMMAND.VOLUME_DEC", val: true }, function (obj) {        
                                         sendcmdToIp('COMMAND:SET\r\nVOLUME_DEC\r\nID:ioBroker\r\n\r\n',radio.IP);
                                         sendcmdToIp('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n',radio.IP);});
                                       on({ id: pfad2  + radio.pfad + ".COMMAND.VOLUME_MUTE", change: "ne" }, function (obj) {            
                                            if (obj.state.val === true) {
                                                sendcmdToIp('COMMAND:SET\r\nVOLUME_MUTE\r\nID:ioBroker\r\n\r\n',radio.IP);}
                                            if (obj.state.val === false) {
                                              sendcmdToIp('COMMAND:SET\r\nVOLUME_UNMUTE\r\nID:ioBroker\r\n\r\n',radio.IP);
                                            }
                                         sendcmdToIp('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n',radio.IP);
                                         });
                                       on({ id: pfad2 +radio.pfad+ ".COMMAND.RADIO_ON", change: "ne", ack: false }, function (obj) {    
                                                if (obj.state.val === true) 
                                                    sendcmdToIp('COMMAND:SET\r\nRADIO_ON\r\nID:ioBroker\r\n\r\n',radio.IP);                
                                                if (obj.state.val === false) 
                                                    sendcmdToIp('COMMAND:SET\r\nRADIO_OFF\r\nID:ioBroker\r\n\r\n',radio.IP);    
                                                sendcmdToIp('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n',radio.IP);});
                                      on({ id: pfad2 +radio.pfad+ ".COMMAND.PLAY_STATION", change: "ne", ack: false }, function (obj) {    
                                        if (obj.state.val <= 8 && obj.state.val > 0) {
                                            sendcmdToIp('COMMAND:PLAY\r\nSTATION:' + obj.state.val + '\r\nID:ioBroker\r\n\r\n',radio.IP);}}); 
                                      on({ id: pfad2+radio.pfad + ".COMMAND.VOLUME_SET", change: "ne", ack: false }, function (obj) {    
                                        if (obj.state.val <= 31 && obj.state.val >= 0) {
                                            sendcmdToIp('COMMAND:SET\r\nVOLUME_ABSOLUTE:' + obj.state.val + '\r\nID:ioBroker\r\n\r\n',radio.IP);}});         
                                    });
                                };
                                initOnForAllRadios();
                                

                                das Skript einach nur stoppen und starten reicht glaube ich nicht du musst den ganzen javascript adapter neustarten, da die port weiter belegt sind wenn du nur das skript neustartest.
                                geil wäre es wenn du mal so ne message von so einem radio posten könntest.
                                ich hatte es bei mir mit nen fake udp radio local getestet , da scheinen die meldung im borker anzukommen ich kann leider nicht ne genau message von so nem radio simulieren , da ich nicht weiß wie die aussieht.
                                grüße

                                E Offline
                                E Offline
                                Eaterhnk
                                schrieb am zuletzt editiert von
                                #23

                                Ja super, werde ich ausprobieren! Komme aber erst am Wochenende dazu. Besten Dank!

                                1 Antwort Letzte Antwort
                                0
                                • E Offline
                                  E Offline
                                  Eaterhnk
                                  schrieb am zuletzt editiert von
                                  #24

                                  Guten Abend,

                                  das Skript läuft einwandfrei. Musste den Java Adapter stoppen. Dann hat es geklappt. Vielen Dank!
                                  Welche Message möchtest du sehen bzw. was muss ich dafür tun?

                                  N 1 Antwort Letzte Antwort
                                  0
                                  • E Eaterhnk

                                    Guten Abend,

                                    das Skript läuft einwandfrei. Musste den Java Adapter stoppen. Dann hat es geklappt. Vielen Dank!
                                    Welche Message möchtest du sehen bzw. was muss ich dafür tun?

                                    N Offline
                                    N Offline
                                    Nahasapee
                                    schrieb am zuletzt editiert von
                                    #25

                                    @Eaterhnk na wenn es geht, dann nichts mehr da hab ich wahrscheinlich richtig geraten ;)

                                    1 Antwort Letzte Antwort
                                    0
                                    • CKOC Offline
                                      CKOC Offline
                                      CKO
                                      schrieb am zuletzt editiert von
                                      #26

                                      Hi,

                                      ich nutze auch seit neustem das Script mit meinem iNet Radio und es funktioniert hervorragend. Ich erhalte seit der Nutzung allerding im ioBroker Log immer Warnings mit "has been written without ack-flag"

                                      Kann man das noch irgendwie fix, um das Log nicht voll zu müllen? Ich weis alternativ kann man das Log Level erhöhen auf Critical, aber dann gilt das m.M. für alle JS-Skripte und das will ich eigentlich nicht.

                                      
                                      javascript.0
                                      2022-01-03 10:04:04.056	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.STATION_PLAYING" has been written without ack-flag with value "90.4 | MDR JUMP (Adult Contemporary)"
                                      
                                      javascript.0
                                      2022-01-03 10:04:04.055	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.STATION_URL_PLAYING" has been written without ack-flag with value "http://opml.radiotime.com/Tune.ashx?id=s6634&formats=mp3,aac,ogg&partnerId=TrOI9LnX&serial=7947330E"
                                      
                                      javascript.0
                                      2022-01-03 10:04:04.055	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.STATION_ID_PLAYING" has been written without ack-flag with value ""
                                      
                                      javascript.0
                                      2022-01-03 10:04:04.054	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.PLAYING" has been written without ack-flag with value "TUNEIN"
                                      
                                      javascript.0
                                      2022-01-03 10:04:04.052	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.PLAYING_MODE" has been written without ack-flag with value ""
                                      
                                      javascript.0
                                      2022-01-03 10:04:04.051	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.ID" has been written without ack-flag with value "ioBroker"
                                      
                                      javascript.0
                                      2022-01-03 10:04:04.049	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.Command" has been written without ack-flag with value "GET"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.044	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.WLAN-FW" has been written without ack-flag with value "Drv 1.3.5 FW 1.3.25"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.044	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.SW-VERSION" has been written without ack-flag with value "03.12"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.044	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.SERIAL_NR" has been written without ack-flag with value "xxxxxxxxxxxxx"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.042	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.COUNTRY" has been written without ack-flag with value "Deutschland"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.040	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.MAC_ADRESS" has been written without ack-flag with value "00:00:00:00:00:00"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.039	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.SSID" has been written without ack-flag with value "XXXX"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.039	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.GATEWAY" has been written without ack-flag with value "192.168.x.x"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.038	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.IPMODE" has been written without ack-flag with value "ON"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.038	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.IPMASK" has been written without ack-flag with value "255.255.255.x"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.038	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.IPADDR" has been written without ack-flag with value "192.168.x.x"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.037	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.ID" has been written without ack-flag with value "ioBroker"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.037	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.NAME" has been written without ack-flag with value "RADIO-BAD-OG"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.036	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.WLAN_STRENGTH" has been written without ack-flag with value "-64"
                                      
                                      javascript.0
                                      2022-01-03 10:04:03.035	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.Command" has been written without ack-flag with value "GET"
                                      
                                      javascript.0
                                      2022-01-03 10:04:02.039	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.VOLUME" has been written without ack-flag with value "16"
                                      
                                      javascript.0
                                      2022-01-03 10:04:02.037	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.ID" has been written without ack-flag with value "ioBroker"
                                      
                                      javascript.0
                                      2022-01-03 10:04:02.036	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.Command" has been written without ack-flag with value "GET"
                                      
                                      javascript.0
                                      2022-01-03 10:04:01.040	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.ENERGY_MODE" has been written without ack-flag with value "PREMIUM"
                                      
                                      javascript.0
                                      2022-01-03 10:04:01.039	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.POWER" has been written without ack-flag with value "ON"
                                      
                                      javascript.0
                                      2022-01-03 10:04:01.038	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.ID" has been written without ack-flag with value "ioBroker"
                                      
                                      javascript.0
                                      2022-01-03 10:04:01.038	warn	Read-only state "javascript.0.Geraete.BuschJaeger.RadioINet.Bad OG.Command" has been written without ack-flag with value "GET
                                      

                                      NODE.JS: V16.18.1
                                      NPM: 8.19.2

                                      1 Antwort Letzte Antwort
                                      0
                                      • crunchipC Abwesend
                                        crunchipC Abwesend
                                        crunchip
                                        Forum Testing Most Active
                                        schrieb am zuletzt editiert von
                                        #27

                                        @cko ich kann zwar überhaupt kein Javascript, aber ich denke, es müsste, da sämtliche angelegten Datenpunkte nicht beschreibbar (write : false)
                                        entsprechend bei setState......am Schluss der Zeile folgendes anhängen, falls nicht schon vorhanden

                                        , true)
                                        

                                        umgestiegen von Proxmox auf Unraid

                                        W 1 Antwort Letzte Antwort
                                        0
                                        • crunchipC crunchip

                                          @cko ich kann zwar überhaupt kein Javascript, aber ich denke, es müsste, da sämtliche angelegten Datenpunkte nicht beschreibbar (write : false)
                                          entsprechend bei setState......am Schluss der Zeile folgendes anhängen, falls nicht schon vorhanden

                                          , true)
                                          
                                          W Offline
                                          W Offline
                                          Weissnicht
                                          schrieb am zuletzt editiert von
                                          #28

                                          @crunchip @CKO

                                          ja, so ist es (wohl). Habe diese Korrektur bei mir bereits vorgenommen, daher hier gerne zum C&P.

                                          Und wirklich, funktioniert prima als Skript! :+1: Aber ein Adapter wäre auch etwas schönes :-)

                                          Off topic: Seit iOS15 ist die Busch Jäger App nicht mal mehr aufrufbar am Telefon

                                          /* Change history:
                                          v1.2
                                          - added ack: true to setstates() command when states are updated by the radio
                                          
                                          v1.1
                                          - comment of line var RadioIpaddress as no longer used due to multi radio support
                                          - found bug: if IP address not correct, the jscript adapter crashes; has to be fixed. How?
                                          - added function onClose to relese the socket binding when script ist stopped / restarted
                                            otherwise restart throws an error due to binding to port not possible as still blocked
                                          
                                          v1.0 script copy of ioBroker forum from user intruder7
                                          */
                                          
                                          var pfad = 'Geraete.BuschJaeger.RadioINet.';
                                          var pfad2 = 'javascript.0.' + pfad
                                           // vollständiger id Pfad wird: pfad2 + radio.pfad
                                          
                                          var UDPListenPort = 4242; //nicht ändern 
                                          var UDPPort = 4244; //nicht ändern 
                                          // var RadioIPadress = '192.168.2.67' // IP Adresse des Radios
                                          var HOST = '0.0.0.0'; //nicht ändern 
                                          
                                          var logging = false;
                                           
                                          /* ToDo: 
                                          - wenn IP nicht korrekt, stürzt der komplette jscript Adapter ab!
                                            Grund: Das sende-Kommando kann nicht gebaut werden: radio.path ist undefined für die IP
                                          - Prüfen, ob sendcmd und sendcmdToIP vereinheitlicht werden kann
                                            sendcmd: sendet an alle Radios
                                            sendcmdToIP: sendet nur an ein bestimmtes Radio
                                          */
                                          
                                          const radios =  [
                                               {
                                                       IP: '192.168.2.67',
                                                       pfad: 'Bad'
                                               }/*,
                                              {
                                                       IP: '192.168.100.74',
                                                       pfad: 'Keller'
                                                      }        */
                                          ];
                                          
                                          
                                          // ab hier nichts mehr ändern 
                                          
                                          var dgram = require('dgram');
                                          var socket = dgram.createSocket('udp4');
                                          var server = dgram.createSocket('udp4');
                                          //var server2 = dgram.createSocket('udp4');
                                           
                                          
                                          const getRadioForIP= (IP)=>{
                                              return radios.find(radio=>radio.IP == IP )
                                          }
                                          
                                          const createAllStates = ()=>{    
                                              radios.forEach((radio)=>{createRadioState(radio);});    
                                          };
                                          
                                          const createRadioState = (radio)=>{
                                          createState(pfad+ radio.pfad +"."+ "Command", '', { type: 'string', name: 'Last command', write: false });
                                          createState(pfad+ radio.pfad +"."+ "WLAN_STRENGTH", '', { type: 'string', name: 'WLAN strength', write: false, unit: 'dBm' });
                                          createState(pfad+ radio.pfad +"."+ "NAME", '', { type: 'string', name: 'Name of radio', write: false });
                                          createState(pfad+ radio.pfad +"."+ "ID", '', { type: 'string', name: 'UDP ID', write: false });
                                          createState(pfad+ radio.pfad +"."+ "IPADDR", '', { type: 'string', name: 'IP adress', write: false });
                                          createState(pfad+ radio.pfad +"."+ "IPMASK", '', { type: 'string', name: 'IP Mask', write: false });
                                          createState(pfad+ radio.pfad +"."+ "IPMODE", '', { type: 'string', name: 'IP  Mode', write: false });
                                          createState(pfad+ radio.pfad +"."+ "GATEWAY", '', { type: 'string', name: 'Gateway', write: false });
                                          createState(pfad+ radio.pfad +"."+ "SSID", '', { type: 'string', name: 'SSID', write: false });
                                          createState(pfad+ radio.pfad +"."+ "MAC_ADRESS", '', { type: 'string', name: 'MAC adress', write: false });
                                          createState(pfad+ radio.pfad +"."+ "COUNTRY", '', { type: 'string', name: 'Country', write: false });
                                          createState(pfad+ radio.pfad +"."+ "SERIAL_NR", '', { type: 'string', name: 'Serial Nr', write: false });
                                          createState(pfad+ radio.pfad +"."+ "SW-VERSION", '', { type: 'string', name: 'Software version', write: false });
                                          createState(pfad+ radio.pfad +"."+ "WLAN-FW", '', { type: 'string', name: 'WLAN Firmware', write: false });
                                          
                                          createState(pfad +radio.pfad+ "." + "POWER", '', { type: 'string', name: 'Current state of radio', write: false });
                                          createState(pfad +radio.pfad+ "." + "ENERGY_MODE", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "VOLUME", '', { type: 'number', name: 'VOLUME', write: false });
                                          createState(pfad +radio.pfad+ "." + "PLAYING_MODE", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "PLAYING", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATION_ID_PLAYING", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATION_URL_PLAYING", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATION_PLAYING", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "TUNEIN_ID", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "TUNEIN_SNR", '', { type: 'string', name: '', write: false });
                                          
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_1_NAME", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_1_URL", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_2_NAME", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_2_URL", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_3_NAME", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_3_URL", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_4_NAME", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_4_URL", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_5_NAME", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_5_URL", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_6_NAME", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_6_URL", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_7_NAME", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_7_URL", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_8_NAME", '', { type: 'string', name: '', write: false });
                                          createState(pfad +radio.pfad+ "." + "STATIONS.STATION_8_URL", '', { type: 'string', name: '', write: false });
                                          
                                          createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_INC", false, { type: 'boolean', name: '', read: false, write: true, role: 'button' });
                                          createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_DEC", false, { type: 'boolean', name: '', read: false, write: true, role: 'button' });
                                          createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_MUTE", false, { type: 'boolean', name: '', read: false, write: true, role: 'switch' });
                                          createState(pfad + radio.pfad +"." + "COMMAND.RADIO_ON", false, { type: 'boolean', name: '', read: false, write: true, role: 'switch' });
                                          createState(pfad + radio.pfad +"." + "COMMAND.PLAY_STATION", 1, { type: 'number', name: 'PLAYING STATION 1-8', read: false, write: true });
                                          createState(pfad + radio.pfad +"." + "COMMAND.VOLUME_SET", 1, { type: 'number', name: 'SET VOLUME 0-31', read: false, write: true });
                                          };
                                          
                                          createAllStates();
                                           server.on('error', (err) => {
                                              log(`server error:\n${err.stack}`);
                                              server.close();
                                          });
                                          
                                          server.on('listening', function () {
                                              var address = server.address();
                                              log('UDP Server listening on ' + address.address + ":" + address.port);
                                          });
                                          
                                          try{
                                          server.bind(UDPListenPort);
                                          }
                                          
                                          catch(error){console.log(error);}
                                           
                                          
                                          /* server2.on('listening', function () {
                                          
                                              server2.setBroadcast(true);
                                          
                                              server2.setMulticastLoopback(true);
                                          
                                              var address = server2.address();
                                          
                                             log('UDP Server 2 listening on ' + address.address + ":" + address.port);
                                          
                                          });
                                          
                                          server2.bind(PORT2, HOST); */
                                          
                                           
                                          
                                          // Antworten vom Radio auf Abfragen
                                          
                                          server.on('message', function (message, remote) {   
                                              if (logging) log('(148) Meldung vom RADIO: ' + message);
                                              const radio = getRadioForIP(remote.address);
                                              var command = findstr("COMMAND:", message);
                                              if (command == "GET") {
                                          
                                              if (message.indexOf("INFO_BLOCK") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "WLAN_STRENGTH", findstr("WLAN STRENGTH:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "NAME", findstr("NAME:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "IPADDR", findstr("IPADDR:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "IPMASK", findstr("IPMASK:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "IPMODE", findstr("IPMODE:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "GATEWAY", findstr("GATEWAY:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "SSID", findstr("SSID:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "MAC_ADRESS", findstr("MAC:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "COUNTRY", findstr("COUNTRY:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "SERIAL_NR", findstr("SERNO:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "SW-VERSION", findstr("SW-VERSION:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "WLAN-FW", findstr("WLAN-FW:", message),true);
                                          
                                              } else if (message.indexOf("VOLUME") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)),true);
                                          
                                                  if (parseInt(findstr("VOLUME_SET:", message)) >= 0 && parseInt(findstr("VOLUME_SET:", message)) <= 31 && message.indexOf("RESPONSE:ACK") >= 0) {
                                          
                                                      setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true);
                                          
                                                  }
                                          
                                              } else if (message.indexOf("POWER_STATUS") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "POWER", findstr("POWER:", message),true);
                                          
                                                  if (findstr("POWER:", message) == "ON") {
                                          
                                                      setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", true, true)
                                          
                                                  } else if (findstr("POWER:", message) == "OFF") {
                                          
                                                      setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", false, true)
                                          
                                                  };
                                          
                                                  setState(pfad + radio.pfad + "." + "ENERGY_MODE", findstr("ENERGY_MODE:", message),true);
                                          
                                              } else if (message.indexOf("TUNEIN_PARTNER_ID") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "TUNEIN_ID", findstr("PARTNERID:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "TUNEIN_SNR", findstr("SERNO:", message),true);
                                          
                                              } else if (message.indexOf("ALL_STATION_INFO") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_1_NAME", findstr("1\r\nNAME:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_1_URL", findstr(findstr("1\r\nNAME:", message) + '\r\nURL:', message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_2_NAME", findstr("2\r\nNAME:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_2_URL", findstr(findstr("2\r\nNAME:", message) + '\r\nURL:', message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_3_NAME", findstr("3\r\nNAME:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_3_URL", findstr(findstr("3\r\nNAME:", message) + '\r\nURL:', message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_4_NAME", findstr("4\r\nNAME:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_4_URL", findstr(findstr("4\r\nNAME:", message) + '\r\nURL:', message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_5_NAME", findstr("5\r\nNAME:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_5_URL", findstr(findstr("5\r\nNAME:", message) + '\r\nURL:', message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_6_NAME", findstr("6\r\nNAME:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_6_URL", findstr(findstr("6\r\nNAME:", message) + '\r\nURL:', message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_7_NAME", findstr("7\r\nNAME:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_7_URL", findstr(findstr("7\r\nNAME:", message) + '\r\nURL:', message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_8_NAME", findstr("8\r\nNAME:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATIONS.STATION_8_URL", findstr(findstr("8\r\nNAME:", message) + '\r\nURL:', message),true);
                                          
                                              } else if (message.indexOf("PLAYING_MODE") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "ID", findstr("ID:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "PLAYING_MODE", findstr("MODE:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "PLAYING", findstr("PLAYING:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATION_ID_PLAYING", findstr("N\r\nID:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATION_URL_PLAYING", findstr("URL:", message),true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATION_PLAYING", findstr("NAME:", message),true);
                                          
                                              };
                                          
                                          } else if (command == "NOTIFICATION") {
                                          
                                              var event = findstr("EVENT:", message);
                                          
                                              setState(pfad + radio.pfad + "." + "Command", findstr("COMMAND:", message),true);
                                          
                                              setState(pfad + radio.pfad + "." + "IPADDR", findstr("IP:", message),true);
                                          
                                              setState(pfad + radio.pfad + "." + "NAME", findstr("NAME:", message),true);
                                          
                                              if (logging) log("Event = '" + event + "'");
                                          
                                             
                                          
                                              if (event == 'POWER_OFF' || event == 'POWER_ON') {
                                          
                                                  sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                                          
                                              };
                                          
                                              if (event == "VOLUME_CHANGED") {
                                          
                                                  sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                                          
                                              };
                                          
                                              if (event == 'STATION_CHANGED') {
                                          
                                              };
                                          
                                          } else if (command == "SET") {
                                          
                                              if (message.indexOf("VOLUME_ABSOLUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                                          
                                                  setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                                          
                                              }
                                          
                                              if (message.indexOf("VOLUME_DEC") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                                          
                                                  setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                                          
                                              }
                                          
                                              if (message.indexOf("VOLUME_INC") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "VOLUME", parseInt(findstr("VOLUME_SET:", message)), true);
                                          
                                                  setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_SET", parseInt(findstr("VOLUME_SET:", message)), true)
                                          
                                              }
                                          
                                              if (message.indexOf("VOLUME_UNMUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_MUTE", false, true)
                                          
                                              }
                                          
                                              if (message.indexOf("VOLUME_MUTE") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "COMMAND.VOLUME_MUTE", true, true)
                                          
                                              }
                                          
                                              if (message.indexOf("RADIO_OFF") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", false, true);
                                          
                                                  setState(pfad + radio.pfad + "." + "POWER", "OFF",true);
                                          
                                              }
                                          
                                              if (message.indexOf("RADIO_ON") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "COMMAND.RADIO_ON", true, true);
                                          
                                                  setState(pfad + radio.pfad + "." + "POWER", "ON",true);
                                          
                                              }
                                          
                                          } else if (command == "PLAY") {
                                          
                                              if (message.indexOf("STATION") >= 0 && message.indexOf("RESPONSE:ACK") >= 0) {
                                          
                                                  setState(pfad + radio.pfad + "." + "COMMAND.PLAY_STATION", parseInt(findstr("STATION:", message)), true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATION_ID_PLAYING", parseInt(findstr("STATION:", message)), true);
                                          
                                                  setState(pfad + radio.pfad + "." + "STATION_PLAYING", findstr("PLAYING:", message), true);
                                          
                                              }
                                          
                                          } else {
                                          
                                           
                                          
                                              if (logging) log('unexpected message: ' + message);
                                          
                                           
                                          
                                          }
                                          
                                          });
                                          
                                           
                                          
                                          // starten der Abfragen nach Empfang von Broadcasts
                                          
                                          /* var timer = null;
                                          
                                           
                                          
                                          server2.on('message', function (message, remote) {
                                          
                                              if (timer) clearTimeout(timer);
                                          
                                              if (logging) log('Broadcast vom Radio: ' + message);
                                          
                                              if (logging) log(JSON.stringify(message));
                                          
                                              //var obj = JSON.parse('{'+message+'}');
                                          
                                              sendcmd(buf2);
                                          
                                              timer = setTimeout(function () {
                                          
                                                  sendcmd(buf3);
                                          
                                              }, 1000);
                                          
                                          }); */
                                          
                                          function findstr(name, str) {
                                          
                                              var suchstring = String(name);
                                          
                                              var teststring = String(str);
                                          
                                              var pos = (teststring.indexOf(suchstring) + suchstring.length);
                                          
                                              var zaehler = (pos) + 1;
                                          
                                              //log("String: " + suchstring + "befindet sich an " + pos + " Stelle")
                                          
                                              do {
                                          
                                                  var Zeichen = String(teststring).charCodeAt(zaehler);
                                          
                                                  //log ("Zeichen: " + Zeichen + " Zähler: " + (zaehler - pos));
                                          
                                                  zaehler = zaehler + 1;
                                          
                                              } while (Zeichen != 13 && zaehler - pos <= 100);
                                          
                                           
                                          
                                           
                                          
                                              //log("Start: " + pos + "Ende: " + zaehler);
                                          
                                              var ergebnis = String(str).substring(pos, zaehler - 1);
                                          
                                              if (teststring.indexOf(suchstring) == -1) {
                                          
                                                  ergebnis = ""
                                          
                                              };
                                          
                                           
                                          
                                              //log("Objekt: " + name + " Wert: '" + ergebnis + "'");
                                          
                                              return ergebnis
                                          
                                          }
                                          
                                           
                                          
                                           
                                          
                                          function sendcmd(cmd) {
                                          
                                              radios.forEach(radio=>{       
                                          
                                              socket.send(cmd, 0, cmd.length, UDPPort, radio.IP, function (err, result) {
                                          
                                                  if (err) log('Fehler Senden ' + cmd, 'error');
                                          
                                                  else {
                                          
                                                      if (logging) log('(477) Kommando gesendet: ' + cmd);
                                          
                                                  }
                                          
                                              });})   
                                          
                                          }
                                          
                                           
                                          
                                          function sendcmdToIp(cmd,IP) {    
                                          
                                              socket.send(cmd, 0, cmd.length, UDPPort, IP, function (err, result) {
                                          
                                                  if (err) log('Fehler Senden ' + cmd, 'error');
                                          
                                                  else {
                                          
                                                      if (logging) log('(495) Kommando gesendet: ' + cmd);
                                          
                                                  }
                                          
                                              });   
                                          
                                          }
                                          
                                           
                                          
                                          //einmalige Ausführung beim  Starten des Skriptes
                                          
                                          sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                                          
                                          sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                                          
                                          sendcmd('COMMAND:GET\r\nINFO_BLOCK\r\nID:ioBroker\r\n\r\n');
                                          
                                          sendcmd('COMMAND:GET\r\nPLAYING_MODE\r\nID:ioBroker\r\n\r\n');
                                          
                                          sendcmd('COMMAND:GET\r\nALL_STATION_INFO\r\nID:ioBroker\r\n\r\n');
                                          
                                           
                                          
                                           
                                          
                                          var timer1 = null;
                                          
                                          var timer2 = null;
                                          
                                          var timer3 = null;
                                          
                                          var timer4 = null;
                                          
                                          schedule('*/1 * * * *', function () {  // jede Minute die wichtigsten Infos aktualisieren
                                          
                                           
                                          
                                              if (timer1) clearTimeout(timer1);
                                          
                                              timer1 = setTimeout(function () {
                                          
                                                  sendcmd('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n');
                                          
                                              }, 1000);
                                          
                                              if (timer2) clearTimeout(timer2);
                                          
                                              timer2 = setTimeout(function () {
                                          
                                                  sendcmd('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n');
                                          
                                              }, 2000);
                                          
                                              if (timer3) clearTimeout(timer3);
                                          
                                              timer3 = setTimeout(function () {
                                          
                                                  sendcmd('COMMAND:GET\r\nINFO_BLOCK\r\nID:ioBroker\r\n\r\n');
                                          
                                              }, 3000);
                                          
                                              if (timer4) clearTimeout(timer4);
                                          
                                              timer4 = setTimeout(function () {
                                          
                                                  sendcmd('COMMAND:GET\r\nPLAYING_MODE\r\nID:ioBroker\r\n\r\n');
                                          
                                              }, 4000);
                                          
                                          });
                                          
                                           
                                          
                                          schedule('*/30 * * * *', function () {  // alle 30 Minuten die Stationsliste aktualisieren
                                          
                                              sendcmd('COMMAND:GET\r\nALL_STATION_INFO\r\nID:ioBroker\r\n\r\n');
                                          
                                          });
                                          
                                           
                                          
                                          const initOnForAllRadios =()=>{
                                          
                                              radios.forEach(radio=>
                                          
                                              {
                                          
                                                on({ id: pfad2 + radio.pfad + ".COMMAND.VOLUME_INC", val: true }, function (obj) {                        
                                          
                                                      
                                          
                                                           sendcmdToIp('COMMAND:SET\r\nVOLUME_INC\r\nID:ioBroker\r\n\r\n',radio.IP);
                                          
                                                           sendcmdToIp('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n',radio.IP);
                                          
                                                       });                                                                         
                                          
                                           
                                          
                                                 on({ id: pfad2 + radio.pfad + ".COMMAND.VOLUME_DEC", val: true }, function (obj) {        
                                          
                                                   sendcmdToIp('COMMAND:SET\r\nVOLUME_DEC\r\nID:ioBroker\r\n\r\n',radio.IP);
                                          
                                                   sendcmdToIp('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n',radio.IP);});
                                          
                                                 on({ id: pfad2  + radio.pfad + ".COMMAND.VOLUME_MUTE", change: "ne" }, function (obj) {            
                                          
                                                      if (obj.state.val === true) {
                                          
                                                          sendcmdToIp('COMMAND:SET\r\nVOLUME_MUTE\r\nID:ioBroker\r\n\r\n',radio.IP);}
                                          
                                                      if (obj.state.val === false) {
                                          
                                                        sendcmdToIp('COMMAND:SET\r\nVOLUME_UNMUTE\r\nID:ioBroker\r\n\r\n',radio.IP);
                                          
                                                      }
                                          
                                                   sendcmdToIp('COMMAND:GET\r\nVOLUME\r\nID:ioBroker\r\n\r\n',radio.IP);
                                          
                                                   });
                                          
                                                 on({ id: pfad2 +radio.pfad+ ".COMMAND.RADIO_ON", change: "ne", ack: false }, function (obj) {    
                                          
                                                          if (obj.state.val === true) 
                                          
                                                              sendcmdToIp('COMMAND:SET\r\nRADIO_ON\r\nID:ioBroker\r\n\r\n',radio.IP);                
                                          
                                                          if (obj.state.val === false) 
                                          
                                                              sendcmdToIp('COMMAND:SET\r\nRADIO_OFF\r\nID:ioBroker\r\n\r\n',radio.IP);    
                                          
                                                          sendcmdToIp('COMMAND:GET\r\nPOWER_STATUS\r\nID:ioBroker\r\n\r\n',radio.IP);});
                                          
                                                on({ id: pfad2 +radio.pfad+ ".COMMAND.PLAY_STATION", change: "ne", ack: false }, function (obj) {    
                                          
                                                  if (obj.state.val <= 8 && obj.state.val > 0) {
                                          
                                                      sendcmdToIp('COMMAND:PLAY\r\nSTATION:' + obj.state.val + '\r\nID:ioBroker\r\n\r\n',radio.IP);}}); 
                                          
                                                on({ id: pfad2+radio.pfad + ".COMMAND.VOLUME_SET", change: "ne", ack: false }, function (obj) {    
                                          
                                                  if (obj.state.val <= 31 && obj.state.val >= 0) {
                                          
                                                      sendcmdToIp('COMMAND:SET\r\nVOLUME_ABSOLUTE:' + obj.state.val + '\r\nID:ioBroker\r\n\r\n',radio.IP);}});         
                                          
                                              });
                                          
                                          };
                                          
                                          initOnForAllRadios();
                                          
                                          onStop(() => { 
                                          
                                              socket.close();
                                              server.close();
                                          
                                          });
                                          
                                          MaigoldM 1 Antwort Letzte Antwort
                                          0
                                          Antworten
                                          • In einem neuen Thema antworten
                                          Anmelden zum Antworten
                                          • Älteste zuerst
                                          • Neuste zuerst
                                          • Meiste Stimmen


                                          Support us

                                          ioBroker
                                          Community Adapters
                                          Donate

                                          759

                                          Online

                                          32.4k

                                          Benutzer

                                          81.4k

                                          Themen

                                          1.3m

                                          Beiträge
                                          Community
                                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                                          ioBroker Community 2014-2025
                                          logo
                                          • Anmelden

                                          • Du hast noch kein Konto? Registrieren

                                          • Anmelden oder registrieren, um zu suchen
                                          • Erster Beitrag
                                            Letzter Beitrag
                                          0
                                          • Home
                                          • Aktuell
                                          • Tags
                                          • Ungelesen 0
                                          • Kategorien
                                          • Unreplied
                                          • Beliebt
                                          • GitHub
                                          • Docu
                                          • Hilfe