Announcement

Collapse
No announcement yet.

IP / Serial Plugin for HS3 (by "drule") - Discussion Thread

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Originally posted by reggs11 View Post
    Hi David - Thanks for that, I'm finally getting data back from the projector and can parse the text in to a script.
    I can do that so well that I can even match an MD5 encrypted password and still talk to the projector

    On further reading of the PJLink protocol however, its unveiled another problem which I guess was always gonna happen

    After 30 seconds of initiating a TCP connection the Projector forcibly closes the TCP connection if no more commands are sent to it.

    When the plugin detects the dropped connection, it obviously reestablishes the link and we end up in an endless loop with the connection being closed and opened every 30 seconds forever.

    This is the relevant bit of the PJLink docs:
    http://pjlink.jbmia.or.jp/english/da...g_20131210.pdf


    The projector actually doesn't return to Standby, it just drops the TCP connection which would be fine if the plugin only reestablished the connection if\when I send the next command.

    So this is what I am seeing (see image) :
    The initial response as can be seen below is correct :
    17/12/2016 07:12:37:[drhsIpPlugIn]->Projector - received TCP data from: 192.168.0.83, length: 9, containing: %1POWR=0
    %1POWR=0 Just means the projector is off (or it can be any other valid state).
    After 30 seconds or so, if no more commands have been sent, the projector closes the connection.

    The plugin's watchdog then detects the closed or stalled TCP connection and then opens a new connection.
    Every response after then is just the projector acknowledging a new connection e.g.
    [drhsIpPlugIn]->Projector - received TCP data from: 192.168.0.83, length: 9, containing: PJLINK 0

    This behaviour just repeats forever.

    Is there any way for the plugin to only wait a few seconds for a valid response that triggers a script and then allows the connection to drop and not remain persistent? I guess something that disables the watchdog for certain connections might work...

    All I'm really trying to do is get the response to a valid query, parse any received data to my script and then drop the connection until I send another command which may not happen until for example I want to turn the projector off maybe a few hours later.

    On a side note, another query I had that is not shown in this example is that when using passwords the initial query comes back with "PJLINK " + a 1 digit status + a random 8 digit number. Is there any way to use wildcards somehow for the random number as it changes with every new connection?

    Cheers,
    - John
    The plugin should be able to handle this. If you disable the persist option of the TCP client connection, the plugin will wait for a response for the amount of time defined by the "TCP client response timeout" setting on the plugin's options page, before closing the connection. The drawback of this setting is that all TCP clients will wait this amount of time. At some point I need to change this to a per-connection setting, rather than global.

    As for the random number problem, I could probably add an event condition for "contains", or "starts with". I'll add these to my to-do list. In the meantime you could use a pass-thru script to achieve the same thing.

    -David

    Comment


      Hi David. Thanks for looking into it.

      That seems to fit with what I was seeing.

      re.
      ...When a string is received on a serial port, it is immediately sent to the pass-thru script ...
      Question 1: For the serial port, what are you using to define a string? or specifically, the end of a Message (EOM)? Serial buffers can be quite annoying and may not pass on every byte as it's received but one can usually determine if there is data in the buffer and grab it. imho, your plugin should not pass data to the pass-thru script until it gets a EOM string (end of message) or the timeout is reached and it should then clear the plugin string buffer, not concatenate and resend. I think it should also print an error message in the log...but that's just me

      I guess the easiest fix will be to replace my hard-coded setting with one that is user selectable. It shouldn't take too long. Will this work for you?
      Unfortunately it's not a good solution as one can not use silence to define a complete message (except for certain protocols like Modbus which uses silent frames to separate messages - but they are pretty rare The use of a timeout to delimit a string is not an ideal technique for serial imho). The pass-thru module should ideally only ever receive a complete (and singular) serial string (as defined by the EOM termination string). Not partial strings, not multiple strings.

      Question 2: Is it intended that :
      a) your plugin may send multiple and/or incomplete message string to the pas-thru module and the buffer and break-up/parse the input data or
      b) your plugin will only send a single "complete" message string to the pass-thru module?
      I would think it should be b) and your plugin does the buffering and sends a single complete message to the pass-thru module.


      Different systems can use different a different termination string - ie. HEX "03". The way I have handled this in the past is to have a user defined termination string to delimit a complete string (and have this default to HEX "0D0A").

      My recommendation (which should be just as easy to implement): :
      1) Add a termination string to the Serial Ports config. page and have your plugin wait for this EOM string to arrive before sending data to the pass-thru. If it does not arrive by the timeout, send nothing (display error). This should be very easy to add in.
      2) Add a user selectable timeout to the Plugin Config page for rare timed protocols like Modbus.

      It also presents the opportunity to simplify the specification of a termination string for transmission. As it is always the same char string for an interface, it is redundant to have to specify this in the command string every time I write a command. The system should add it for me. It would also remove a common user error for new users of your plugin - people forgetting to add the EOM string to their individual commands (usually specified as "\r"). To make it backward compatible with the existing user configurations (where people have to specify the termination string at the end of every command), you would allow the EOM Transmit to be left blank (and it will assume it is specified in the command by the user as is done today).

      Something like this... I recommend you avoid "C Escaped" characters here as hex allows for the use of any possible eol string and serial is usually defined in hex anyway....but if you wanted, you could add a type field to allow the user to choose like you have in the commands screen.

      PS. For what it's worth, I think the guys over at Command Fusion do a great job of this - being an iPad, it's just TCP but still worth a look ...http://www.commandfusion.com/wiki2/s...tem-properties
      Attached Files
      Last edited by davros; December 17, 2016, 09:39 PM.

      Comment


        Originally posted by drule View Post
        The plugin should be able to handle this. If you disable the persist option of the TCP client connection, the plugin will wait for a response for the amount of time defined by the "TCP client response timeout" setting on the plugin's options page, before closing the connection. The drawback of this setting is that all TCP clients will wait this amount of time. At some point I need to change this to a per-connection setting, rather than global.

        As for the random number problem, I could probably add an event condition for "contains", or "starts with". I'll add these to my to-do list. In the meantime you could use a pass-thru script to achieve the same thing.

        -David
        Hi David - Okay so this is probably a misunderstanding on my part but when the persist checkbox isn't checked, I can't select the relevant connection as it no longer shows up in the 'drhsIpPlugin : Received Triggers' event box.

        Click image for larger version

