Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

VD & TCP/IP Commands


bker

Question

Hi All,

I am trying to get a understanding of creating VD's for control of my TV's and projector. I was able to download a VD from the Fibaro Market Place for my Panasonic TV which works. I am currently running v4.580

I have spent the last 2 days trying all sorts of different LUA codes to try and control my JVC projector which I can control via telnet from my laptop though I am stuck trying to do this from a VD. Below is what I have tried and the projector requires the following TCP/IP command PJREQ first then it leaves the socket open for 5 secs so you can send the next command. I am only looking to be able to turn it on & off. In the example below is the HEX string to turn the projector ON............apologies this is all new to me so any help would be very much appreciated

 

I have already assigned the correct IP address and Port in the advanced section of the VD..........I just can't workout how to sent the actual command strings

 

local device = fibaro:getSelfId();
local ipaddress = fibaro:getValue(device, "IPAddress");
local port = fibaro:getValue(device, "TCPPort");
FIBARO = Net.FHttp(ipaddress, port)
tcpSocket:write(string.char(PJREQ))
tcpSocket:setReadTimeout(5000);
tcpSocket:write(string.char(PJREQ));
tcpSocket:write(string.char(21 89 01 50 57 31 0A));
tcpSocket = Net.FTcpSocket(ip, port);

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
Guest Turmoil

I have just added an article on Lua programming for virtual devices which you can find here:

Please login or register to see this link.


Hope that helps with the lua comms side of things. Let me know if there is anything missing or I haven't explained something correctly.

 

Have you written a telnet client before? I seem to remember there is some sort of NVT (network virtual terminal) handshake required on connection setup which might be a bit tricky to start with. Once that's over it should be simple enough.

 

Let us know how you get on, good luck. T

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Hi Turmoil,

    I just finally got back to this after COVID and now I can control the JVC projector from my laptop using Hercules Ethernet control program, I checked out the link you sent me though I apologise I am none the wiser in creating the LUA commands in the VD that I have created for the projector. 

     

    I need to work out how to do the inital connection process, then I know I need to send PJ_REQ in ascii then send 21 89 01 50 57 31 0A in HEX to turn the projector on......any help would be greatly appreciated

     

    Best regards

    bker

    Link to comment
    Share on other sites

    • 0
    Guest Turmoil

    Hi bker, didn't get a notification on your post, so have only just seen it. On page

    Please login or register to see this link.

    you need to look at Using Net.FTcpSocket. This is because you do not want to use HTTP protocols and you do want total control of the data exchange. You need to specify the projector's IP address in the config and use port 23 (standard telnet), your documentation may say that the projector listens on a different port, in which case use that number. In the example code, the line local vdConn = Net.FTcpSocket(ipAddr, tcpPort); will attempt to build a connection to the configured IPaddr and Port, there is no feedback (standard Fibaro) you get an error when you attempt to write to the projector if the connection could not be established.

     

    The line local bytes, retc = vdConn:write("login z99u54"); can be changed to something like local bytes, retc = vdConn:write("PJ_REQ"); After checking the write completes, you issue a READ as in local resp, retc = vdConn:read(); Repeat the write/read sequence until you need to disconnect. Forget what I said about NVT negotiation, from your comments it sounds as if the projector is accepting all terminal types.

     

    It's going to be a case of experimentation to get this working. One suggestion is, if you have problems connecting when the projector is powered off, try to establish a connection with it already powered on. Sometimes the higher level protocols such as TCP (for telnet) are inactive when the projector is not powered on in which case you might need to use something like wake-up on LAN (I've not used this personally). In my case I could configure the projector to start immediately power is switched on and so I used a fibaro socket/switch to automatically turn the power and the projector on. You still need a connection to switch off, since the projector needs power to cool the bulb for some period.

     

    I just looked at your original post again: vdConn in the example code is a cross reference identifying the established connection (a bit like an instance of an object) that's why you need to reference it on all subsequent calls, vdConn:write() and vdConn:read(). So in your text remove the FIBARO = Net.FHttp(ipaddress, port), you don't want to use HTTP. Move the line tcpSocket = Net.FTcpSocket(ip, port); to where the FIBARO line was, put a local in front of it and you are halfway there. You need to issue read() calls to pick up the projectors response (or fail if no data is received within your ReadTimeout value). Read will cause the wait you need for the projector to process each request and be ready for the next one.

     

    regards, T

    Edited by Turmoil
    Link to comment
    Share on other sites

    • 0

    Hi @Turmoil

     

    This was VERY helpful. I have been trying to use HTTP to send simple text commands to a device without success when I should have used NET.FTcpSocket.

     

    To impose on you further, I also need my VD to monitor for incoming messages. These are from an alarm system which sends a text string indicating which motion sensor has been tripped. 

     

    Any advise on how I can program my VD to "listen" for these incoming messages and then respond by running a scene?

     

    Cheers  

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi Innervations,

    I have be occupied with other work around the house......looks like you know much more than me about this...I am struggling to get anywhere trying to get this JVC projector to work with HC2

     

    Cheers

    Bker

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...