Heartbeat
alecg
Posts: 30
Hi all. AMX noob question here:
What is best practice for generating heartbeat scripts in NetLinx Studio?
Specifically, I'm controlling a Sharp TV via IP. My commands work fine, but after an hour or two, the connection seems to close, after which my commands fall on deaf ears. I'd like to powercheck the TV every 10 seconds or so and if it doens't respond, re-initialize the connection (IP_Client_Open).
Is there a correct way to do this? Or does my failure come from a more fundamental lack of programming knowledge (all I'm doing is the IP_Open command on start)?
Any help is very much appreciated!
What is best practice for generating heartbeat scripts in NetLinx Studio?
Specifically, I'm controlling a Sharp TV via IP. My commands work fine, but after an hour or two, the connection seems to close, after which my commands fall on deaf ears. I'd like to powercheck the TV every 10 seconds or so and if it doens't respond, re-initialize the connection (IP_Client_Open).
Is there a correct way to do this? Or does my failure come from a more fundamental lack of programming knowledge (all I'm doing is the IP_Open command on start)?
Any help is very much appreciated!
0
Comments
How about you do an OPEN anytime you have a command to send? If you are still open from a recent prior command, the new open will error but that really doesn't matter... unless you have bursts of lots of commands and don't want to see the error clutter in telnet/diagnostics. In which case, look away, or reset a timer when you open, and skip the reopen if a new command is issued before a timeout you decide works for you and the connection.
It seems like John's solution is more appropriate for my use case in light of how simple my control requirements are, but I very much like the idea of using a status flag to qualify the need for the OPEN (or any other type of comms structure for that matter). I just seem to have a LOT to learn yet!
Thank you for the assistance, I will post my results shortly.
Http you don't have a choice and have to open/close per command but connection that can maintain are often easier to maintain but that's just extra work for the processor. Either way though is really totally acceptable and I'll go either way depending on my mood that day.
Good luck.
I did not realize that the controller would manage that connection in its own right and report the verified connection status as an ONLINE and OFFLINE event without any further intervention from me. Following your advice I created a connection status flag with an off state, on state and waiting state. When an ONLINE or OFFLINE Event happens, the flag updates, when I initiate or kill a connection the flag updates, and when a command is requested it first evaluates the flag state before deciding how to proceed.
This is super cool and potentially way more reliable for not losing a command than some of the other systems I've been programming.
Now I'm onto incoming string parsing, but that's an entirely new thread.
Thanks very much for your help!
I do, however, still have a problem with Sharp IP connections dropping immediately on connect, if the TV isn't already on. This only seems to happen with the bigger sets, I've confirmed with 2 80" TV's but don't have the same problem with 60" sets. If the TV is on when the IP connection is made, no problem. It's only when the TV is off the connection picks up then drops immediately.
Always something strange, eh?
If you look at the Kaleidescape module for instance, for some reason it keeps track of many states, offline, online, pending, waiting, closed, open, error etc, as if it was dealing with raw sockets. I don't see any reason to do this, and in fact leads to more errors trying to second guess what the underlying socket is doing. Some devices will close the port after receiving a command, like most typical IP devices like Sonos, etc, and some will not like Extron (I believe). Either way it doesn't matter since if the offline or error event hasn't run since the last online event, you know its open so send away. When the offline event runs you know you have to open the port, and then wait until the online event occurs to send commands. Its really that simple.
Paul
I've have the AMX system essentially "ping" each device (varies by device and connection). It doesn't really matter the command as long as the piece of equipment returns some sort of string. Then on each string data_event I have a counter that resets. In the mainline of the code that counter increases ever X number of seconds. If XY number of seconds have passed without a response from the piece of equipment then the controller will attempt to reconnect. If that doesn't work, then an error message pops up on the touch panel screen alerting the user. Typically at this point the piece of equipment has locked up, the network has gone down, or a cable has been knocked loose.
I've found the offline/online to not be the most reliable, and if a piece of equipment does not come back online, the user should be notified to handle accordingly.
That's because there is no offline/online flag to track. It's not done on the hardware layer, best I can tell it's a simple "I'm getting responses," or "I'm not getting responses" from the socket, with a timeout.
If the transport protocol does not allow for maintain connection, like RESTful and SOAP, I will still maintain state of the device, and provide true feedback.
Although 100% of my device control is done with duet, so that may force me into this mind set.