NEWS
[Vorlage] Busch Jäger Radio iNet 8216 U
-
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 einconsole.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. -
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: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 Funktionierenfü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'); // } // });
-
@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 -
@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
-
@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. -
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 -
Ja super, werde ich ausprobieren! Komme aber erst am Wochenende dazu. Besten Dank!
-
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? -
@Eaterhnk na wenn es geht, dann nichts mehr da hab ich wahrscheinlich richtig geraten
-
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
-
@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)
-
ja, so ist es (wohl). Habe diese Korrektur bei mir bereits vorgenommen, daher hier gerne zum C&P.
Und wirklich, funktioniert prima als Skript! 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(); });
-
Habe das Script für meine 3 Radios implementiert - was soll ich sagen: ein Traum!
Nur eine Sache bekomme ich nicht hin, ich habe alle Radios auch mit AUX-In belegt und streame so zentral Musik auf die Räume, bekomme aber die Umstellung/COMMAND Punkt für PLAYING nicht hin. Hatte verstanden, dass dieser entweder auf STATION oder AUX_IDCOCK stehen muss.
Irgendjemand eine Idee wie man das im Script anpassen muss? -
@maigold kann ich leider nicht weiterhelfen
-
@maigold
In Zwischenzeit ist auch ein adapter dafür erschienen, hast du den mal getestet? -
@e-s wirklich?
Gar nicht mitbekommen -
@e-s
Kann nichts dazu finden - hast Du einen Link o.ä.? -
-
@e-s
Ah, danke!
Interessant, hätte ich nie gefundenSieht auf den ersten Blick noch rudimentär aus aber werde ich bei Gelegenheit mal testen.
Mit dem Skript läuft es ganz gut. Lediglich der Erfolg, die Lautstärke automatisch anzupassen, wenn das Radio (z.B. spät Abends) eingeschaltet wird, ist vom Zeitpunkt des Befehls abhängig, ob es klappt.
Naja, gut zu wissen. -
Habe den Adapter mal ausprobiert und der funktioniert mal gar nicht.
Außer der IP und eine PIN kann man nichts konfigurieren bzw. falsch machen. Eine PIN braucht der 8216 U nicht, aber egal, ob leer gelassen oder eine Random-PIN eingegeben, der Adapter stürzt ab.
Wenn jemand hier andere Erfahrungen macht, bitte man Ping!