Aller au contenu

Messages recommandés

Posté(e)

T'as quoi dans le debug du main loop ? Active le àtrue dans le code.

Tu peux aussi regarder dans le debug du bouton power voir ce qu'il se passe.

Posté(e)

@Domodial

J'ai trouvé une boucle infinie dans le main loop qui plante l'ampli. Donc tu dois dans l'ordre : modifier le code du main loop avec celui-ci, éteindre l'alimentation complète de ton ampli (tu débranches) et tu rebranches.

-------------------------------------------------------------
-- Plugin for Onkyo TX-NR626 receiver
-- Use port 60128
-- Version 1.1.1 (04-16-2014)
-- Author : Jean-christophe Vermandé modified by BenjyNet
-------------------------------------------------------------
-- Change log 1.1.0 to 1.1.1 :
--  Infinite loop in main loop rectified
--------------------------------------------------------c[_]-

fibaro:debug('Start process Main Loop v1.1.1');

local _deviceIp = fibaro:get(fibaro:getSelfId(), "IPAddress");
local _devicePort = fibaro:get(fibaro:getSelfId(), "TCPPort");
local _maxRetryProcess = 5;
local _trace = false;

-- Polling time (here = 1 min), you can change this
local _polling = 1*60*1000;

-- Name of your inputs, you can change this
input = {
	[00] = "VIDEO1 - VCR/DVR",
	[01] = "VIDEO2 - CBL/SAT",
	[02] = "VIDEO3 - GAME/TV - GAME",
	[03] = "VIDEO4 - AUX",
	[04] = "VIDEO5 - AUX2",
	[05] = "VIDEO6 - PC",
	[16] = "BD/DVD",
	[34] = "PHONO",
	[35] = "TV/CD",
	[36] = "TUNER - FM",
	[37] = "TUNER - AM",
	[38] = "TUNER",
	[41] = "FRONT USB",
	[42] = "REAR USB",
	[43] = "NET",
	[46] = "BLUETOOTH"
};

-- Name of your listenning modes, you can change this
mode = {
	[00] = "STEREO",
	[01] = "DIRECT",
	[02] = "SURROUND",
	[03] = "GAME-RPG",
	[04] = "THX",
	[05] = "GAME-ACTION",
	[06] = "GAME-ROCK",
	[08] = "ORCHESTRA",
	[09] = "UNPLUGGED",
	[10] = "STUDIO-MIX",
	[11] = "TV LOGIC",
	[12] = "ALL CH STEREO",
	[13] = "THEATER-DIMENSIONAL",
	[14] = "GAME-SPORT",
	[15] = "MONO",
	[17] = "PURE AUDIO",
	[19] = "FULL MONO",
	[22] = "AUDISSEY DSX",
	[23] = "WHOLE HOUSE MODE",
	[35] = "STAGE",
	[37] = "ACTION",
	[38] = "MUSIC",
	[46] = "SPORTS",
	[64] = "STRAIGHT DECODE",
	[65] = "DOLBY EX",
	[66] = "THX CINEMA",
	[67] = "THX SURROUND EX",
	[68] = "THX MUSIC",
	[69] = "THX GAMES",
	[80] = "THX CINEMA 2, U2/S2/II/S CINEMA",
	[81] = "THX MUSIC MODE, THX U2/S2/II/S MUSIC",
	[82] = "THX GAMES MODE, THX U2/S2/II/S GAMES",
	[128] = "PLII/PLIIx MOVIE",
	[129] = "PLII/PLIIx MUSIC",
	[130] = "NEO:6 CINEMA/NEO:X CINEMA",
	[131] = "NEO:6 MUSIC/NEO:X MUSIC",
	[132] = "PLII/PLIIx THX CINEMA",
	[133] = "NEO:6/NEO:X THX CINEMA",
	[134] = "PLII/PLIIx GAME",
	[137] = "PLII/PLIIx THX GAMES",
	[140] = "NEO:6/NEO:X THX GAMES",
	[141] = "PLII/PLIIx THX MUSIC",
	[142] = "NEO:6/NEO:X THX MUSIC",
	[144] = "PLIIz HEIGHT",
	[148] = "PLIIz HEIGHT + THX CINEMA",
	[149] = "PLIIz HEIGHT + THX MUSIC",
	[150] = "PLIIz HEIGHT + THX GAMES",
	[151] = "PLIIz HEIGHT + THX U2/S2 CINEMA",
	[152] = "PLIIz HEIGHT + THX U2/S2 MUSIC",
	[153] = "PLIIz HEIGHT + THX U2/S2 GAMES",
	[154] = "NEO:X GAME",
	[160] = "PLIIx/PLII MOVIE + AUDISSEY DSX",
	[161] = "PLIIx/PLII MUSIC + AUDISSEY DSX",
	[162] = "PLIIx/PLII GAME + AUDISSEY DSX",
	[167] = "DOLBY EX + AUDISSEY DSX"
};

