Neues Modul VestelTVs für verschiedene TVs (Telefunken, Graetz, Toshiba, Medion)

Begonnen von eki, 04 Januar 2021, 18:56:19

Vorheriges Thema - Nächstes Thema

ryonchev

Creation of remote control and notify works perfect. One suggestion to layout - volume down is "vol -" and volume up is "speacker +" - it will be better if both are with vol or with speacker, i.e. "vol -"/ "vol +" or alternatively "speacker -" / "speaker +"

Buttons youtube and netflix are empty here - obviously no icons - where I can get them?

Sending of commands - unfortuntely it doesn't work. I even cant send commands from the dropmenu of TV object. I'm not so much familiar with perl but looking your code I found this:

   foreach my $command (sort keys %VestelTVs_commands) {
      next if ($opt eq "on" and ReadingsVal($name,"status","off") eq "on");      # omit command if TV is already on
      next if ($opt eq "off" and ReadingsVal($name,"status","off") eq "off");      # omit command if TV is already off
      if ($command eq $opt) {
         my $key = $VestelTVs_commands{$command};
         Log3 $name, 5, "$name - Key: $key";
         VestelTVs_SendKey($hash,$key);
      }
   }
   if ($opt eq '_keydirect') {
      VestelTVs_SendKey($hash,$value);
   }

   return undef;

This is at the end of VestelTVs_Set($@). I think if statement should be before foreach and when it is before there should be also "return undef;" inside if statement.
Maybe it is not correct - as I said - not so familiar with perl

Will try to figure out what is happening tomorrow with "event monitor" and log...

eki

I tested the version with my TV and it worked. So I doubt that it has something to do with that part of the code. I can do some more checks tomorrow.

One more question: Did it work before at all in the direction of sending commands to the TV (this is done in a complete different way compared to getting TV status information).

ryonchev

I never managed to get TV status information, but before at least sending of commands was working. In general this is enough for me.
Last night when I tested the new file from you I was not able to send commands, but I saw notifications are correct.
I think there is some issue with the ports...
In google play store there is app Smart Remote Control for Vestel. I discovered it autodetects TV as soon as TV is turned on. I decompiled the application and found class TVDetector. It seems it posts some data to port 1900 and/or port 4950 (although these ports are reported closed by nmap) and from the response it takes the correct ports. I will try this later today.
I also found python program on Github for this TV - http port is the same which I use - 56791, but status port is 56792 and the guy reads from this port file named dd.xml - the same thing I found and in android apk

Will make additional tests and will post the results

PS: Thank you for the fast implementation of key codes correction and automatic remote control generation :)

eki

I know the software you are referring to. The python program more or less was the initial part I was starting with when I did the module. I tried also the websocket connection but it was not working on my TV and so I deactivated it. The detection on Port 1900 is something I did not try, I would be interested in your findings and I can try to adapt the module accordingly.
There is a function in the Module called VestelTVs_TryPorts this function configures the connectivity to all known ports (the ones that I got when doing nmap with root rights) and tries a connection. You could set a high verbose level, run this function (set <name> tryports) and send me the resulting log, may be I find something in there.

ryonchev

Hallo eki,

1. Probably it was my mistake while testing your new module - today without doing anything the module works perfectly, remote control also. Probably after reload of the module manual disconnect/connect should be done also - not sure, but today wotks. Im still not able to get TV status. Definitely http port in my case is 56791. If I change it to something else remote control and commands from drop down menu stop to work.
2. To receive TV status I suppose tcp port should be correct. I tried all ports available but without success. Yes I tried your port scanner but not so much info (Log of this try attached). While testing I also tried a file few posts above not the one from the first page. I suspect there was something left from web sockets because I received some readings  like mute ON/OFF and energysaving, but only this. This module was working fine for about few hours then (probably when I turn on my TV) FHEM server continuously restarted because Anyevent module was not installed. I installed it, but in the same moment I saw your new module and decided to test it... So probably my TV works via web socket.
3. Android apk - I converted it to jar file which is better readable with jd-gui, reading smali files is not my favorite :). Will attach jar file and jd-giu (windows). Inside jar file you can take a look in com->vestel.supertvcommunicator->TVDetector. What I found there is interesting but doesn't work with my TV (I tried this with curl). However if app is running on your phone or tablet, few seconds after Vestel TV is turned on it displays the IP address of the TV. This will be good feature for your module and I will continue to work on this, since this could solve all problems with ports :)


