[SOLVED] String item not updating from TCP binding

Hi All,
Hoping someone can help - I have a String item bound to a TCP socket that isn’t updating when a string comes in over the socket.

(I couldn’t get it to work on OH2, so now on OH1.8 and having the exact same issue)

I have in openhab.cfg:
tcp:updatewithresponse=true

My item:
String amx {tcp="<[10.0.1.63:*:default]"}

I see this in the terminal so I know the string is coming into the socket:
2018-04-07 17:36:00.019 [INFO ] [runtime.busevents ] - amx state updated to testString

But my rule is not triggering:
rule “Test”
when
Item amx received update testString
then
sendCommand(amx, “String received!”)
end

Seems like the String item is always in a state of ‘Null’.

If I change the rule to:
“when
Item amx received update”
Then it triggers on any string that comes in and I receive “String received!” on my tcp client.

Cheers

Dave

Hello,

Please use code fences when posting, please…

Try:

rule “Test”
when
    Item amx received update "testString"
then
    amx.sendCommand(“String received!”)
end

Note that I have used the item method amx.sendCommand instead of the action sendCommand(String, String). It is recommended to use the method when you know what item to send a command to. Use the action only for some reserved cases like:

https://docs.openhab.org/configuration/rules-dsl.html#sendcommand-method-vs-action

Thanks for the reply :slight_smile:
And the tip for the fences!

I had already tried this as well with no luck - see below. Sending in testString didn’t trigger the rule.
With the code block you posted, is there a difference with the double quotes? Some are angled and some are vertical. When I pasted yours straight into mine it changed the syntax highlighting based on the different double quotes.

rule "Test"
when
    Item amx received update "testString"
then
    amx.sendCommand("String received!")
end

I can also try this as a test to see what “String” is being held it the item “amx” after sending in a string:

rule "Test"
when
    Item amx received update
then
    amx.sendCommand(amx)
end

The log:

2018-04-07 19:41:51.752 [INFO ] [runtime.busevents             ] - amx state updated to something

2018-04-07 19:41:51.783 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Test': Could not invoke method: org.openhab.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.String) on instance: null

Cheers

Dave

Try

rule "Test"
when
    Item amx received update
then
    logInfo("TEST", amx.state.toString)
    //amx.sendCommand(amx)
end

What does the log show?

This:

2018-04-07 20:26:14.802 [INFO ] [runtime.busevents             ] - amx state updated to something

2018-04-07 20:26:16.077 [INFO ] [org.openhab.model.script.TEST ] - something

Ok so that works!!
Next, the double quotes denote a String

rule "Test"
when
    Item amx received update "something"
then
    logInfo("TEST", amx.state.toString)
    //amx.sendCommand(amx.state.toString)
end

Yes, interesting that the item does actually hold the incoming string.

But still no trigger:

2018-04-07 21:11:42.524 [INFO ] [runtime.busevents             ] - amx state updated to something


Cheers

Ok then, workaround

rule "Test"
when
    Item amx received update
then
    logInfo("TEST", amx.state.toString)
    if (amx.state.toString == "something") {
        logInfo("TEST2", amx.state.toString)
    }
    //amx.sendCommand(amx.state.toString)
end

Still no luck:

rule "Test"
when
    Item amx received update
then
    logInfo("TEST", amx.state.toString)
    if (amx.state.toString == "something") {
        logInfo("TEST2", amx.state.toString)
    }
    //amx.sendCommand(amx.state.toString)
end
2018-04-07 21:26:26.043 [INFO ] [runtime.busevents             ] - amx state updated to something

2018-04-07 21:26:26.064 [INFO ] [org.openhab.model.script.TEST ] - something


Cheers

Ok, your something string is not exactly “something” that’s why it’s doesn’t go in the if test and doesn’t trigger the rule.

Is there a trailing space or hidden character?

I wonder if there is a carriage return / line feed attached to it somehow?
This would also explain why I had no trouble doing almost exactly the same thing a few years ago with openHAB1.7.0 but with a serial connection instead of the tcp socket. I wonder if the socket is passing through the carriage return.

I’m using netcat on a MAC terminal to connect to the openHAB socket, and just typing “something” (without the quotes) and hitting enter.

I could try using packet sender on a windows machine with could probably send the string without a carriage return.

Is there a way in openhab to test the if statement with a carriage return as well? Like “something”\r ?

20:26:14.802 [INFO ] [runtime.busevents             ] - amx state updated to something

2018-04-07 20:26:16.077 [INFO ] [org.openhab.model.script.TEST ] - something

Is that your actual log?
If yes then there is a carriage return
How do you get the item updated?
What is the binding?

Yeah you’re right it’s putting a new line in! Yes actual log.

The binding is: https://github.com/openhab/openhab1-addons/wiki/TCP-Binding

Item:

String amx {tcp="<[10.0.1.63:*:default]"}

“How do you get the item updated?” Using a tcp client (netcat) on a MAC, typing something and hitting enter.

I have some software on windows that can send just the bytes we want and not a carriage return, I’ll try that.

And if successful, the control system I’ll be using once I set all this up can send without a carriage return as well.

Cheers

Got it to trigger by sending the update from a different tcp client (packet sender) which doesn’t add a carriage return!

2018-04-07 22:25:20.972 [INFO ] [runtime.busevents             ] - amx state updated to something
2018-04-07 22:25:20.982 [INFO ] [org.openhab.model.script.TEST ] - something
2018-04-07 22:25:21.104 [INFO ] [org.openhab.model.script.TEST2] - something

I should be right from here. Thanks heaps for all your help! :slight_smile:

Cheers

Dave

You can try the trigger now

rule "Test"
when
    Item amx received update "something"
then
    logInfo("TEST", amx.state.toString)
    //amx.sendCommand(amx.state.toString)
end

Yes i have the rule triggering now, and also the sendCommand works to send a response back out over the socket.

Thanks so much for your help!

Cheers

Dave

That’s good…
A bit of a struggle but we got there :slight_smile:
Please mark the thread as solved, thank you
Good luck