-- Device parameters
device = device or {
	id = fibaro:getSelfId(),
	power = 0,
	mute = 0,
	volume = 0,
	source = "unknown",
	lst_mode = "unknown"
};


-- Functions' declarations ------------------------------------
function trace(value)
  if (_trace) then
    return fibaro:debug(tostring(value));
  end
end

function split(pString, pPattern)
   local Table = {}
   local fpat = "(.-)" .. pPattern
   local last_end = 1
   local s, e, cap = pString:find(fpat, 1)
   while s do
          if s ~= 1 or cap ~= "" then
          table.insert(Table,cap)
          end
          last_end = e+1
          s, e, cap = pString:find(fpat, last_end)
   end
   if last_end <= #pString then
          cap = pString:sub(last_end)
          table.insert(Table, cap)
   end
   return Table
end

function getPowerState(retry)
	local retry = retry or 0;
	local cmd = nil;
	--notify user
	trace("Request Power STATUS, #" .. retry .. " please wait...");
	--send packet
	bytes, errorCode = _tcpSocket:write("ISCP\0\0\0\16\0\0\0\12\1\0\0\0\!1PWRQSTN\0x1A\r\n");
	-- check for error
	if errorCode == 0 then
		trace("Power STATUS command successufully transmited.");
    	fibaro:sleep(50);
		-- amplifier sould return the string sent if success
    	while (cmd == nil and retry < _maxRetryProcess) do
			local result = _tcpSocket:read();
			-- check if result is equal than command to confirm success
			trace("Result's lenght : " .. result:len() .. " " .. type(result));
			cmd = string.match(result, "PWR%d%d");
			if (cmd ~= nil) then
				trace(cmd);
				local pwr_value = tonumber(cmd:sub(4,5));
				trace("Result OK : PWR" .. pwr_value);
				return pwr_value;
			else
				trace("Result fail, retry process, #" .. retry .. " please wait...");
				retry = retry + 1;
			end
		end
		return nil;
    else
    	if retry < _maxRetryProcess then
      	trace("Retry process, please wait...");
      	fibaro:sleep(2000);
      	return getPowerState(retry + 1);
      	end
		return nil;
    end
end

function getVolumeLevel(retry)
	local retry = retry or 0;
	local cmd = nil;
	--notify user
	trace("Request Volume LEVEL, #" .. retry .. " please wait...");
	--send packet
	bytes, errorCode = _tcpSocket:write("ISCP\0\0\0\16\0\0\0\12\1\0\0\0\!1MVLQSTN\0x1A\r\n");
	-- check for error
	if errorCode == 0 then
		trace("Request Volume LEVEL command successufully transmited.");
    	fibaro:sleep(50);
		retry = 0;
		-- amplifier sould return the string sent if success
    	while (cmd == nil and retry < _maxRetryProcess) do
			local result = _tcpSocket:read();
			-- check if result is equal than command to confirm success
			trace("Result's lenght : " .. result:len() .. " " .. type(result));
			cmd = string.match(result, "MVL..");
			if (cmd ~= nil) then
				local vol_value = tonumber(cmd:sub(4, 5), 16);
				trace("Result OK : MVL" .. vol_value .. cmd);
				return vol_value;
			else
				trace("Result fail, retry process, #" .. retry .. " please wait...");
				retry = retry + 1;
			end
		end
		return getVolumeLevel(0);
    else
    	if retry < _maxRetryProcess then
      	trace("Retry process, please wait...");
      	fibaro:sleep(2000);
      	return getVolumeLevel(retry + 1);
      	end
		return nil;
    end
end

