TCP Binding to control multiple devices


I’m currently using the TCP binding to send simple commands to a network device which works perfectly. I’m doing this with a simple item like this:

String Device1 "[%s]" { tcp=">['REGEX((.*))']" }

Then I’m able to send commands to this device with no issues from my rules like this:

Device1.sendCommand ("command")

As I say, this all works perfectly. However I now want to control a second TCP device and I’m having issues with it. If I add a second item such as:

String Device2 "[%s]" { tcp=">['REGEX((.*))']" }

As soon as I create this second item I can see in the Openhab logs that the TCP binding is constantly creating new connections to the device, then getting disconnected and connecting again until the device I want to control eventually starts refusing connections until I restart it.

I’m not sure where I’m going wrong though? Can anyone advise on why the second device might affect the first? Can you only have 1 TCP controlled device at a time with this binding?

Thanks in advance for any help.

Comment out your Device1 so only the Device2 is active.

Does it exhibit the same behavior? If the answer is yes then the problem is specific to that device. If the answer is no then the problem is caused by having two or more Items.

Put the binding into debug log mode and watch the logs.

Once you narrow down the problem to either be caused by that one device or by having two you might have to file an issue on the binding. It should work.

Thanks for the suggestion and nudge in the right direction, both devices do work by themselves and now I’ve realised where the issue was I can get both running at the same time.

What I didn’t realise was that if you make a configuration change and add a new device to control by TCP you need to restart OpenHAB fully each time, otherwise you get lots of errors like this

23:42:53.519 [ERROR] [ing.tcp.AbstractSocketChannelBinding] - An exception occurred while scheduling a job with the Quartz Scheduler Unable to store Job : 'org.openhab.binding.tcp.protocol.internal.TCPBinding@791a5d.791a5d-Reconnect-1502491373519', because one already exists with this identification.

Then it constantly tries to connect to the devices again and again until they start refusing connections. I’ve got both up and running at the same time now. Thanks.