help with reading reply

hey all,

the request is http post

http://192.168.0.201:8809

content-type is
Content-Type: application/x-www-form-urlencoded User-Agent: Dalvik/1.6.0 (Linus; U; Android 4.4.2; ASUS_T00J Build/KVT49L) Host: ipofnas:8809 Connection: Keep-Aliv Accept-Encoding: gzip

workload is
asremoteCmds/infoCmd=system get task system 0

returns

{“tid”: “1472081934.83”, “ui”: {“mainpage”: [“remotePad”], “subpage”: {“Player”: “”, “Exit”: “poweroff”, “Back”: “press back”, “Keyboard”: “”}, “subqueue”: {“1”: “Player”, “0”: “Back”, “3”: “Exit”, “2”: “Keyboard”}}, “appName”: “xbmc”}

``

i then need to read the tid and add it to this workload (the tid keeps changing)

change the workload to
asremoteCmds/controlCmd=1472081934.83 press left

when i do a sensor i can get it to show the return but i cant narrow it down to just the tid value.

then the next problem i foresee so copying that value to the workload.

if anyone can help that would be great :slight_smile:

Hi nick,

you can extract a field from the return value with JSONPath. For this example the correct string would be “$.tid”. More about JSONPath http://jsonpath.com/

You can pass a value to workload with ${param}. You can do this from a rule. For your example a rule would be something like: (not tested)

rule “pass tid to workload”

when

Event(source==“tid_sensor”, $v:value)

then

execute.command(“workload_command”, “asremoteCmds/controlCmd=”+$v.toString()+" press left");

end

thanks heaps Michal,

the rule didnt work though but i dont no anything about rules yet!! time to try and learn how to :slight_smile:

if i cant work it out i will post back

ok so have been looking for 4 hrs solid and cant get my head around rules. and how to get it to copy its values to a buttons workload

so i have 2 commands
command to send command “new_left” with workload = asremoteCmds/controlCmd=${param} press left

command to retrieve “get_tid” number using JSON “currently giving me 1472138127.24”

sensor for “get_tid”

rule

package org.openremote.controller.protocol

global org.openremote.controller.statuscache.CommandFacade execute;

global org.openremote.controller.statuscache.SwitchFacade switches;

rule “tid_to_workload” when

Event( source == “tid_sensor”, $v.value )

then

execute.command(“new_left”, asremoteCmds/controlCmd=+$v.toString()+ press left);

end

the aim is to get the tid number to paste its self to the ${param} in the buttons workload.

hope this makes sense

and thanks for the help :slight_smile:

Hi nick,

the rule can be simple

rule “tid_to_workload” when

Event( source == “tid_sensor”, $v.value )

then

execute.command(“new_left”, $v.toString());

end

because you’re adding other parts in the workload. It is always good to check the logs/boot.log to see if rules are initialised without syntax errors. Then you can look in logs/rules/drools.log and check if the rule is triggered with tid_sensor.

with out rules the boot log has no errors
with the rule in i get lines and lines of errors

DEBUG 2016-08-26 14:14:15,568 : Initializing event processor: Drools Rule Engine

DEBUG 2016-08-26 14:14:15,592 : Adding Rule ‘modeler_rules.drl’…

ERROR 2016-08-26 14:14:16,501 : Rule definition ‘modeler_rules.drl’ could not be deployed. See errors below.

ERROR 2016-08-26 14:14:16,501 : [ERR 101] Line 7:42 no viable alternative at input ‘)’ in rule “tid_to_workload” in pattern Event

ERROR 2016-08-26 14:14:16,502 : There was an error parsing the rule definition ‘modeler_rules.drl’ : Could not parse knowledge.

java.lang.IllegalArgumentException: Could not parse knowledge.

at org.drools.builder.impl.KnowledgeBuilderImpl.newKnowledgeBase(KnowledgeBuilderImpl.java:58)

at org.openremote.controller.statuscache.rules.RuleEngine.getValidKnowledgePackages(RuleEngine.java:532)

at org.openremote.controller.statuscache.rules.RuleEngine.start(RuleEngine.java:253)

at org.openremote.controller.statuscache.EventProcessorChain.start(EventProcessorChain.java:112)

at org.openremote.controller.statuscache.StatusCache.start(StatusCache.java:120)

at org.openremote.controller.deployer.Version20ModelBuilder.buildSensorModel(Version20ModelBuilder.java:659)

at org.openremote.controller.deployer.Version20ModelBuilder.build(Version20ModelBuilder.java:557)

at org.openremote.controller.deployer.AbstractModelBuilder.buildModel(AbstractModelBuilder.java:154)

at org.openremote.controller.service.Deployer.startup(Deployer.java:872)

at org.openremote.controller.service.Deployer.softRestart(Deployer.java:454)

at org.openremote.controller.service.Deployer$ControllerDefinitionWatch.run(Deployer.java:1411)

at java.lang.Thread.run(Thread.java:745)

``

and im guessing couse the rules are failing it hasnt made a log for drools.log

Oh, I see. You’ve replaced double dot with a single dot. The line with Event should be:

Event(source==“tid_sensor”, $v:value)

just like in my first replay.

yar sorry about that. when i was trying to learn rules most of the examples i sore only had . not :

now its giving me a different error. but i think its related to the version of java im using. JRE 1.8.0_31

ERROR 2016-08-26 16:58:51,811 : Error in rule definition ‘modeler_rules.drl’ : wrong class format