Name:	No connection available.jpg
Views:	1
Size:	28.0 KB
ID:	1188163

        Also, I can't select a script to run without the persist box being checked (its greyed out) so with neither option being available how do you trigger an event based on the response data? I'm not able to enable the projectors port 4352 either as the port enable button disappears.

        Click image for larger version

Name:	No persist.jpg
Views:	1
Size:	14.5 KB
ID:	1188164

        I'm obviously missing something

        Comment


          Originally posted by reggs11 View Post
          I'm obviously missing something
          Actually, no that's another bug. When I first coded it, non-persistent connections, opened their connection, sent their data and then immediately closed. Therefore it made no sense to allow a trigger on received data, or offer a pass-thru. Later on I added the response timeout to allow a device I was working with to write its response to the homeseer log. Since I didn't need to trigger anything based on that response, I guess I didn't un-grey out the options. Will fix shortly and post.

          -David

          Comment


            Originally posted by drule View Post
            Actually, no that's another bug. When I first coded it, non-persistent connections, opened their connection, sent their data and then immediately closed. Therefore it made no sense to allow a trigger on received data, or offer a pass-thru. Later on I added the response timeout to allow a device I was working with to write its response to the homeseer log. Since I didn't need to trigger anything based on that response, I guess I didn't un-grey out the options. Will fix shortly and post.

            -David
            Ah okay, fair enough. I'll stop playing with stuff for the time being then

            Comment


              Hi David, how are you coming with the 2 bugs:

              1) Concatenation
              http://forums.homeseer.com/showpost....&postcount=527

              2) Ability to call plugin from json
              http://forums.homeseer.com/showpost....&postcount=484

              3) Plugin does not recover from a port disconnect. I am running a flaky cat6 port extender and it seems to drop and reconnect the com ports. In the below com port after x mins. (example below lasted 17min 36 sec's and 8 mins 29 sec's.

              There is also a third issue where the plugin shuts the serial connection....
              Code:
              Dec-26 7:46:44 PM	 	drhsIpPlugIn	Stopping DAB1...
              I need to restart the plugin to get it to work again.

              You can see this pattern in the below. Disabling and re-enabling the connection in the "drhsIpPlugIn"/"config"/"Connections" tab/screen produces an error saying the comm post can not be found.
              Code:
              Dec-26 7:46:46 PM	 	drhsIpPlugIn	SerialPort COM4 not found
              Dec-26 7:46:46 PM	 	drhsIpPlugIn	Starting serial client for DAB1 on COM4
              Restarting the plugin temporarily fixes the connection.
              Code:
              Dec-26 7:48:03 PM	 	Plug-In	Finished initializing plug-in drhsIpPlugIn
              Dec-26 7:48:02 PM	 	drhsIpPlugIn	Starting Tcp host for DAB1-Relay on port 1026
              Dec-26 7:48:02 PM	 	drhsIpPlugIn	Starting serial client for DAB1 on COM4
              Dec-26 7:48:02 PM	 	Info	Plugin drhsIpPlugIn has connected. IP:127.0.0.1:65464
              Dec-26 7:47:45 PM	 	Info	Plugin drhsIpPlugIn with instance: has disconnected
              Dec-26 7:47:45 PM	 	Plug-In	Shutting down Plug-In:

              Debug log below:
              Code:
              Dec-26 7:57:54 PM	 	drhsIpPlugIn	DAB1 - closing serial client
              Dec-26 7:56:34 PM	 	Z-Wave	Device: Node 21 Z-Wave Luminance Set to 36 (Lux)
              Dec-26 7:56:32 PM	 	Z-Wave	Device: Node 21 Z-Wave Temperature Set to 27 (C)
              Dec-26 7:55:15 PM	 	Warning	Not running script since its already running: C:/Program Files (x86)/HomeSeer HS3/scripts/get_emoncms.vb Single instance option enabled in event properties
              Dec-26 7:50:39 PM	 	Z-Wave	Device: Lights Z-Wave Watts 2 Set to 42.2 (42.2 Watts)
              Dec-26 7:49:25 PM	 	DAB1_Parse_In	Data(1) :+OK
              Dec-26 7:49:25 PM	 	DAB1_Parse_In	Data(1) :+OK
              Dec-26 7:49:25 PM	 	DAB1_Parse_In	Data(0) :+V323
              Dec-26 7:49:25 PM	 	DAB1_Parse_In	param(0):DAB1 Data:+V323 +OK
              Dec-26 7:49:25 PM	 	DAB1_Parse_In	Data(1) :+OK
              Dec-26 7:49:25 PM	 	DAB1_Parse_In	Data(0) :+V323
              Dec-26 7:49:25 PM	 	DAB1_Parse_In	param(0):DAB1 Data:+V323 +OK
              Dec-26 7:49:25 PM	 	DAB1_Parse_In	Data(0) :+
              Dec-26 7:49:25 PM	 	DAB1_Parse_In	param(0):DAB1 Data:+
              Dec-26 7:49:25 PM	 	DAB1_Relay_Cmd	Sending to DAB1 :V3--
              Dec-26 7:48:03 PM	 	Plug-In	Finished initializing plug-in drhsIpPlugIn
              Dec-26 7:48:02 PM	 	drhsIpPlugIn	Starting Tcp host for DAB1-Relay on port 1026
              Dec-26 7:48:02 PM	 	drhsIpPlugIn	Starting serial client for DAB1 on COM4
              Dec-26 7:48:02 PM	 	Info	Plugin drhsIpPlugIn has connected. IP:127.0.0.1:65464
              Dec-26 7:47:45 PM	 	Info	Plugin drhsIpPlugIn with instance: has disconnected
              Dec-26 7:47:45 PM	 	Plug-In	Shutting down Plug-In: drhsIpPlugIn
              Dec-26 7:46:46 PM	 	drhsIpPlugIn	SerialPort COM4 not found
              Dec-26 7:46:46 PM	 	drhsIpPlugIn	Starting serial client for DAB1 on COM4
              Dec-26 7:46:44 PM	 	drhsIpPlugIn	Stopping DAB1...
              Dec-26 7:46:35 PM	 	drhsIpPlugIn	BuildComPortList: Item has already been added. Key in dictionary: 'COM7' Key being added: 'COM7'
              Dec-26 7:42:42 PM	 	Z-Wave	Device: Node 22 Z-Wave Temperature Set to 26.62 (C)
              Dec-26 7:39:13 PM	 	drhsIpPlugIn	DAB1 - closing serial client
              Dec-26 7:21:37 PM	 	DAB1_Parse_In	Data(1) :+OK
              Dec-26 7:21:37 PM	 	DAB1_Parse_In	Data(0) :+V324
              Dec-26 7:21:37 PM	 	DAB1_Parse_In	param(0):DAB1 Data:+V324 +OK
              Note: this does not occur with any other serial clients I have tested with the DAB1 device on the same windows machine so I suspect the plugin does not detect a disconnect event and try reconnecting.

              I suspect it's the code assuming that once the port is opened, it never closes. This is not the case...a cable may fall lose or .net may pull one of it's tricks and crap out the serial. perhaps check if the port is .Open when doing a write (and every now and then) and if not open it?



              Edit: Just going to say it....it would be sooo much easier to debug this if you' publish the source...just saying.
              Last edited by davros; December 26, 2016, 08:31 AM.

              Comment


                IP/Serial Plugin by "drule"

                Where can I get drule's IP/Serial Plugin?
                I cannot find it on the plugin list

                Comment


                  Originally posted by wmcmath View Post
                  Where can I get drule's IP/Serial Plugin?
                  I cannot find it on the plugin list
                  Here you are
                  cheeryfool

                  Comment


                    Hey Drule or Cherryfool...any updates?

                    I've sent PM'd and given detailed feedback and I can see you posting on other threads so I know you're about...

                    Can you please let me know you if are or are not going to look at the issues raised.

                    PS I get it's yours and it's free and all that...however i would appreciqte a response - even a one line response "busy, go away"
                    Last edited by davros; January 12, 2017, 03:27 AM.

                    Comment


                      Serial questions

                      Hello
                      I a have a few questions:
                      1. does anyone have a complete list of the serial commands to control an LG TV (49LB5550)
                      2. I have tried a number of different ways to configure the PI using a GC100-18 to control the TV using the service port with no luck. Any suggests would be greatly appreciated!
                      Attached Files

                      Comment


                        Originally posted by sjz26 View Post
                        Hello

                        I a have a few questions:

                        1. does anyone have a complete list of the serial commands to control an LG TV (49LB5550)

                        2. I have tried a number of different ways to configure the PI using a GC100-18 to control the TV using the service port with no luck. Any suggests would be greatly appreciated!


                        Here is a source for the serial commands:

                        http://activatethespace.freshdesk.co...gs-for-lg-tv-s

                        It appears you need to be sending commands to port 4001

                        It looks like carrier return is the terminator so I'm thinking the power off command would look like:

                        ka 01 00/r

                        Comment


                          thank you for your reply, still unable to connect...

                          any other suggestions

                          I would really appreciate anyones help here. Really want to get this one working

                          Comment


                            Originally posted by sjz26 View Post
                            thank you for your reply, still unable to connect...

                            any other suggestions

                            I would really appreciate anyones help here. Really want to get this one working


                            It appears I put the wrong slash on the command. It should be:

                            ka 01 00\r

                            Try that and see what happens.

                            Comment


                              Still unable to connect. My thought is to remove the GC100 for testing an connect directly from a PC. Do you know the best program and setup to accomplish this?

                              Has anyone tried using a serial to usb on a LG TV?
                              Last edited by sjz26; January 24, 2017, 08:45 PM.

                              Comment


                                New Benq Projector to setup

                                I am using this successfully with 2 other serial devices and just got a new BenQ projector and it has an RS232 port.

                                I (mostly) know my way around this (most awesome) plugin and am just looking for some help getting the serial commands correct.

                                According to the Benq doc this is the Power On command:
                                Power On: <CR>*pow=on#<CR>

                                How should I enter this command in the in the plugin?
                                Thanks,
                                Darren

                                Comment

                                Working...
                                X