eXadra
(Pedro)
July 17, 2017, 9:21am
1
Hello all.
I receive a string value from a sensor using MQTT, this string has sensor values and after beying parced I store it in a numerical variable, lets call it Sensor1, the data.
Until here all OK.
This variable is has an 8 bit value, form 0 to 255 where each bit represents a boolean state of a device.
So I need to retrieve the value from bits 0,1,2… to update switch type items from Sensor1 using a AND mask.
I tried
“
if (Sensor1 AND 0x01) postupdate(Alarm1,ON)
else postupdate(Alarm1,OFF)
”
but I get erros…
Whow should be the check made?
Thanks
opus
(Jürgen Baginski)
July 17, 2017, 11:49am
2
Have a look at this old post.
eXadra
(Pedro)
July 17, 2017, 4:40pm
3
Thanks.
It works fine if the value is comming from an Item
"
var myState = (Gen_Alarm.state as DecimalType).toBigDecimal.toBigInteger
if (myState.testBit(1) ) postUpdate(Gen_lowFuel,OFF)
else postUpdate(Gen_lowFuel,ON)
"
but if the value comes from a variable I get an error
"
var myState = valor.toBigDecimal.toBigInteger
if (myState.testBit(1) ) postUpdate(Gen_lowFuel,OFF)
else postUpdate(Gen_lowFuel,ON)
"
valor is a Numerical variable.
opus
(Jürgen Baginski)
July 17, 2017, 6:15pm
4
Use a logInfo to display the differences and what is the error?
eXadra
(Pedro)
July 18, 2017, 1:00pm
5
Back
As I posted before if I use the source of data from a Item all works;
“
var myState = (Gen_Alarm.state as DecimalType).toBigDecimal.toBigInteger
”
But, if I use a Numerical variable like below
"
var Number valor=7 (value here is hardcoded just for example)
var myState = valor.toBigDecimal.toBigInteger
logInfo(“test”,“nhala parcing, ITEM:” + myState.toString )
if (myState.testBit(1) ) postUpdate(Gen_lowFuel,OFF)
else postUpdate(Gen_lowFuel,ON)
"
I get this error in Eclipse
"
Multiple markers at this line
Couldn’t resolve reference to JvmIdentifiableElement ‘toBigDecimal’.
Couldn’t resolve reference to JvmIdentifiableElement ‘toBigInteger’.
"
And, if I run it, I get the following error:
" Error during the execution of rule ‘nhala rec’: The name ‘.toBigDecimal’ cannot be resolved to an item or type.
"
Any ideas?
opus
(Jürgen Baginski)
July 18, 2017, 2:11pm
6
Try valor.toString.toBigDecimal.toBigInteger
eXadra
(Pedro)
July 19, 2017, 10:28am
7
Thanks for the help Jürgen,
I triyed the solution of your post
“
Try valor.toString.toBigDecimal.toBigInteger
”
It still shows the error:
"
Multiple markers at this line
Couldn’t resolve reference to JvmIdentifiableElement ‘toBigDecimal’.
Couldn’t resolve reference to JvmIdentifiableElement ‘toBigInteger’.
"