Edit: After some more tests -
Zitat
Offline eki
Developer
Hero Member
****
Posts: 1275
View Profile Personal Message (Offline)

Antw:Neues Modul VestelTVs für verschiedene TVs (Telefunken, Graetz, Toshiba, Medion)
« Reply #29 on: 01 February 2021, 11:40:00 »
Quote
Ups sorry, ich habe ein # zu viel entfernt. Neue Version anghängt. Die Warnungen im Log sind normal, kommen vom reload.
* 82_VestelTVs.pm (49.41 kB - downloaded 2 times.)

with this version of the module I receive some readings, but only after execution of the command. Now I have installed module Anyevent and FHEM does not restart anymore. I saw, you commented almost everything connected with websocket - will uncomment everything and will try it tomorrow

eki

When you want to "activate" websocket, you have to uncomment line 44 and remove lines 747 (=a) and 785 (=cut) in the latest version of the module. If websocket provides any information, there should appear a reading called ws_answer. It would be interesting if on your TV such a reading appears with websocket activated and what kind of content the reading has. You can also play around with the port by setting the attribute ws_port.

ryonchev

Some more tests done. I think there is something wrong with the module:
1. I enabled web socket connection in VestelTVs_Connect (and uncommented line 44 also). I run tryports. In this case web socket connects, but read function is always tcp reading. I cannot find reading function for web socket in the module.
2. I disabled tcp connection in VestelTVs_Connect and run again tryports and of course reading was not possible anymore

According to android apk the TV can be either tcp or web socket, but cannot be both. Also according to the same app remote control commands are always send via http. So I suggest you if ws_port is set always establish ONLY web socket connection. If ws_port is not set always establish tcp connection. Of course read function for web socket also should be added



Meanwhile I figured out how auto TV detection works:
1. We are asking the network if host with ip 239.255.255.250 is known. If yes this could be Vestel TV model MB100 (this MB seems to be internal Vestel's designation of models). Then message "M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 10\r\nST: urn:dial-multiscreen-org:service:dial:1\r\n\r\n" is sent to http://239.255.255.250:1900. I don't know how this works because I don't have such TV and I don't know whether phone (or tab) changes wifi network, but it seems this model TV makes his own access point - the answer from the TV (if any) is compared if starts with "ap0". If there is an answer probably it contains some important info. If there is no answer - not Vestel TV
2. The app scans all clients on current network and tries to establish Telnet connection on port 1986. This means that all Vestel TVs should allow such connection on this port. If no connection - no Vestel TV. If connected simple command like GETVOLUME is isuued. If there is response - TCP Vestel TV. If there is no response the TV is tested for MB90 model - message "vr_query_tv_version_782" is posted to http://ipaddress:4950. If there is response it is MB90 model. I dont know what response contains - I don't have such TV either. If there is no response the TV is tested for web socket TV - it seems the port is always 7681, but I cannot be sure until more people confirm it
3. IP addresses which are not Vestel TVs are stored in something like "blacklist". The app continuously scan for new ips (TV just switched on) and performs steps 1 and 2 above. IPs from blacklist are never scanned again. Blacklist is not stored on sdcard, just in memory, so if you restart app it will scan again all clients of current network - this solves the problems with DHCP and TV can change ip address.

If your TV is TCP you should be able to establish telnet connection via PuTTY (for instance) on port 1986 and then in the command line to give directly commands to TV.

If more people can confirm my findings will be perfect.

So finally eki, according to the above algorhytm my TV should b web socket and not TCP. As I wrote above TV is either TCP or web socket, but never both, so either TCP connection should be established or web socket, but not both.

I hope this will help :)

PS. I forgot to explain, but all probing described above should be timeouted in case post command is successful but there is no answer. For those who like to test here are messages using curl:

For MB100:
curl -v -X POST -d "M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 10\r\nST: urn:dial-multiscreen-org:service:dial:1\r\n\r\n" http://239.255.255.250:1900

For MB90:
curl -v -X POST -d "vr_query_tv_version_782" http://ipaddress:4950
Change "ipaddres" accordingly.

