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)’]"}
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)?
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.
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.
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)']"}
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.
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
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.
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
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.