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


Recommended Posts

Posted

Hi all,

 

Im trying to port the implementation i had in HC2 to HC3 regarding a TCPSocket i use to get data from a Solar inverter.

 

I can get it working by only using 1 write/read but when i try to do write/read using a set of commands, it all gets messed up which i think is because of the asynchronous write/read..

 

Any suggestion how to solve this?

 

Basically, i need to send one command, wait for the response and in "OnDataReceived" function handle it and after that is done, iterate through the next list of commands, etc.

 

BR

Posted (edited)

I've recently did something similar on HC3 when integrating with my AC unit. Usually such problems are due to poor implementation of the receiving side, not HC3. When you send multiple commands at once they can be sent in a single TCP packet. Properly programmed receiving side should handle such situation, but with simple devices it is often not the case.

 

To solve this problem, I've ensure that there is only one command sent over the network at once. If the code wants to send more commands, then they are queued until response is received.

 

The code is on GitHub here: 

Please login or register to see this link.


In particular, function sendCommand is here: 

Please login or register to see this link.


When it sends first command it sets a flag, waitingForResponse, which causes subsequent commands to be put in a queue

When a response is received, the flag is cleared and next command from the queue is sent, if any. That part is here: 

Please login or register to see this link.

 

End result is the code just uses sendCommand function and doesn't have to bother with anything else. Only one command is on the flight which makes the receiving device happy.

Edited by rraptorr
  • Topic Author
  • Posted

    Thanks rraptorr!
     

    It sounds like its exactly how i want it to behave.

    Ill have a look at your code, thanks again!

     

    BR

    Join the conversation

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

    Guest
    Reply to this topic...

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