For TCP TV - just use PuTTY (windows) or telnet. When connected try GETVOLUME - if no response - not TCP TV

The conclusion is (according to the app and for this moment - I don't know what Vestel will do in future :) ): It seems that TCP TV's are always on port 1986 and web socket TV's are always on port 7681, but this should be proved by more users. At least it is firm that telnet connection on port 1986 should be always available. HTTP connection is another issue, but usually http ports are the high ports (above 50000) so it is easy to try them.

eki

OK, I think I have to digest all the information (thanks for finding out all this).

Just for your information, what the standard module does currently:

1. It sends pings to the IP address of the TV (the one you specify when you define the module in FHEM) regularly (when INTERVAL is greater than 0 every <INTERVAL> seconds the default for INTERVAL is 300 so every 5 minutes). When it gets a positive answer for the ping, it assumes the TV to be on else off and sets the according reading. This means that even without all the stuff you mention, the module should be able to at least check if the TV is on or off (maybe you have to change the interval attribute to get a fast answer).

2. When you enter a remote control command (like volumeUp) it sends the key behind this command via HTTP (on port 56789 by default but can be changed by setting attribute http_port). This is done instantaneously, no relation to the interval setting here. This should normally work independantly from the other connections.

3. It regularly at the same timing as for the pings establishes a TCP connection (tcp socket connection) (on port 1986 by default, but can be changed by attribute tcp_port) and sends requests for information to the TV over this connection. When there is a valid reply it converts the information into reading status information (e.g. current channel etc.). As the commands for this question and answer game I use the information at (https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwiYiLDun5TvAhXC6qQKHYFcA3cQFjAAegQIARAD&url=https%3A%2F%2Fwww.vestelvisualsolutions.com%2Ffiles%2Fvestel-visual-solutions-rs232-lan-customer-control-v1-1-d13c7b454990_9ABE26049440.pdf&usg=AOvVaw0ZGGRuN-heUOnX3AonTjoo)

4. If you uncomment the websocket part, it additionally activates a websocket connection (on port 7681 by default but can be changed with the attribute ws_port). It listens to this port and currently, whenever there is a message on this port received, it enters the result in the reading ws_answer. In the websocket case there is no question/answer game, the socket is open and whenever there is a message, a callback is entered (line with code "$connection->on(each_message => sub {" ) so there is no "reading function". I would need to parse the result and transfer it to readings, but I do not have any information how yet (would need at least an example of any answer).

I think http, tcp and ws connections can be open in parallel, but if the TV is either/or tcp and websocket respectively, it will only get results from one or the other. If there is a kind of blocking of tcp and websocket and vice versa, you could try to only activate websocket   by commenting out the lines 728 to 740.

ryonchev

ok. I see your logic and it seems correct unless tcp port and web socket port are one and the same, but as I already know this is not the case, so it should work. I have the same document (the link you posted) so I know this part is correct.
Independently I made simple tests with telnet and websocat on all ports. Both are not connecting on high ports (above 50000), so these are definetely http ports. websocat do not connect on port 2870 also, but connects to all other ports. On each connection I try the command GETVOLUME (telnet & websocat connection). Unfortunately there is no answer anywhere.

The problem is that according to android apk web socket connection with TV is secured (wss://). Probably due to this reason I don't have an answer. In the jar file which I posted yesterday - look into com->vestel.supertvcommunicator->WebSocketClient.class

Also it seems that request which should be posted is not plain text. WebSocketClient uses HybiParser and on first look the request (and an answer also) is in binary form as array of bytes.
But connect function of WebSocketClient is very interesting!

PS. As I mentioned in one of my previous posts working remote control is enough for me. If you think it is good to dig more and more and make module better I can help - unfortunately writing code on perl is not my strong side, but can help with debuging, testing, reverse engineering of known soft etc.

ryonchev

After more tests I discovered there is no way to receive TV status with android apk (not supported), so probably my TV just doesn't support this function regardless tcp or web socket connection...
But somehow I received some answers for some events (see the attached picture). Im not able to reproduce these events right now... I don't know what is going on..

But Im happy with the module. I just added to define function calls to remote control generation and notify generation. in my case the missing name/parameter is "RC".$name, so now when you define TV additionally remote control and notify are generated automatically.

eki, I still stand behind my previous post and if I should help with something - just tell me how.

eki

ZitatBut somehow I received some answers for some events (see the attached picture). Im not able to reproduce these events right now... I don't know what is going on..

As said, the status reading (on/off) is updated based on the ping as well. The chlist_loaded reading is also entered by the module. The others might come from settings you made, whenever you set some parameter with the set command, this value is entered in a reading as well, even when no status messages are received from the TV.

KölnSolar

Hallo Eki,
ich grätsch hier mal rein. Vielleicht hast Du ja mitbekommen, dass ich gerade versuche das Thema UPnP in FHEM zu vereinheitlichen. Insbesondere TVs verfügen in der Regel über das UPnP "subset" DLNA. Damit lässt sich hervorragend das Thema "presence" und in der Regel Volume-Steuerung und Streaming bedienen. Darüber hinaus gehende "features"(wie z.B. remotecontrol) sind in der Regel herstellerspezifisch und müssen in spezifischen Modulen wie Deinem realisiert werden.

In meinem Thread kann man aktuell das Medion-Bsp. verfolgen. Bisher funktioniert scheinbar presence u. Status-Meldungen. Gerade hakt es bei den actions.(das aber nur als Randinfo).

Auch hier im Thread wird ja DLNA angesprochen
ZitatWe are asking the network if host with ip 239.255.255.250 is known. If yes this could be Vestel TV model MB100 (this MB seems to be internal Vestel's designation of models). Then message "M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 10\r\nST: urn:dial-multiscreen-org:service:dial:1\r\n\r\n" is sent to http://239.255.255.250:1900.
und ich sah, dass Du presence per ping prüfst.

Wenn Du Dir mein SamsungAV anschaust, siehst Du wie ich in einem 1. Ansatz versucht habe das unter einen Hut zu bringen: Definition im herstellerspezifischen SamsungModul mit dem optionalen DLNARenderer-device. Dadurch kann der User in DLNA-Standard streamen. Genervt hat "aktuell" auch bei mir die presence-Prüfung. Ein periodischer ping ist da nichts Halbes u. nichts Ganzes. Deshalb wollte ich auch dafür DLNA nutzen, denn es ist doch viel schöner, wenn der TV FHEM sagt in welchem state er sich befindet, als dass wir in mühsam u. zeitlich ungenau "befragen".  Wie so oft kam es etwas anders und ich hab mich nun auf den weiten Weg gemacht, UPnP in Gänze aufzuarbeiten/vereinheitlichen, den DLNARenderer damit abzulösen u. als letzten Schritt dann mein Samsung-Modul auf Vordermann zu bringen.

Da Deine Modulentwicklung noch relativ jung ist, fänd ich es prima wenn Du einen ähnlichen Weg einschlagen würdest bzw. mal meine UPnP-Neuentwicklung austestest, denn mit dem UPNPController bekommt man einfach u. schnell eine erste Information, was ein TV mit DLNA unterstützt. Kannst ja ggfs. in meinem UPnP Thread antworten, um diesen Thread nicht mit "Technik" zu "belasten". ;)

Schönes WE
Markus
RPi3/2 buster/stretch-SamsungAV_E/N-RFXTRX-IT-RSL-NC5462-Oregon-CUL433-GT-TMBBQ-01e-CUL868-FS20-EMGZ-1W(GPIO)-DS18B20-CO2-USBRS232-USBRS422-Betty_Boop-EchoDot-OBIS(Easymeter-Q3/EMH-KW8)-PCA301(S'duino)-Deebot(mqtt2)-zigbee2mqtt

eki

Danke Markus für die Info. Ich schau mir das mal an, klingt vielversprechend. Kann aber ein bisschen dauern weil ich aktuell nicht an den TV rankomme.

ryonchev

Hallo eki,

I continue with the tests with my TV to get status, but for now no success. Probably not supported - my TV is 2015 model... If there is something new will inform you.

About remote control - can you tell me where I can find these files: black_btn_YOUTUBE.png and black_btn_NETFLIX.png - they are empty here. I searched the net but no success. Please send a link if you have. And if you have them probably will be easier to post them here - will appreciate.

Thank you, Danke!