java.lang.RuntimeException: wrong class format

at org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:260)

at org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:204)

at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:102)

at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)

at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122)

at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromTypeSignature(LookupEnvironment.java:1188)

at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromVariantTypeSignature(LookupEnvironment.java:1244)

at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeArgumentsFromSignature(LookupEnvironment.java:1031)

at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromTypeSignature(LookupEnvironment.java:1193)

at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createFields(BinaryTypeBinding.java:355)

at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.cachePartsFrom(BinaryTypeBinding.java:326)

at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:640)

at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:619)

at org.eclipse.jdt.internal.compiler.Compiler.accept(Compiler.java:295)

at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:107)

at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)

at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122)

at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.resolve(ParameterizedTypeBinding.java:851)

at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:100)

at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveTypesFor(BinaryTypeBinding.java:1016)

at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.getExactMethod(BinaryTypeBinding.java:771)

at org.eclipse.jdt.internal.compiler.lookup.Scope.findExactMethod(Scope.java:893)

at org.eclipse.jdt.internal.compiler.lookup.Scope.getMethod(Scope.java:2234)

at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:401)

at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:314)

at org.eclipse.jdt.internal.compiler.ast.Expression.resolve(Expression.java:913)

at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:447)

at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:189)

at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:406)

at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1131)

at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1219)

at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:528)

at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:759)

at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:464)

at org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJavaCompiler.java:351)

at org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:51)

at org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:389)

at org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompiletimeRegistry.java:56)

at org.drools.compiler.PackageRegistry.compileAll(PackageRegistry.java:74)

at org.drools.compiler.PackageBuilder.compileAll(PackageBuilder.java:677)

at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:640)

at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:266)

at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:458)

at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)

at org.openremote.controller.statuscache.rules.RuleEngine.getValidKnowledgePackages(RuleEngine.java:498)

at org.openremote.controller.statuscache.rules.RuleEngine.start(RuleEngine.java:253)

at org.openremote.controller.statuscache.EventProcessorChain.start(EventProcessorChain.java:112)

at org.openremote.controller.statuscache.StatusCache.start(StatusCache.java:120)

at org.openremote.controller.deployer.Version20ModelBuilder.buildSensorModel(Version20ModelBuilder.java:659)

at org.openremote.controller.deployer.Version20ModelBuilder.build(Version20ModelBuilder.java:557)

at org.openremote.controller.deployer.AbstractModelBuilder.buildModel(AbstractModelBuilder.java:154)

at org.openremote.controller.service.Deployer.startup(Deployer.java:872)

at org.openremote.controller.service.Deployer.softRestart(Deployer.java:454)

at org.openremote.controller.service.Deployer$ControllerDefinitionWatch.run(Deployer.java:1411)

at java.lang.Thread.run(Thread.java:745)

Caused by: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException

at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.(ClassFileReader.java:372)

at org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:254)

… 54 more

ERROR 2016-08-26 16:58:51,820 : Cannot start event processor ‘Drools Rule Engine’ : java.lang.ClassNotFoundException: org/openremote/controller/protocol/Rule_tid_to_workload_0DefaultConsequenceInvoker

org.drools.RuntimeDroolsException: java.lang.ClassNotFoundException: org/openremote/controller/protocol/Rule_tid_to_workload_0DefaultConsequenceInvoker

at org.drools.rule.JavaDialectRuntimeData.reload(JavaDialectRuntimeData.java:383)

at org.drools.rule.JavaDialectRuntimeData.onBeforeExecute(JavaDialectRuntimeData.java:139)

at org.drools.rule.DialectRuntimeRegistry.onBeforeExecute(DialectRuntimeRegistry.java:132)

at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:509)

at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:445)

at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:142)

at org.openremote.controller.statuscache.rules.RuleEngine.getValidKnowledgePackages(RuleEngine.java:534)

at org.openremote.controller.statuscache.rules.RuleEngine.start(RuleEngine.java:253)

at org.openremote.controller.statuscache.EventProcessorChain.start(EventProcessorChain.java:112)

at org.openremote.controller.statuscache.StatusCache.start(StatusCache.java:120)

at org.openremote.controller.deployer.Version20ModelBuilder.buildSensorModel(Version20ModelBuilder.java:659)

at org.openremote.controller.deployer.Version20ModelBuilder.build(Version20ModelBuilder.java:557)

at org.openremote.controller.deployer.AbstractModelBuilder.buildModel(AbstractModelBuilder.java:154)

at org.openremote.controller.service.Deployer.startup(Deployer.java:872)

at org.openremote.controller.service.Deployer.softRestart(Deployer.java:454)

at org.openremote.controller.service.Deployer$ControllerDefinitionWatch.run(Deployer.java:1411)

at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.ClassNotFoundException: org/openremote/controller/protocol/Rule_tid_to_workload_0DefaultConsequenceInvoker

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:344)

at org.drools.rule.DroolsCompositeClassLoader.loadClass(DroolsCompositeClassLoader.java:91)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

at org.drools.rule.JavaDialectRuntimeData.wire(JavaDialectRuntimeData.java:312)

at org.drools.rule.JavaDialectRuntimeData.reload(JavaDialectRuntimeData.java:379)

… 16 more

``

Yes, you are correct. You can either try controller 2.6 or downgrade JRE to 1.7. Usually you can have both version a single machine and switch between them. However, IMHO this is beyond this post.