function getSource(retry)
	local retry = retry or 0;
	local cmd = nil;
	--notify user
	trace("Request SOURCE, #" .. retry .. " please wait...");
	--send packet
	bytes, errorCode = _tcpSocket:write("ISCP\0\0\0\16\0\0\0\12\1\0\0\0\!1SLIQSTN\0x1A\r\n");
	-- check for error
	if errorCode == 0 then
		trace("Request SOURCE command successufully transmited.");
    	fibaro:sleep(50);
		-- amplifier sould return the string sent if success
    	while (cmd == nil and retry < _maxRetryProcess) do
			local result = _tcpSocket:read();
			-- check if result is equal than command to confirm success
			trace("Result's lenght : " .. result:len() .. " " .. type(result));
			cmd = string.match(result, "SLI..");
			if (cmd ~= nil) then
				local src_value = tonumber(cmd:sub(4, 5), 16);
				trace("Result OK : SLI" .. src_value .. cmd);
				return src_value;
			else
				trace("Result fail, retry process, #" .. retry .. " please wait...");
				retry = retry + 1;
			end
		end
		return getSource(0);
    else
    	if retry < _maxRetryProcess then
      	trace("Retry process, please wait...");
      	fibaro:sleep(2000);
      	return getSource(retry + 1);
      	end
		return nil;
    end
end

function getMute(retry)
	local retry = retry or 0;
	local cmd = nil;
	--notify user
	trace("Request MUTE, #" .. retry .. " please wait...");
	--send packet
	bytes, errorCode = _tcpSocket:write("ISCP\0\0\0\16\0\0\0\12\1\0\0\0\!1AMTQSTN\0x1A\r\n");
	-- check for error
	if errorCode == 0 then
		trace("Request MUTE command successufully transmited.");
    	fibaro:sleep(50);
		-- amplifier sould return the string sent if success
    	while (cmd == nil and retry < _maxRetryProcess) do
			local result = _tcpSocket:read();
			-- check if result is equal than command to confirm success
			trace("Result's lenght : " .. result:len() .. " " .. type(result));
			cmd = string.match(result, "AMT..");
			if (cmd ~= nil) then
				local mute_value = tonumber(cmd:sub(4,5));
				trace("Result OK : AMT" .. mute_value .. cmd);
				return mute_value;
			else
				trace("Result fail, retry process, #" .. retry .. " please wait...");
				retry = retry + 1;
			end
		end
		return getMute(0);
    else
    	if retry < _maxRetryProcess then
      	trace("Retry process, please wait...");
      	fibaro:sleep(2000);
      	return getMute(retry + 1);
      	end
		return nil;
    end
end

function getLstMode(retry)
	local retry = retry or 0;
	local cmd = nil;
	--notify user
	trace("Request LISTENING MODE, #" .. retry .. " please wait...");
	--send packet
	bytes, errorCode = _tcpSocket:write("ISCP\0\0\0\16\0\0\0\12\1\0\0\0\!1LMDQSTN\0x1A\r\n");
	-- check for error
	if errorCode == 0 then
		trace("Request LISTENING MODE command successufully transmited.");
    	fibaro:sleep(50);
		-- amplifier sould return the string sent if success
    	while (cmd == nil and retry < _maxRetryProcess) do
			local result = _tcpSocket:read();
			-- check if result is equal than command to confirm success
			trace("Result's lenght : " .. result:len() .. " " .. type(result));
			cmd = string.match(result, "LMD..");
			if (cmd ~= nil and cmd ~= "LMDN/") then
				local mode_value = tonumber(cmd:sub(4,5), 16);
				trace("Result OK : LMD" .. mode_value .. cmd);
				return mode_value;
			else
				trace("Result fail, retry process, #" .. retry .. " please wait...");
				retry = retry + 1;
			end
		end
		return getLstMode(0);
    else
    	if retry < _maxRetryProcess then
      	trace("Retry process, please wait...");
      	fibaro:sleep(2000);
      	return getLstMode(retry + 1);
      	end
		return nil;
    end
end

