Script Télécommande SFR TV

Hello

Je m’arrache les cheveux pour faire fonctionné une commande dans le script sfr
le script en question est ici

J’arrive a faire fonctionné presque tout sauf une ligne avec laquelle je me bat
celle-ci:
« NUMBER »: « THIRDARGUMENT_UTF8DECIMALCODE »,

Elle ce trouve dans cette partie:

j’arrive pas a trouvé le bon paramètre
Quelqu’un pourrait m’aidé ?

Merci

Bonsoir,

Pour cela essaie :
ton url suivi: /var/www/html/plugins/script/data/telecommande_sfr.php BUTTONEVENT NUMBER 1 ou autre chiffre.

A+
Bernard

Hello
Merci de ton aide
Je viens de testé ta solution cela ne fonctionne pas

Désolé !

Est ce que tu peux faire une copie d’écran de ton code telecommande_sfr.php

Hello

@Bercolly
Je te fais cela , dsl je suis en déplacement toutes les semaines d’où mes temps de réponse longue

<?php

$IP="192.168.1.253"; // a changer
$PORT=7682;

$ws = new ws(array('host' => $IP,'port' => $PORT,'wskey' => 'XXXXXXXXXXXXXXXXXXXXXX=='));

switch ($argv[1]) {
    case "ZAP":
		$ws->send('{"Params": {"Token": "LAN", "DeviceSoftVersion": "11.2.2", "Params": ['.$argv[2].', "zapdigit"], "Action": "CustomEvent", "DeviceModel": "iPhone", "Event": "GotoLive"}}');
  		break;
    case "BUTTONEVENT":
    	$ws->send('{"Params": {"Token": "LAN", "DeviceSoftVersion": "11.2.2", "Action": "ButtonEvent", "Press": ['.$argv[2].'], "DeviceModel": "iPhone"}}');
    	break;
   	case "APP":
    	$ws->send('{"Params":{"Token":"LAN","DeviceSoftVersion":"11.2.2","Action":"GotoApp","AppName":"'.$argv[2].'","DeviceModel":"iPhone","DeviceId":"375CC21F-2E8D-4C31-B728-7790E6D24BD0"}}');
    	break;
}

$ws->close();

class ws
{
	private $params;
	private $head;
	private $instance;
		
	public function __construct($params)
	{
		foreach($params as $key => $value)
			$this->params[$key] = $value;

		$this->head =	"GET / HTTP/1.1\r\n" .
						"Upgrade: websocket\r\n" .
						"Host: ".$this->params['host'].":".$this->params['port']."\r\n" .
						"Origin: ".$this->params['host'].":".$this->params['port']."\r\n" .
						"Sec-WebSocket-Key: ".$this->params['wskey']."\r\n" .
						"Sec-WebSocket-Version: 13\r\n" .
            "Connection: upgrade\r\n" .
            "Sec-WebSocket-Protocol: lws-bidirectional-protocol\r\n";		
	}

	public function send($method)
	{
      	echo $method."</br >";
		$this->head .= "Content-Length: ".strlen($method)."\r\n\r\n";
		$this->connect();		
		fwrite($this->instance, $this->hybi10Encode($method));
		//$wsdata = fread($this->instance, 2000);
      	//echo $this->hybi10Decode($wsdata);
		//return $this->hybi10Decode($wsdata);		
	}

	public function close()
	{
		if($this->instance)
		{
			fclose($this->instance);
			$this->instance = NULL;
		}
	}
	
	private function connect()
	{
		$sock = fsockopen($this->params['host'], $this->params['port'], $errno, $errstr, 2);
		fwrite($sock, $this->head);
		$headers = fread($sock, 2000);

		$this->instance = $sock;		
	}
	
	private function hybi10Decode($data)
	{
		$bytes = $data;
		$dataLength = '';
		$mask = '';
		$coded_data = '';
		$decodedData = '';
		$secondByte = sprintf('%08b', ord($bytes[1]));
		$masked = ($secondByte[0]=='1') ? true : false;
		$dataLength = ($masked===true) ? ord($bytes[1]) & 127 : ord($bytes[1]);

		if ($masked===true)
		{
			if ($dataLength===126)
			{
				$mask = substr($bytes, 4, 4);
				$coded_data = substr($bytes, 8);
			}
			elseif ($dataLength===127)
			{
				$mask = substr($bytes, 10, 4);
				$coded_data = substr($bytes, 14);
			}
			else
			{
				$mask = substr($bytes, 2, 4);
				$coded_data = substr($bytes, 6);
			}
			for ($i = 0; $i<strlen($coded_data); $i++)
				$decodedData .= $coded_data[$i] ^ $mask[$i % 4];
		}
		else
		{
			if ($dataLength===126)
				$decodedData = substr($bytes, 4);
			elseif ($dataLength===127)
				$decodedData = substr($bytes, 10);
			else
				$decodedData = substr($bytes, 2);
		}

		return $decodedData;
	}

