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

TCP Quick App with login and password


sergiobaiao

Question

Hi there,

 

Can any of you help me adapt the sample TCP.fqa (TCP Client Quick App) so it has a login and password sent while connecting?

 

I used to have a VD in HC2 that, when clicking on the VD button, it would connect to my device, send the login and password, wait for the "telnet" prompt and then send the command. I really need this working on HC3, but i'm not able to get it working by myself.

 

Please help me

Please login or register to see this attachment.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
11 hours ago, sergiobaiao said:

Hi there,

Can any of you help me adapt the sample TCP.fqa (TCP Client Quick App) so it has a login and password sent while connecting?

I used to have a VD in HC2 that, when clicking on the VD button, it would connect to my device, send the login and password, wait for the "telnet" prompt and then send the command. I really need this working on HC3, but i'm not able to get it working by myself.

This is a start. It can still have some issues with your specific device.

Configure quickAppVariables for ip and port and a good test that the net.TCPSocket also worked with the

Please login or register to see this link.

:-)

(It's quite useful to develop in a real IDE when debugging socket protocols....)

 

Please login or register to see this attachment.

The code is actually quite small 

Please login or register to see this code.

 

Edited by jgab
Link to comment
Share on other sites

  • 0
  • Inquirer
  • thank you very much. I'll test it and post here the results.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I tried to modify the QA to make it a little "more flexible" but it didn't work. I've added 3 variables to it, login, password and LID (being the ID of the Lutron Lighting Zone).

     

    As this will be controlling a Lighting zone, there should be buttons for both ON and OFF at least, maybe a slider if it's a Dimmable zone. So what i this was add this to onInit:

     

    self.login = self:getVariable("login")               -- "lutron" 
    self.password = self:getVariable("password")               -- "integration" 
    self.lID = self:getVariable("LID")               -- "41" 
     
     
    then i created a copy of the "commands" variable and tried to make it work with my created variables, and that thrown an error:
     
    local commandsON = {
      250,"W:".. self.login .."\r\n","R:(.*)",
      250,"W:".. self.password .."\r\n","R:(.*)",
      250,"W:#OUTPUT," ..self.LID.. "41,1,100\r\n",
      250,function(cmds,n,res) 
        quickApp:updateView('status','text','OK')
      end
    }
     
    local commandsOFF = {
      250,"W:".. self.login .."\r\n","R:(.*)",
      250,"W:".. self.password .."\r\n","R:(.*)",
      250,"W:#OUTPUT," ..self.LID.. "41,1,0\r\n",
      250,function(cmds,n,res) 
        quickApp:updateView('status','text','OK')
      end
    }
     
    -- This would be a dimmer like command, setting the zone to 30%, reading the value from a slider
    local commandsDIM = {
      250,"W:".. self.login .."\r\n","R:(.*)",
      250,"W:".. self.password .."\r\n","R:(.*)",
      250,"W:#OUTPUT," ..self.LID.. "41,1,30\r\n",
      250,function(cmds,n,res) 
        quickApp:updateView('status','text','OK')
      end
    }
     
     
    Can you help again to adapt it? 
     

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
    13 minutes ago, sergiobaiao said:

    I tried to modify the QA to make it a little "more flexible" but it didn't work. I've added 3 variables to it, login, password and LID (being the ID of the Lutron Lighting Zone).

     

    As this will be controlling a Lighting zone, there should be buttons for both ON and OFF at least, maybe a slider if it's a Dimmable zone. So what i this was add this to onInit:

     

    self.login = self:getVariable("login")               -- "lutron" 
    self.password = self:getVariable("password")               -- "integration" 
    self.lID = self:getVariable("LID")               -- "41" 
     
     
    then i created a copy of the "commands" variable and tried to make it work with my created variables, and that thrown an error:
     
    local commandsON = {
      250,"W:".. self.login .."\r\n","R:(.*)",
      250,"W:".. self.password .."\r\n","R:(.*)",
      250,"W:#OUTPUT," ..self.LID.. "41,1,100\r\n",
      250,function(cmds,n,res) 
        quickApp:updateView('status','text','OK')
      end
    }
     
    local commandsOFF = {
      250,"W:".. self.login .."\r\n","R:(.*)",
      250,"W:".. self.password .."\r\n","R:(.*)",
      250,"W:#OUTPUT," ..self.LID.. "41,1,0\r\n",
      250,function(cmds,n,res) 
        quickApp:updateView('status','text','OK')
      end
    }
     
    -- This would be a dimmer like command, setting the zone to 30%, reading the value from a slider
    local commandsDIM = {
      250,"W:".. self.login .."\r\n","R:(.*)",
      250,"W:".. self.password .."\r\n","R:(.*)",
      250,"W:#OUTPUT," ..self.LID.. "41,1,30\r\n",
      250,function(cmds,n,res) 
        quickApp:updateView('status','text','OK')
      end
    }
     
     
    Can you help again to adapt it? 
     

    Please login or register to see this attachment.

    You can't use 'self' outside the QuickApp functions

    Especially this won't work

    local commandsON = {
      250,"W:".. self.login .."\r\n","R:(.*)",
      250,"W:".. self.password .."\r\n","R:(.*)",
      250,"W:#OUTPUT," ..self.LID.. "41,1,100\r\n",
      250,function(cmds,n,res) 
        quickApp:updateView('status','text','OK')
      end
    }
     
    I would create the table in the QuickApp:login function that hands it to doCommands(...). There you have self defined.
    You could then also have other buttons that sends other command lists to doCommands() to do other stuff.

    Updated the example by moving commands into login()...

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 38 minutes ago, jgab said:

    You can't use 'self' outside the QuickApp functions

    Especially this won't work

     

    local commandsON = {
      250,"W:".. self.login .."\r\n","R:(.*)",
      250,"W:".. self.password .."\r\n","R:(.*)",
      250,"W:#OUTPUT," ..self.LID.. "41,1,100\r\n",
      250,function(cmds,n,res) 
        quickApp:updateView('status','text','OK')
      end
    }
     
    I would create the table in the QuickApp:login function that hands it to doCommands(...). There you have self defined.
    You could then also have other buttons that sends other command lists to doCommands() to do other stuff.

    Updated the example by moving commands into login()...

     

    Hi Jan,

     

    In the QA file you sent me, does it keep the connection established all the time? Or it connect only when sending the command? 

    Link to comment
    Share on other sites

    • 0

    The last ”command” closes the socket

    Please login or register to see this code.

    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...