This page last changed on Feb 15, 2014 by pjmm.

I have a text file which has one line with either "On" or "Off" I want to write a batch file which will
read this text file and update a sensor

I need help in writing this batch file

can some one give me an example

I had a look at my last post and I need to explain it better.

I know how to create a batch file to open a text file and read from it

This is my batch file

set /p "var="<"data.txt"
echo %var%

for /f "delims=" %%a in (data.txt) do set "var=%%a"&goto :stop
:stop
echo %var%

If you are running this from the command line it reads "On" from Data.txt and echos on to the display.

I propose to run this batch file using Shell Execution which I have tested and it starts the batch file OK

My question "is echo the correct command to use in order for Openremote to read in the status or should I be using
some other command"

Posted by pjmm at Feb 16, 2014 15:54

I am still working on reading a value from a text file and updating a sensor

I can start the batch file which should read on from the text file and it should updates the sensor

If I look in the device log I can see that it starts the script but I cannot see it receiving the data

2014-02-18 18:51:27,897 INFO main: Registered sensor : Sensor (Name = 'sensor1', ID = '232505', State Mappings: {})
2014-02-18 18:51:27,899 INFO main: Startup complete.
2014-02-18 18:51:27,900 INFO main: Controller Definition File Watcher for Default Deployer started.
2014-02-18 18:51:27,912 TRACE [Polling thread for sensor: sensor1 232505]: Processed '', received ''
2014-02-18 18:51:28,922 TRACE [Polling thread for sensor: sensor1 232505]: Processed '', received ''

It is poling every second as set up

I am not sure what string I should send with the On

any pointers would help

Posted by pjmm at Feb 18, 2014 19:40

Hi Pierce - I don't actually have a Windows machine to experiment with, but I would try a couple of things here...

First, Try to re write your batch file to only need one 'echo' command. OR is probably going to read only one of them - either first or last (unsure of behavior on windows).

Second, make sure your OR Shell Execution command has a regex entered to read back the echoed response. The following should pull back everything

^(.*).*
and you can tweak from here to refine this if needed

Third, and I got caught on this myself , double check you are using a 2.1 version of controller that actually supports regexing feedback from shell commands. Some of the earlier version will execute the commands, but cant perform the regexing.. OpenRemote-Controller-2.1.0_FM_SNAPSHOT-2013-07-18 works for me..

Hope some of this helps a bit, let me know..

Posted by holeymoley at Feb 18, 2014 23:21

Hi Paddy

many thanks for the reply I have tested a simple batch file

echo No
:end
:exit

I can see this read in by Openremote

If I set the variable var to No and try this batch file it dosen't work

echo %var%
:end
:exit

If I run it at the command prompt it returns No which is correct

Have you any ideas

Pierce

Posted by pjmm at Feb 19, 2014 23:23

i'm trying exactly the same thing and having problems. I'm using the file to store the state of x10 switches. I can write out the file via a shell execution script, and have written the shell script which should read back in the contents of the text file. I can't get this value to update a sensor state or be used in a rule.

I've just read something that said regex looks for a crlf at the end of the line, so am trying \n in the shell script - will let you know if this works.

Posted by nickbrookes76 at Feb 20, 2014 21:21

Problem Solved

In order for my batch file to work the Data file and Batch file must be in
the C:\OpenRemote-Controller\bin directory

The following .bat file reads in the data from data.txt

@echo Off
set /p "var="<"data.txt"
@echo On
%var%
:end
:exit

Posted by pjmm at Feb 21, 2014 20:37

Can any one confirm that the Regex under

Shell Execution works correctly.

My program reads in a from a text file into openremote

C:\OpenRemote-Controller-2.1.0_SNAPSHOT-2013-06-17\bin>echo Off

I use the Regex ^.*(On|Off) to extract Off

I have tested this using the online Regex tester and it returns Off

in Openremote I get

2014-02-23 20:16:58,609 INFO [Polling thread for sensor: sensor1 232564]: regex evaluation did not find a match
2014-02-23 20:16:58,610 TRACE [Polling thread for sensor: sensor1 232564]: Processed 'N/A', received 'N/A'

I have looked at Max's post saying that the Regex he used unde Shell Executionwas was
(on|off)\s(on|off)\s(on|off)\s(on|off)\s(on|off)\s(on|off)\s(on|off)\s(on|off)\s
to extract On Or Off from
off off off off off off off off

I have tested this using the online Regex tester and cannot get it to work

Posted by pjmm at Feb 23, 2014 20:25

The regex implementation is provided by the Java class libraries, so it would either fail on all regular expressions or should work on all of them.

Note that Java regex may slightly differ from other language runtimes. Also the ending line feed characters seem to often cause issues with matches.

Posted by juha at Mar 05, 2014 16:57

Hi Pierce, I realise it's a while ago but I have been trying to use the same system you have outlined here.
My problem is that I get a java IO exception saying cannot run program.
I have virtually copied your batch file and placed both files in the controller.bin directory.
If you have any other suggestions I would appreciate them.
If UDPlistener would work on the free version of OR that would even be better.
Thanks, and have merry christmas.
Fraser

Posted by freddyc at Dec 23, 2015 05:10
Document generated by Confluence on Jun 05, 2016 09:38