	private function hybi10Encode($payload, $type = 'text', $masked = true)
	{
		$frameHead = array();
		$frame = '';
		$payloadLength = strlen($payload);

		switch ($type)
		{
			case 'text' :
				// first byte indicates FIN, Text-Frame (10000001):
				$frameHead[0] = 129;
				break;

			case 'close' :
				// first byte indicates FIN, Close Frame(10001000):
				$frameHead[0] = 136;
				break;

			case 'ping' :
				// first byte indicates FIN, Ping frame (10001001):
				$frameHead[0] = 137;
				break;

			case 'pong' :
				// first byte indicates FIN, Pong frame (10001010):
				$frameHead[0] = 138;
				break;
		}

		// set mask and payload length (using 1, 3 or 9 bytes)
		if ($payloadLength>65535)
		{
			$payloadLengthBin = str_split(sprintf('%064b', $payloadLength), 8);
			$frameHead[1] = ($masked===true) ? 255 : 127;
			for ($i = 0; $i<8; $i++)
				$frameHead[$i + 2] = bindec($payloadLengthBin[$i]);

			// most significant bit MUST be 0 (close connection if frame too big)
			if ($frameHead[2]>127)
			{
				$this->close(1004);
				return false;
			}
		}
		elseif ($payloadLength>125)
		{
			$payloadLengthBin = str_split(sprintf('%016b', $payloadLength), 8);
			$frameHead[1] = ($masked===true) ? 254 : 126;
			$frameHead[2] = bindec($payloadLengthBin[0]);
			$frameHead[3] = bindec($payloadLengthBin[1]);
		}
		else
			$frameHead[1] = ($masked===true) ? $payloadLength + 128 : $payloadLength;

		// convert frame-head to string:
		foreach (array_keys($frameHead) as $i)
			$frameHead[$i] = chr($frameHead[$i]);

		if ($masked===true)
		{
			// generate a random mask:
			$mask = array();
			for ($i = 0; $i<4; $i++)
				$mask[$i] = chr(rand(0, 255));

			$frameHead = array_merge($frameHead, $mask);
		}
		$frame = implode('', $frameHead);
		// append payload to frame:
		for ($i = 0; $i<$payloadLength; $i++)
			$frame .= ($masked===true) ? $payload[$i] ^ $mask[$i % 4] : $payload[$i];

		return $frame;
	}
}
?>

Bonsoir,*
Si je comprends bien tu as ré-écrit le script python en php , non ?

A+
Bernard

Re

j’ai pas écrit une seule ligne , le script je l’ai trouvé la:

Bonjour,

Essaie cela

'{"Params": {"Token": "LAN", "DeviceSoftVersion": "11.2.2", "Action": "ButtonEvent", "Press": [ "' .$argv[2].'"], "DeviceModel": "iPhone"}}';

Le paramètre argv[2] doit être un caractère et non un nombre . Donc, il suffit de l’entourer avec des quotes.

A+
Bernard

J’attends ton retour.
Si OK, pense à noter le problème comme résolu.
A+
Bernard

1 « J'aime »

Hello

Bon alors si j’applique ta solution je perd toute mes fonctions
BUTTONEVENT 303, etc…

C’est a devenir dingue ce truc …

Non,
Pour evenir à l’origine du problème dans ton cas le script envoie THIRDARGUMENT_01.

En fait dans ce cas, je pense qu’il s’agit de fournir le code ascii de la touche sur laquelle tu aurais appuyer .

Comment actives-tu ton script depuis un scénario ?

Donc annule la modification que je t’ai ai indiquée et modifie l’appel de ton dernier script ainsi
/var/www/html/plugins/script/data/telecommande_sfp.php BUTTONEVENT ord(‹ 1 ›)

si la fonction ord n’est pas reconnue par jeedom dans l’appel du script essaie :
/var/www/html/plugins/script/data/telecommande_sfp.php BUTTONEVENT 49

49 est le code ascii de '1'.

Ceci est pour l’exemple à toi de voir sur le forum comment passer un paramètre à un script.

Re

Alors si je fais cela :
/var/www/html/plugins/script/data/telecommande_sfp.php BUTTONEVENT ord(‹ 1 ›)

J’ai comme erreur ceci :
Erreur sur php /var/www/html/plugins/script/data/telecommande_sfp.php BUTTONEVENT 226 2>&1 valeur retournée : 1. Détails : Could not open input file: /var/www/html/plugins/script/data/telecommande_sfp.php

Et avec cela:
/var/www/html/plugins/script/data/telecommande_sfp.php BUTTONEVENT 49

rien ne se passe… Malgré que jeedom me dit action exécuté avec succès.

J’ai mis le script dans le plugin.

Ensuite je crée mes commandes tout simplement , pour avoir un contrôle via un cran , ou téléphone

Il y a une erreur typo , en fait c’est :

/var/www/html/plugins/script/data/telecommande_sfr.php BUTTONEVENT 49

Yes Yes yes

si :
/var/www/html/plugins/script/data/telecommande_sfr.php BUTTONEVENT 49

Alors je zappe sur la 1 (TF1)

Merci merci @Bercolly

Bon maintemant il va falloir que je trouve les combinaisons
de la suite :

49 est le code ascii de '1'.

Edit je crois avoir trouvé
https://fr.wikibooks.org/wiki/Les_ASCII_de_0_à_127/La_table_ASCII

Parfait !
Tu peux marquer le problème comme résolu ?
A+
Bernard

C est déjà fait :wink:

OK, Je ne l’avais pas vu.

Ce sujet a été automatiquement fermé après 24 heures suivant le dernier commentaire. Aucune réponse n’est permise dorénavant.