function getAudioOutMode(retry)
	local retry = retry or 0;
	local cmd = nil;
	--notify user
	trace("Request AUDIO OUT MODE, #" .. retry .. " please wait...");
	--send packet
	bytes, errorCode = _tcpSocket:write("ISCP\0\0\0\16\0\0\0\12\1\0\0\0\!1IFAQSTN\0x1A\r\n");
	-- check for error
	if errorCode == 0 then
		trace("Request AUDIO OUT MODE command successufully transmited.");
    	fibaro:sleep(50);
		-- amplifier sould return the string sent if success
    	while (cmd == nil and retry < _maxRetryProcess) do
			local result = _tcpSocket:read();
			-- check if result is equal than command to confirm success
			trace("Result's lenght : " .. result:len() .. " " .. type(result));
			cmd = string.match(result, "IFA(.+)\n");
			if (cmd ~= nil and cmd:len() > 5) then
				trace(cmd .. cmd:len());
				local audio_value = split(cmd,",");
				trace("Result OK : LMD" .. audio_value[5] .. cmd);
				return audio_value[5];
			else
				trace("Result fail, retry process, #" .. retry .. " please wait...");
				retry = retry + 1;
			end
		end
		return "STRAIGHT DECODE";
    else
    	if retry < _maxRetryProcess then
      	trace("Retry process, please wait...");
      	fibaro:sleep(2000);
      	return getAudioOutMode(retry + 1);
      	end
		return nil;
    end
end

function refreshInterface()
	if (device.power == true) then    
		local label = fibaro:getValue(device.id, "ui.lblPowerStatus.value");
		if (label == "OFF") then fibaro:call(device.id, "setProperty", "ui.lblPowerStatus.value", "ON"); end
		-- update UI volume
		if (device.volume ~= nil) then
			fibaro:call(device.id, "setProperty", "ui.VolumeSlider.value", device.volume);
		end
		-- update UI input
		if (device.source ~= nil) then    
			fibaro:call(device.id, "setProperty", "ui.lblInput.value", input[device.source]);
		end
		-- update UI mute
		if (device.mute ~= nil) then    
			if (device.mute == 1 and label:match("Mutting") == nil) then
				local labelUpdated = label .. " - Mutting";
				fibaro:call(device.id, "setProperty", "ui.lblPowerStatus.value", labelUpdated);
			elseif (device.mute == 0 and label:match("Mutting") == "Mutting") then
				local labelUpdated = label:gsub("%s[-]%sMutting", "");
				fibaro:call(device.id, "setProperty", "ui.lblPowerStatus.value", labelUpdated);
			end
		end
		-- update UI mode
		if (device.lst_mode ~= nil) then
			fibaro:call(device.id, "setProperty", "ui.lblCurrentMode.value", device.lst_mode);
		end
	else
		fibaro:call(device.id, "setProperty", "ui.lblPowerStatus.value", "OFF");
		fibaro:call(device.id, "setProperty", "ui.lblInput.value", "unknown");
		fibaro:call(device.id, "setProperty", "ui.VolumeSlider.value", "0");
		fibaro:call(device.id, "setProperty", "ui.lblCurrentMode.value", "unknown");
	end
	return true;
end

function main()
-- prepare a global counter
if (_count == nil) then
	fibaro:debug("HC2 start script at " .. os.date());
	_count = 0;
end
--notify begin of process
fibaro:debug("Start process #".._count..", please wait...");
--open the socket
if (_tcpSocket == nil) then
	_tcpSocket = Net.FTcpSocket(_deviceIp, _devicePort);
	--set the read timeout
	_tcpSocket:setReadTimeout(1000);
end
-- Query power status
local power = getPowerState();
if (power == 1) then
	device.power = true;
	fibaro:debug("Power is ON ");
	fibaro:sleep(55);
    -- Query volume
	device.volume = getVolumeLevel();
	fibaro:debug("Volume is "..device.volume);
	fibaro:sleep(55);
    -- Query source
	device.source = getSource();
	fibaro:debug("Source selected is "..input[device.source]);
	fibaro:sleep(55);
    -- Query mute
	device.mute = getMute();
	fibaro:debug("Mute is set to "..device.mute);
	fibaro:sleep(55);
    -- Query mode
	local temp = getLstMode();
	fibaro:debug("Listenning Mode is set to "..mode[temp]);
	if (temp == 64) then
		fibaro:sleep(55);
		device.lst_mode = getAudioOutMode();
	else
		device.lst_mode = mode[temp];
	end
elseif (power == 0) then
	device.power = false;
	fibaro:debug("Power is OFF ");
else
	fibaro:debug("No Response... check later...");
