This page last changed on Aug 01, 2015 by rayon02.

Hi, I am a new user of openremote and I want to interface openremote with a microcontroller which has a temperature sensor(DS1820) attached to one of its pins through serial protocol. The temperature will be displayed in a label. I use a button in order to send the temperature reading command (COM2/ 9600/ 'A'). How can I display the temperature in a label since this requires a sensor? If I use the reading command(as a sensor command) the microcontroller is busy with temperature monitoring and I don't want this. ( it must do something else). So I write a rule:

rule "Read Temperature"
when
CustomState(source=="DS1820", $v: value)
then
double correctedValue = Double.parseDouble($v.toString());
double fahrenheit = (correctedValue*9) / 5 + 32;
execute.command("VTEMP", String.format("%.1f \u2103 / %.1f \u2109", correctedValue, fahrenheit));
end

1) Every time when the microcontroller send a string ( the string which contain the temperature) is it triggered the DS1820 sensor? Namely, OR send the command of the DS1820 sensor ('A')?(I know that the VTEMP command is also performed => display temperature ) But the microcontroller sends the tempererature once I push the button, hence the reading command ('A') is executed indefinitely....=> the microcontroller is busy with temperature sending (the above situation)

Is there any solution for the DS1820 sensor to be executed at least when the temperature is changing? I don't know... something like this: $v:value!= last result

2) If I have a second sensor connected to another pin, how could I display both values in different labels?

Any advice would be appreciated. Thanks!

Sorry for my English!


readSensors.png (image/png)
Capture.PNG (image/png)

If I use the reading command(as a sensor command) the microcontroller is busy with temperature monitoring and I don't want this. ( it must do something else)

Can you elaborate on this? Why you can't use the reading command?

Unless your microcontroller can generate an UDP message and send it to Openremote, the reading command with pooling interval is the only option.

Posted by aktur at Aug 03, 2015 13:52

I have: a button (sends the reading command: 'A')
a sensor (DS1820/the reading command/custom)
a label linked to sensor

1)OR: I press the button => OR sends 'A' (the reading command)
2)microcontroller: receives the reading command, and then it sends the temperature : printf("31,5 \r\n")
3)OR: recieves the string ( "31,5") => the rule triggers => the temperature is dislayed in a label(which is OK) and the reading command('A') also is executed;
4)microcontroller: recieves the reading command ('A') again => the step 2 is performed again... then step 3, step 4....then step 2 again and so on.

Thus the microcontroller is busy with the temperature monitoring....I want to do something else (conversion,LCD temperature display,...)

And.... Do you have an answer for the question 2? (2 sensors in 2 different labels)

Posted by rayon02 at Aug 03, 2015 17:35

I don't understand why in 3) the reading command is executed again and why this is correlated with pressing the button? The rule sets only in-memory variable, it does not call the microcntroller.

Although I might have an answer for question 2, first I need fully understand what you are doing.

Posted by aktur at Aug 03, 2015 22:22

Look at this code:

rule "Read Temperature"
when
CustomState(source=="DS1820", $v: value)
then
double correctedValue = Double.parseDouble($v.toString());
double fahrenheit = (correctedValue*9) / 5 + 32;
execute.command("VTEMP", String.format("%.1f \u2103 / %.1f \u2109", correctedValue, fahrenheit));
end

When OR receives a string the VTEMP command is executed but it seems that it's also executed the command of the DS1820 sensor.
(in my project the command of the sensor is the reading command which it is also the command of the button in UI)

in step 3 OR receives the temperature as a string (because I press the button=> the microcontroller sends the temp),then
it executes the VTEMP command and it also executes the command of the sensor (the reading command).

I don't know why it's executed the reading command again, but inside the label (in UI), the temperature is changing continously..... I want to change the temperature ONLY if I press the button.

Posted by rayon02 at Aug 04, 2015 00:15

Another thing: Which is the role of a command in a sensor inside a rule? ( the command of the DS1820)...It is a write command, isn't it?

Posted by rayon02 at Aug 04, 2015 00:33

Please show me how you've defined the VTEMP command. The rule is for temperature conversion and VTEMP should be in memory Virtual command (as indicted by the first letter V, which I use as a name for each in-memory virtual commands to distinguish them from device commands).

The role of this command is to pass converted temperature value to a sensor which is linked to VTEMP command.

Posted by aktur at Aug 04, 2015 08:48

name: VTEMP
protocol: In-memory Virtual Command
command: status
adress: VTEMP

for temperature reading: ReadTemp /Serial/ COM2/ 9600bps/'A'
for DS1820 sensor: DS1820/ ReadTemp/ custom

name: VirtualSensor
command: VTEMP
type: custom

VirtualSensor is linked to a label.
the button has the ReadTemp command.

Do you say that the role of ReadTemp (in DS1820 sensor) is only to pass the temperature received to the VirtualSensor?....
So it no longer matter which is the command of the DS1820 sensor.... whether is the ReadTemp or not... Thus I could define another command for the DS1820 sensor...and I could keep the ReadTemp command for the button

Posted by rayon02 at Aug 04, 2015 12:03

It is not the rule which triggers the reading command. Are you sure that the pooling interval of the ReadTemp is not set?

Anyway, it won't work the way you want, i.e. press button -> one temperature read. This is because the instance of ReadCommand attached to the button is not linked with a sensor, therefore it's return value will be lost. Right now you probably are pooling the microcontroller all the time. You can decrease the pooling interval so the microcontroller has more time for other tasks.

Of course you can define more commands for the DS1820 sensor but triggering them with a button is not feasible in Openremote. Each command needs separate sensor definition which it can be linked to. You can call these commands from a rule but their return value wont be passed back. So you really need sensors for all commands.

Posted by aktur at Aug 04, 2015 15:10

Thank you for your help Michal!
I understand what you say, but, however I feel that I'm missing something... Let's forget the buttons

1)What are the conditions for triggering the rule?
Must I send a string from the microcontroller in order to trigger the rule (to execute the VTEMP command? ($v:value)=> the microcontroller has to start the communication
For value =="on"=> the rule will be triggered only if I send the "on" string ?

2)How could I set the polling interval? In my command definition there is no polling interval.. I've seen that HTTP protocol has a polling interval... I could insert a delay in the microcontroller's software or maybe I could write timer (int: 1s 00h)
before "when" statement

Posted by rayon02 at Aug 04, 2015 22:01

1) the rule is started when the sensor DS1820 is updated (changes value). If you constraint a value then it will be triggered only when the value condition is true.

2) Unfortunately, serial protocol is not a part of pro controller, which I'm using. It seems to be a beta feature. Anyway, all my commands have polling interval, which serial protocol is obviously missing.

Posted by aktur at Aug 06, 2015 08:41

Hello, again!

How could I display multiple values of temperature in different labels? (10 sensors - 10 labels) Must I use rules?

Posted by rayon02 at Aug 16, 2015 00:29

You don' have to use rules for multiple sensors.

Posted by aktur at Aug 16, 2015 09:35
Document generated by Confluence on Jun 05, 2016 09:31