TCP Binding : "Could not find a mapping for..." / "Can not parse input..."

Hello,

I want to communicate with my weather station Davis Vantage PRO2 with the TCP Binding.

Here is my configuration file for “.items”:
Switch MeteoDavisStation “Station météo Davis” (gRDC) {tcp=">[ON:172.16.128.112:22222:‘MAP(MeteoDavis.map)’], >[OFF:172.16.128.112:22222:‘MAP(MeteoDavis.map)’]"}

Here is my configuration file for “MeteoDavis.map” (with communication reference manual: http://www.davisnet.com/support/weather/download/VantageSerialProtocolDocs_v261.pdf):
ON=LAMP 1
OFF=LAMP 0
UNDEFINED=inconnu
-=inconnu

But I don’t understand why I have: "Could not find a mapping for ’ ’ in the file ‘MeteoDavisStation’’ and “Can not parse input to match command ON on item MeteoDavisStation” (see attached doc)?

Thank you in advance for your help.

Flavien

Your Item is being set to what looks like a newline or carriage feed character and there is no mapping for that character nor can the TCP binding parse it to something meaningful and convert it to ON or OFF.

I don’t know if it is possible to put this sort of character into a MAP so you might need to move to a REGEX or JavaScript transform to deal with these odd messages.

According to the linked document, there is neither such command LAMP 1 nor LAMP 0 nor inconnu:slight_smile:

Hello,

Thank you for your reply and I’ll try to look in that direction.

Flavien

Hello,

I can communicate with my DAVIS console. I can for example turn on the light with these configurations:

Maison.items:
> Switch MeteoDavisStationLamp "Station météo Davis Lamp" <sun> (gRDC) {tcp=">[ON:172.16.128.112:22222:'MAP(MeteoDavis.map)'], >[OFF:172.16.128.112:22222:'MAP(MeteoDavis.map)']"} String Str1 "Str1 [%s]" (gRDC) {tcp="<[:172.16.128.112:*:'REGEX((.*\n)*)']"}

MeteoDavis.map:
ON = LAMPS 1\n OFF = LAMPS 0\n

But my goal is to retrieve weather data of course. However I do not know how to display this data in openHAB.

As a beginner, I tried several configurations with regex but nothing conclusive.

Therefore, how can I retrieve and display every minute for example my weather data please? (with script? rules?)

Flavien

PS: when I send my order to turn on the light of my DAVIS console, it returns me a \ nOK \ n as shown in the manual on page 21 (http://www.davisnet.com/support/weather/download/VantageSerialProtocolDocs_v261.pdf :
Example (turn the lamps off):
>"LAMPS 0"<LF> <<LF><CR>"OK"<LF><CR> )
.



The regular expression that should cut out the newlines should look something like this: (NOTE: according to the manual it isn’t using just \n but \r\n)

REGEX(\r\n(.*)\r\n)

which means give me everything between a “\r\n” and a “\r\n”.
or perhaps something a bit more inclusive:

REGEX(.*\n\r(.*)\n\r)

which means ignore everything at the start and end of the string and give me what is between "\r\n"s

You can match the “OK” exactly with:

REGEX(.*\"(OK)\".*)

which means give me the String OK if you see it between anything and quotes (returns nothing otherwise).

You can match numbers with:

REGEX(.*([\d\.]+).*)

which means ignore everything until you see one or more digits or a “.”. It is actually a little sloppy because you can have just a “.” or lots of "."s so this would probably be better:

REGEX(.*([\d]+[\.]?[\d]*).*)

which means ignore everything until you see a one or more digits followed but zero or one “.” followed by zero or more digits.

Hello,

Thank you very much for you answer @rlkoshak.

I tried all your suggestions and even this:
String Str1 "Str1 [%s]" (gRDC) {tcp="<[:172.16.128.112:*:'REGEX([\n|\r|\n\r|\r\n]\"(OK)\"[\n|\r|\n\r|\r\n])']"}

But I have still the same problem and I encountered an error with this formulation:
String Str1 "Str1 [%s]" (gRDC) {tcp="<[:172.16.128.112:*:'REGEX(\r\n(.*)\r\n)']"}

I really don’t understand the problem, even if the solution may be simple. Maybe the error comes from the configuration of my “.map”…

Thank you again for your support.

Flavien

As long as you have carriage returns and line feeds (i.e. \r\n) in the string that gets assigned to your Item the mapping will fail.

Beyond that, the “could not be parsed correctly” indicates a syntax error in your binding string (i.e. the stuff between the { }) and I don’t think it is the REGEX that is the problem in this case.

Upon the review of the TCP wiki page, you should not have that leading “:” in front of the IP address. As it says in the wiki:

For String Items : can be omitted

Also, I think you must supply a port number so the “*” after the IP address should be the actual port number. It doesn’t really make sense to use a wild card in this context.

Finally, if you are more comfortable with JavaScript, try using a JavaScript transform to strip the \r\n out of the returned value.

Hello,

Thank you for the additional information.

I’m also not an expert in JavaScript but I’m here to learn.

Flavien

Is it possible to chain REGEX() and MAP()?

In a rule.

Hello,

I’m sorry to bother you again.

I learned JavaScript and I wanted to test a simple example to run my js file. I managed to do an addition !! :+1: :weary:

rules file:
rule "REGEX Test" when Time cron "0/10 * * * * ?" then logInfo("TestJS","JS : " + transform("JS", "MeteoVantage.js", "1")) end

MeteoVantage.js:
// Wrap everything in a function (function(i) { return parseInt(i)+2; })(input) // input variable contains data passed by openhab

result:
[INFO ] [rg.openhab.model.script.TestJS] - JS : 3.0


Now I will wish to recover my famous “OK” of course.
I send my order in my items file.

Switch MeteoDavisStationLamp "Station météo Davis Lamp" <sun> (gRDC) {tcp=">[ON:172.16.128.112:22222:'MAP(MeteoDavis.map)'], >[OFF:172.16.128.112:22222:'MAP(MeteoDavis.map)']"}

And so I want to get my OK in my variable:
String MeteoJS "Test [%s]" (gRDC) {tcp="<[:172.16.128.112:22222:JS(MeteoVantage.js)]"}

But I get nothing. Indeed, I do not know how to configure my file. I am lost after trying several things…


My ultimate goal is to automatically receive and decode the chain received with weather data after sending the command “Loop 1” (cf. LOOP command p12 and 21 : http://www.davisnet.com/support/weather/download/VantageSerialProtocolDocs_v261.pdf).
If I replace LAMPS 1\n by LOOP 1\n in my map file, I receive:
[WARN ] [t.i.s.MapTransformationService] - Could not find a mapping for '♠LOO¶' in the file 'MeteoDavis.map'. [WARN ] [t.protocol.internal.TCPBinding] - Can not parse input ♠LOO¶ to match command ON on item MeteoDavisStationLamp

Flavien

This makes me think there might be a character encoding issue going on. I’m not sure how to help with that.

Hello,

Is it possible to set up a TCP connection in a rule? Indeed, I will wish to create a rule that every 10 seconds for example, the command “LOOP 1 \ n” is sent to my Davis station by the TCP binding.
Then I have to retrieve weather data, I have to analyse this data (probably with JavaScript), and display this data in my items file (number by number).
I think this is possible after watching this: https://github.com/openhab/openhab/blob/master/bundles/binding/org.openhab.binding.davis/src/main/java/org/openhab/binding/davis/datatypes/DavisValueType.java
But being beginner, I lack some basics to properly do this project.

Good evening,

Flavien

I think you have to set up the connection itself as an item. But you can send data out on that Item in a row using sendCommand. For incoming data you can also receive the value and parse out the parts into separate items in a row.

Hello,

Thank you for your answer, but I don’t know how to receive the data for analysis. Do you have an example please?

Flavien

Examples are on the wiki page. Look at the incoming sections.

Yes, but I tried again several parameters (as:
Number MeteoJS "Test MeteoJS [MAP(MeteoDavis.map):%s]" (gRDC) {tcp="<[172.16.128.112:22222:JS(MeteoVantage.js)]"}
, without success. Therefore, I can’t put a parameter in my JavaScript file for later analysis. Yet I get this message at initialization:
09:40:55.505 [DEBUG] [t.AbstractSocketChannelBinding:1238 ] - Setting up the inbound channel Channel [item=MeteoJS, command=0, direction=IN, remote=/172.16.128.112:22222, buffer=, isBlocking=false, isReconnecting=false, host=172.16.128.112, port=22222] 09:40:55.507 [INFO ] [t.AbstractSocketChannelBinding:1240 ] - We will accept data coming from the remote end /172.16.128.112:22222

Thanks for your help

I’m not in a place where I can fully analyze and answer.

The way it works is you set up an item to receive the data according to the wiki page. Create a rule that triggers when the item updates or changes. Parse out the data and send to other items in that rule.

The transforms are only if you want to extract one value from the incoming data to assign to this one item.