end
-- call refresh interface to repaint UI
refreshInterface();
-- dispose socket
if (_tcpSocket ~= nil) then
	-- close socket
	_tcpSocket:disconnect();
	-- destroy object
	_tcpSocket = nil;
end
--notify end of process
fibaro:debug("Process #".._count.." is finish!");
-- increment global counter
_count = _count + 1;
end

-- Start main loop process
main();

-- Sleep
fibaro:sleep(_polling);

-- EOF Main loop
Posté(e)

Ok, par contre attend un peu lorsque tu l'auras débranché genre 5 min quoi. Puis tu rebranches, tu le rallumes et tu attends que les infos remontent correctement au VD.

S'il y a encore des soucis, je pense qu'il faudra augmenter le polling jusqu'àtrouver un comportement optimum.

  • 2 semaines après...
Posté(e)

@mprinfo

Il y a quelques soucis, il manque des tests dans certains boutons. Je dois corriger mais j'ai pas le temps pour le moment, une future v1.1.1

 

Je vous tiens au courant. Faites moi remonter vos bugs s'il y en a.

Posté(e)

Oh con ! Moi qui ait arrété de me prendre la tête sur les quelques bugs restant en attendant les plugins, par respect pour la communauté il va falloir que je me lance dedans après un article pareil. En tout cas merci àDomadoo et àMaximin.

  • 2 semaines après...
  • 3 mois après...
Posté(e)

J'ai installé ce device pour contrôler mon TX-NR709 mais rien qu'en testant le power on/off j'ai:

 

[DEBUG] 21:29:23: Cannot send command !

 

Si quelqu'un a une idée je suis preneur :)

Merci en tout cas pour ce device, même si ça ne marche pas chez moi.

Posté(e)

Salut Icek,

T'as bien paramétré le VD en mettant l'IP et le port correctement ?

Si tu as ce message d'erreur c'est que ton ampli est injoignable.

Posté(e)

Salut Benjynet,

 

Oui c'est le premier truc que j'ai fait.

J'arrive d'ailleurs bien à  la page web de l'Onkyo en tapant son IP.

Le port est bien 60128.

Je me demande si le problème ne vient pas de la chaine "ISCP\0\0\0\16\0\0\0\12\1\0\0\0\!1PWRQSTN\0x1A\r\n" qu'il ne comprendrait pas.

Posté(e)

Bon alors dans le code de ton bouton power met àla ligne 9

local _trace = true;

Et tu cliques sur le bouton power et tu pastes le résultat du debug ci-dessous... ou tu viens me voir sur le tchat :)

Posté(e)

ok. Alors j'ai:

[DEBUG] 19:08:18: Start process POWER ON/OFF v1.1.0
[DEBUG] 19:08:18: Request Power STATUS, #0 please wait...
[DEBUG] 19:08:18: Power STATUS command successufully transmited.
[DEBUG] 19:08:18: Result's lenght : 110 string
[DEBUG] 19:08:18: Result fail, retry process, #0 please wait...
[DEBUG] 19:08:18: Result's lenght : 27 string
[DEBUG] 19:08:18: Result fail, retry process, #1 please wait...
[DEBUG] 19:08:20: Result's lenght : 0 string
[DEBUG] 19:08:20: Result fail, retry process, #2 please wait...
[DEBUG] 19:08:21: Result's lenght : 27 string
[DEBUG] 19:08:21: Result fail, retry process, #3 please wait...
[DEBUG] 19:08:21: Result's lenght : 27 string
[DEBUG] 19:08:21: Result fail, retry process, #4 please wait...
[DEBUG] 19:08:21: Cannot send command !
Posté(e)

Bon déjà , la commande est bien transmise mais le résultat n'est pas bon. Il faudrait utiliser un logiciel pour observer ce qu'il passe sur les trames réseaux. Normalement dans la réponse on doit avoir un truc du genre PWR01 ou PWR00.

 

Fait un telnet sur l'ip/port de ton ampli et clique sur mon bouton power.

Regarde dans la fenêtre si tu vois passer un truc du genre :

gallery_11_7_23356.jpg

Posté(e)

Ca marche!:)

Maintenant, je vais regarder le code de près pour voir où ça coince avec la dernière version.

Merci beaucoup pour le coup de main.

×
×
  • Créer...